Loading sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h +6 −7 Original line number Diff line number Diff line Loading @@ -537,10 +537,9 @@ TEST_P(SensorsHidlTest, CallInitializeTwice) { activateAllSensors(true); // Verify that the old environment does not receive any events EXPECT_EQ(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), 0); EXPECT_EQ(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), 0); // Verify that the new event queue receives sensor events EXPECT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents, newEnv.get(), newEnv.get()).size(), kNumEvents); EXPECT_GE(newEnv.get()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); activateAllSensors(false); // Cleanup the test environment Loading @@ -555,7 +554,7 @@ TEST_P(SensorsHidlTest, CallInitializeTwice) { // Ensure that the original environment is receiving events activateAllSensors(true); EXPECT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); EXPECT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); activateAllSensors(false); } Loading @@ -565,7 +564,7 @@ TEST_P(SensorsHidlTest, CleanupConnectionsOnInitialize) { // Verify that events are received constexpr useconds_t kCollectionTimeoutUs = 1000 * 1000; // 1s constexpr int32_t kNumEvents = 1; ASSERT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), kNumEvents); ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); // Clear the active sensor handles so they are not disabled during TearDown auto handles = mSensorHandles; Loading @@ -577,9 +576,9 @@ TEST_P(SensorsHidlTest, CleanupConnectionsOnInitialize) { } // Verify no events are received until sensors are re-activated ASSERT_EQ(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), 0); ASSERT_EQ(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), 0); activateAllSensors(true); ASSERT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), kNumEvents); ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); // Disable sensors activateAllSensors(false); Loading sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h +8 −50 Original line number Diff line number Diff line Loading @@ -198,49 +198,6 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { RateLevel rate, ISensors::configDirectReport_cb _hidl_cb) = 0; std::vector<EventType> collectEvents(useconds_t timeLimitUs, size_t nEventLimit, bool clearBeforeStart = true, bool changeCollection = true) { return collectEvents(timeLimitUs, nEventLimit, getEnvironment(), clearBeforeStart, changeCollection); } std::vector<EventType> collectEvents(useconds_t timeLimitUs, size_t nEventLimit, SensorsVtsEnvironmentBase<EventType>* environment, bool clearBeforeStart = true, bool changeCollection = true) { std::vector<EventType> events; constexpr useconds_t SLEEP_GRANULARITY = 100 * 1000; // granularity 100 ms ALOGI("collect max of %zu events for %d us, clearBeforeStart %d", nEventLimit, timeLimitUs, clearBeforeStart); if (changeCollection) { environment->setCollection(true); } if (clearBeforeStart) { environment->catEvents(nullptr); } while (timeLimitUs > 0) { useconds_t duration = std::min(SLEEP_GRANULARITY, timeLimitUs); usleep(duration); timeLimitUs -= duration; environment->catEvents(&events); if (events.size() >= nEventLimit) { break; } ALOGV("time to go = %d, events to go = %d", (int)timeLimitUs, (int)(nEventLimit - events.size())); } if (changeCollection) { environment->setCollection(false); } return events; } void testStreamingOperation(SensorTypeVersion type, std::chrono::nanoseconds samplingPeriod, std::chrono::seconds duration, const SensorEventsChecker<EventType>& checker) { Loading Loading @@ -268,7 +225,7 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { ASSERT_EQ(batch(handle, samplingPeriodInNs, batchingPeriodInNs), Result::OK); ASSERT_EQ(activate(handle, 1), Result::OK); events = collectEvents(minTimeUs, minNEvent, getEnvironment(), true /*clearBeforeStart*/); events = getEnvironment()->collectEvents(minTimeUs, minNEvent, true /*clearBeforeStart*/); ASSERT_EQ(activate(handle, 0), Result::OK); ALOGI("Collected %zu samples", events.size()); Loading Loading @@ -335,13 +292,13 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { ASSERT_EQ(activate(handle, 1), Result::OK); usleep(500000); // sleep 0.5 sec to wait for change rate to happen events1 = collectEvents(collectionTimeoutUs, minNEvent, getEnvironment()); events1 = getEnvironment()->collectEvents(collectionTimeoutUs, minNEvent); // second collection, without stopping the sensor ASSERT_EQ(batch(handle, secondCollectionPeriod, batchingPeriodInNs), Result::OK); usleep(500000); // sleep 0.5 sec to wait for change rate to happen events2 = collectEvents(collectionTimeoutUs, minNEvent, getEnvironment()); events2 = getEnvironment()->collectEvents(collectionTimeoutUs, minNEvent); // end of collection, stop sensor ASSERT_EQ(activate(handle, 0), Result::OK); Loading Loading @@ -447,16 +404,17 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { getEnvironment()->setCollection(true); // clean existing collections collectEvents(0 /*timeLimitUs*/, 0 /*nEventLimit*/, true /*clearBeforeStart*/, false /*change collection*/); getEnvironment()->collectEvents(0 /*timeLimitUs*/, 0 /*nEventLimit*/, true /*clearBeforeStart*/, false /*change collection*/); // 0.8 + 0.2 times the batching period usleep(batchingPeriodInNs / 1000 * 2 / 10); ASSERT_EQ(flush(handle), Result::OK); // plus some time for the event to deliver events = collectEvents(allowedBatchDeliverTimeNs / 1000, minFifoCount, false /*clearBeforeStart*/, false /*change collection*/); events = getEnvironment()->collectEvents(allowedBatchDeliverTimeNs / 1000, minFifoCount, false /*clearBeforeStart*/, false /*change collection*/); getEnvironment()->setCollection(false); ASSERT_EQ(activate(handle, 0), Result::OK); Loading sensors/common/vts/utils/include/sensors-vts-utils/SensorsVtsEnvironmentBase.h +36 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ #include <thread> #include <vector> #include <log/log.h> template <class Event> class IEventCallback { public: Loading Loading @@ -74,6 +76,40 @@ class SensorsVtsEnvironmentBase { mCallback = nullptr; } std::vector<Event> collectEvents(useconds_t timeLimitUs, size_t nEventLimit, bool clearBeforeStart = true, bool changeCollection = true) { std::vector<Event> events; constexpr useconds_t SLEEP_GRANULARITY = 100 * 1000; // granularity 100 ms ALOGI("collect max of %zu events for %d us, clearBeforeStart %d", nEventLimit, timeLimitUs, clearBeforeStart); if (changeCollection) { setCollection(true); } if (clearBeforeStart) { catEvents(nullptr); } while (timeLimitUs > 0) { useconds_t duration = std::min(SLEEP_GRANULARITY, timeLimitUs); usleep(duration); timeLimitUs -= duration; catEvents(&events); if (events.size() >= nEventLimit) { break; } ALOGV("time to go = %d, events to go = %d", (int)timeLimitUs, (int)(nEventLimit - events.size())); } if (changeCollection) { setCollection(false); } return events; } protected: SensorsVtsEnvironmentBase(const std::string& service_name) : mCollectionEnabled(false), mCallback(nullptr) { Loading Loading
sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h +6 −7 Original line number Diff line number Diff line Loading @@ -537,10 +537,9 @@ TEST_P(SensorsHidlTest, CallInitializeTwice) { activateAllSensors(true); // Verify that the old environment does not receive any events EXPECT_EQ(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), 0); EXPECT_EQ(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), 0); // Verify that the new event queue receives sensor events EXPECT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents, newEnv.get(), newEnv.get()).size(), kNumEvents); EXPECT_GE(newEnv.get()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); activateAllSensors(false); // Cleanup the test environment Loading @@ -555,7 +554,7 @@ TEST_P(SensorsHidlTest, CallInitializeTwice) { // Ensure that the original environment is receiving events activateAllSensors(true); EXPECT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); EXPECT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); activateAllSensors(false); } Loading @@ -565,7 +564,7 @@ TEST_P(SensorsHidlTest, CleanupConnectionsOnInitialize) { // Verify that events are received constexpr useconds_t kCollectionTimeoutUs = 1000 * 1000; // 1s constexpr int32_t kNumEvents = 1; ASSERT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), kNumEvents); ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); // Clear the active sensor handles so they are not disabled during TearDown auto handles = mSensorHandles; Loading @@ -577,9 +576,9 @@ TEST_P(SensorsHidlTest, CleanupConnectionsOnInitialize) { } // Verify no events are received until sensors are re-activated ASSERT_EQ(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), 0); ASSERT_EQ(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), 0); activateAllSensors(true); ASSERT_GE(collectEvents(kCollectionTimeoutUs, kNumEvents, getEnvironment()).size(), kNumEvents); ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); // Disable sensors activateAllSensors(false); Loading
sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlTestBase.h +8 −50 Original line number Diff line number Diff line Loading @@ -198,49 +198,6 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { RateLevel rate, ISensors::configDirectReport_cb _hidl_cb) = 0; std::vector<EventType> collectEvents(useconds_t timeLimitUs, size_t nEventLimit, bool clearBeforeStart = true, bool changeCollection = true) { return collectEvents(timeLimitUs, nEventLimit, getEnvironment(), clearBeforeStart, changeCollection); } std::vector<EventType> collectEvents(useconds_t timeLimitUs, size_t nEventLimit, SensorsVtsEnvironmentBase<EventType>* environment, bool clearBeforeStart = true, bool changeCollection = true) { std::vector<EventType> events; constexpr useconds_t SLEEP_GRANULARITY = 100 * 1000; // granularity 100 ms ALOGI("collect max of %zu events for %d us, clearBeforeStart %d", nEventLimit, timeLimitUs, clearBeforeStart); if (changeCollection) { environment->setCollection(true); } if (clearBeforeStart) { environment->catEvents(nullptr); } while (timeLimitUs > 0) { useconds_t duration = std::min(SLEEP_GRANULARITY, timeLimitUs); usleep(duration); timeLimitUs -= duration; environment->catEvents(&events); if (events.size() >= nEventLimit) { break; } ALOGV("time to go = %d, events to go = %d", (int)timeLimitUs, (int)(nEventLimit - events.size())); } if (changeCollection) { environment->setCollection(false); } return events; } void testStreamingOperation(SensorTypeVersion type, std::chrono::nanoseconds samplingPeriod, std::chrono::seconds duration, const SensorEventsChecker<EventType>& checker) { Loading Loading @@ -268,7 +225,7 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { ASSERT_EQ(batch(handle, samplingPeriodInNs, batchingPeriodInNs), Result::OK); ASSERT_EQ(activate(handle, 1), Result::OK); events = collectEvents(minTimeUs, minNEvent, getEnvironment(), true /*clearBeforeStart*/); events = getEnvironment()->collectEvents(minTimeUs, minNEvent, true /*clearBeforeStart*/); ASSERT_EQ(activate(handle, 0), Result::OK); ALOGI("Collected %zu samples", events.size()); Loading Loading @@ -335,13 +292,13 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { ASSERT_EQ(activate(handle, 1), Result::OK); usleep(500000); // sleep 0.5 sec to wait for change rate to happen events1 = collectEvents(collectionTimeoutUs, minNEvent, getEnvironment()); events1 = getEnvironment()->collectEvents(collectionTimeoutUs, minNEvent); // second collection, without stopping the sensor ASSERT_EQ(batch(handle, secondCollectionPeriod, batchingPeriodInNs), Result::OK); usleep(500000); // sleep 0.5 sec to wait for change rate to happen events2 = collectEvents(collectionTimeoutUs, minNEvent, getEnvironment()); events2 = getEnvironment()->collectEvents(collectionTimeoutUs, minNEvent); // end of collection, stop sensor ASSERT_EQ(activate(handle, 0), Result::OK); Loading Loading @@ -447,16 +404,17 @@ class SensorsHidlTestBase : public testing::TestWithParam<std::string> { getEnvironment()->setCollection(true); // clean existing collections collectEvents(0 /*timeLimitUs*/, 0 /*nEventLimit*/, true /*clearBeforeStart*/, false /*change collection*/); getEnvironment()->collectEvents(0 /*timeLimitUs*/, 0 /*nEventLimit*/, true /*clearBeforeStart*/, false /*change collection*/); // 0.8 + 0.2 times the batching period usleep(batchingPeriodInNs / 1000 * 2 / 10); ASSERT_EQ(flush(handle), Result::OK); // plus some time for the event to deliver events = collectEvents(allowedBatchDeliverTimeNs / 1000, minFifoCount, false /*clearBeforeStart*/, false /*change collection*/); events = getEnvironment()->collectEvents(allowedBatchDeliverTimeNs / 1000, minFifoCount, false /*clearBeforeStart*/, false /*change collection*/); getEnvironment()->setCollection(false); ASSERT_EQ(activate(handle, 0), Result::OK); Loading
sensors/common/vts/utils/include/sensors-vts-utils/SensorsVtsEnvironmentBase.h +36 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ #include <thread> #include <vector> #include <log/log.h> template <class Event> class IEventCallback { public: Loading Loading @@ -74,6 +76,40 @@ class SensorsVtsEnvironmentBase { mCallback = nullptr; } std::vector<Event> collectEvents(useconds_t timeLimitUs, size_t nEventLimit, bool clearBeforeStart = true, bool changeCollection = true) { std::vector<Event> events; constexpr useconds_t SLEEP_GRANULARITY = 100 * 1000; // granularity 100 ms ALOGI("collect max of %zu events for %d us, clearBeforeStart %d", nEventLimit, timeLimitUs, clearBeforeStart); if (changeCollection) { setCollection(true); } if (clearBeforeStart) { catEvents(nullptr); } while (timeLimitUs > 0) { useconds_t duration = std::min(SLEEP_GRANULARITY, timeLimitUs); usleep(duration); timeLimitUs -= duration; catEvents(&events); if (events.size() >= nEventLimit) { break; } ALOGV("time to go = %d, events to go = %d", (int)timeLimitUs, (int)(nEventLimit - events.size())); } if (changeCollection) { setCollection(false); } return events; } protected: SensorsVtsEnvironmentBase(const std::string& service_name) : mCollectionEnabled(false), mCallback(nullptr) { Loading