From 09cf466c2fad91e360109854a259ce04b57380be Mon Sep 17 00:00:00 2001 From: Shih-Cheng Tu Date: Thu, 1 Aug 2024 02:31:08 +0000 Subject: [PATCH] Skip event count assertion on reporting mode Sensors with reporting mode "One-shot" and "Special" will not trigger event on "activate", hence the test that expecting the event count after calling activate() will fail. Skipping the event count assertion if the device only has sensors with these reporting mode. Bug: 349268211 Test: run vts -m VtsAidlHalSensorsTargetTest -t Sensors/SensorsAidlTest#CallInitializeTwice/0_android_hardware_sensors_ISensors_default Change-Id: I656a652fc205961b8e6207942ccf16a71a08dc14 --- .../aidl/vts/VtsAidlHalSensorsTargetTest.cpp | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp b/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp index be11b87690..48e6c24bd4 100644 --- a/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp +++ b/sensors/aidl/vts/VtsAidlHalSensorsTargetTest.cpp @@ -714,11 +714,14 @@ TEST_P(SensorsAidlTest, CallInitializeTwice) { return; // Exit early if setting up the new environment failed } + size_t numNonOneShotAndNonSpecialSensors = getNonOneShotAndNonSpecialSensors().size(); activateAllSensors(true); // Verify that the old environment does not receive any events EXPECT_EQ(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), 0); - // Verify that the new event queue receives sensor events - EXPECT_GE(newEnv.get()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + if (numNonOneShotAndNonSpecialSensors > 0) { + // Verify that the new event queue receives sensor events + EXPECT_GE(newEnv.get()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + } activateAllSensors(false); // Cleanup the test environment @@ -733,7 +736,9 @@ TEST_P(SensorsAidlTest, CallInitializeTwice) { // Ensure that the original environment is receiving events activateAllSensors(true); - EXPECT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + if (numNonOneShotAndNonSpecialSensors > 0) { + EXPECT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + } activateAllSensors(false); } @@ -743,7 +748,11 @@ TEST_P(SensorsAidlTest, CleanupConnectionsOnInitialize) { // Verify that events are received constexpr useconds_t kCollectionTimeoutUs = 1000 * 1000; // 1s constexpr int32_t kNumEvents = 1; - ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + + size_t numNonOneShotAndNonSpecialSensors = getNonOneShotAndNonSpecialSensors().size(); + if (numNonOneShotAndNonSpecialSensors > 0) { + ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + } // Clear the active sensor handles so they are not disabled during TearDown auto handles = mSensorHandles; @@ -757,7 +766,9 @@ TEST_P(SensorsAidlTest, CleanupConnectionsOnInitialize) { // Verify no events are received until sensors are re-activated ASSERT_EQ(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), 0); activateAllSensors(true); - ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + if (numNonOneShotAndNonSpecialSensors > 0) { + ASSERT_GE(getEnvironment()->collectEvents(kCollectionTimeoutUs, kNumEvents).size(), kNumEvents); + } // Disable sensors activateAllSensors(false);