Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a5b5c359 authored by karthik bharadwaj's avatar karthik bharadwaj
Browse files

Enforce sensors of the same type having a unique name.

Bug: 179076515
Test: run vts -m VtsHalSensorsV2_0Target
Change-Id: Ibf0d90afdcdce5ee5908dc35f8c392ee06e4b49e
parent 0ebf88ab
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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);
+11 −0
Original line number Diff line number Diff line
@@ -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);