Enforce sensors of the same type having a unique name.

Bug: 179076515
Test: run vts -m VtsHalSensorsV2_0Target
Change-Id: Ibf0d90afdcdce5ee5908dc35f8c392ee06e4b49e
This commit is contained in:
karthik bharadwaj
2021-06-15 13:55:43 -07:00
parent 0ebf88ab00
commit a5b5c359cb
2 changed files with 22 additions and 0 deletions

View File

@@ -24,7 +24,9 @@
#include <log/log.h>
#include <utils/SystemClock.h>
#include <algorithm>
#include <cinttypes>
#include <unordered_map>
#include <vector>
using ::android::hardware::Return;
@@ -149,6 +151,7 @@ std::vector<SensorInfo> SensorsHidlTest::getSensorsList() {
TEST_P(SensorsHidlTest, SensorListValid) {
S()->getSensorsList([&](const auto& list) {
const size_t count = list.size();
std::unordered_map<int32_t, std::vector<std::string>> sensorTypeNameMap;
for (size_t i = 0; i < count; ++i) {
const auto& s = list[i];
SCOPED_TRACE(::testing::Message()
@@ -167,6 +170,14 @@ TEST_P(SensorsHidlTest, SensorListValid) {
EXPECT_FALSE(s.name.empty());
EXPECT_FALSE(s.vendor.empty());
// Make sure that sensors of the same type have a unique name.
std::vector<std::string>& v = sensorTypeNameMap[static_cast<int32_t>(s.type)];
bool isUniqueName = std::find(v.begin(), v.end(), s.name) == v.end();
EXPECT_TRUE(isUniqueName) << "Duplicate sensor Name: " << s.name;
if (isUniqueName) {
v.push_back(s.name);
}
// Test power > 0, maxRange > 0
EXPECT_LE(0, s.power);
EXPECT_LT(0, s.maxRange);

View File

@@ -26,10 +26,12 @@
#include <log/log.h>
#include <utils/SystemClock.h>
#include <algorithm>
#include <cinttypes>
#include <condition_variable>
#include <cstring>
#include <map>
#include <unordered_map>
#include <vector>
/**
@@ -373,6 +375,7 @@ int32_t SensorsHidlTest::getInvalidSensorHandle() {
TEST_P(SensorsHidlTest, SensorListValid) {
getSensors()->getSensorsList([&](const auto& list) {
const size_t count = list.size();
std::unordered_map<int32_t, std::vector<std::string>> sensorTypeNameMap;
for (size_t i = 0; i < count; ++i) {
const auto& s = list[i];
SCOPED_TRACE(::testing::Message()
@@ -393,6 +396,14 @@ TEST_P(SensorsHidlTest, SensorListValid) {
EXPECT_FALSE(s.name.empty());
EXPECT_FALSE(s.vendor.empty());
// Make sure that sensors of the same type have a unique name.
std::vector<std::string>& v = sensorTypeNameMap[static_cast<int32_t>(s.type)];
bool isUniqueName = std::find(v.begin(), v.end(), s.name) == v.end();
EXPECT_TRUE(isUniqueName) << "Duplicate sensor Name: " << s.name;
if (isUniqueName) {
v.push_back(s.name);
}
// Test power > 0, maxRange > 0
EXPECT_LE(0, s.power);
EXPECT_LT(0, s.maxRange);