Loading sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp +22 −18 Original line number Diff line number Diff line Loading @@ -38,6 +38,10 @@ using ::android::hardware::sensors::V1_0::SensorsEventFormatOffset; using ::android::hardware::sensors::V1_0::SensorStatus; using ::android::hardware::sensors::V1_0::SharedMemType; using ::android::hardware::sensors::V1_0::Vec3; using std::chrono::duration_cast; using std::chrono::microseconds; using std::chrono::milliseconds; using std::chrono::nanoseconds; constexpr size_t kEventSize = static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH); Loading Loading @@ -67,9 +71,9 @@ class EventCallback : public IEventCallback { } void waitForFlushEvents(const std::vector<SensorInfo>& sensorsToWaitFor, int32_t numCallsToFlush, int64_t timeoutMs) { int32_t numCallsToFlush, milliseconds timeout) { std::unique_lock<std::recursive_mutex> lock(mFlushMutex); mFlushCV.wait_for(lock, std::chrono::milliseconds(timeoutMs), mFlushCV.wait_for(lock, timeout, [&] { return flushesReceived(sensorsToWaitFor, numCallsToFlush); }); } Loading @@ -78,10 +82,9 @@ class EventCallback : public IEventCallback { return mEventMap[sensorHandle]; } void waitForEvents(const std::vector<SensorInfo>& sensorsToWaitFor, int32_t timeoutMs) { void waitForEvents(const std::vector<SensorInfo>& sensorsToWaitFor, milliseconds timeout) { std::unique_lock<std::recursive_mutex> lock(mEventMutex); mEventCV.wait_for(lock, std::chrono::milliseconds(timeoutMs), [&] { return eventsReceived(sensorsToWaitFor); }); mEventCV.wait_for(lock, timeout, [&] { return eventsReceived(sensorsToWaitFor); }); } protected: Loading Loading @@ -372,7 +375,7 @@ TEST_F(SensorsHidlTest, InjectSensorEventData) { } // Wait for events to be written back to the Event FMQ callback.waitForEvents(sensors, 1000 /* timeoutMs */); callback.waitForEvents(sensors, milliseconds(1000) /* timeout */); for (const auto& s : sensors) { auto events = callback.getEvents(s.sensorHandle); Loading Loading @@ -699,7 +702,7 @@ void SensorsHidlTest::runFlushTest(const std::vector<SensorInfo>& sensors, bool } // Wait up to one second for the flush events callback.waitForFlushEvents(sensors, flushCalls, 1000 /* timeoutMs */); callback.waitForFlushEvents(sensors, flushCalls, milliseconds(1000) /* timeout */); // Deactivate all sensors after waiting for flush events so pending flush events are not // abandoned by the HAL. Loading Loading @@ -820,17 +823,18 @@ TEST_F(SensorsHidlTest, Activate) { } TEST_F(SensorsHidlTest, NoStaleEvents) { constexpr int64_t kFiveHundredMilliseconds = 500 * 1000; constexpr int64_t kOneSecond = 1000 * 1000; constexpr milliseconds kFiveHundredMs(500); constexpr milliseconds kOneSecond(1000); // Register the callback to receive sensor events EventCallback callback; getEnvironment()->registerCallback(&callback); const std::vector<SensorInfo> sensors = getSensorsList(); int32_t maxMinDelay = 0; milliseconds maxMinDelay(0); for (const SensorInfo& sensor : getSensorsList()) { maxMinDelay = std::max(maxMinDelay, sensor.minDelay); milliseconds minDelay = duration_cast<milliseconds>(microseconds(sensor.minDelay)); maxMinDelay = milliseconds(std::max(maxMinDelay.count(), minDelay.count())); } // Activate the sensors so that they start generating events Loading @@ -839,7 +843,7 @@ TEST_F(SensorsHidlTest, NoStaleEvents) { // According to the CDD, the first sample must be generated within 400ms + 2 * sample_time // and the maximum reporting latency is 100ms + 2 * sample_time. Wait a sufficient amount // of time to guarantee that a sample has arrived. callback.waitForEvents(sensors, kFiveHundredMilliseconds + (5 * maxMinDelay)); callback.waitForEvents(sensors, kFiveHundredMs + (5 * maxMinDelay)); activateAllSensors(false); // Save the last received event for each sensor Loading @@ -851,21 +855,21 @@ TEST_F(SensorsHidlTest, NoStaleEvents) { } // Allow some time to pass, reset the callback, then reactivate the sensors usleep(kOneSecond + (5 * maxMinDelay)); usleep(duration_cast<microseconds>(kOneSecond + (5 * maxMinDelay)).count()); callback.reset(); activateAllSensors(true); callback.waitForEvents(sensors, kFiveHundredMilliseconds + (5 * maxMinDelay)); callback.waitForEvents(sensors, kFiveHundredMs + (5 * maxMinDelay)); activateAllSensors(false); for (const SensorInfo& sensor : sensors) { // Ensure that the first event received is not stale by ensuring that its timestamp is // sufficiently different from the previous event const Event newEvent = callback.getEvents(sensor.sensorHandle).front(); int64_t delta = newEvent.timestamp - lastEventTimestampMap[sensor.sensorHandle]; ASSERT_GE(delta, kFiveHundredMilliseconds + (3 * sensor.minDelay)); milliseconds delta = duration_cast<milliseconds>( nanoseconds(newEvent.timestamp - lastEventTimestampMap[sensor.sensorHandle])); milliseconds sensorMinDelay = duration_cast<milliseconds>(microseconds(sensor.minDelay)); ASSERT_GE(delta, kFiveHundredMs + (3 * sensorMinDelay)); } getEnvironment()->unregisterCallback(); } void SensorsHidlTest::checkRateLevel(const SensorInfo& sensor, int32_t directChannelHandle, Loading Loading
sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp +22 −18 Original line number Diff line number Diff line Loading @@ -38,6 +38,10 @@ using ::android::hardware::sensors::V1_0::SensorsEventFormatOffset; using ::android::hardware::sensors::V1_0::SensorStatus; using ::android::hardware::sensors::V1_0::SharedMemType; using ::android::hardware::sensors::V1_0::Vec3; using std::chrono::duration_cast; using std::chrono::microseconds; using std::chrono::milliseconds; using std::chrono::nanoseconds; constexpr size_t kEventSize = static_cast<size_t>(SensorsEventFormatOffset::TOTAL_LENGTH); Loading Loading @@ -67,9 +71,9 @@ class EventCallback : public IEventCallback { } void waitForFlushEvents(const std::vector<SensorInfo>& sensorsToWaitFor, int32_t numCallsToFlush, int64_t timeoutMs) { int32_t numCallsToFlush, milliseconds timeout) { std::unique_lock<std::recursive_mutex> lock(mFlushMutex); mFlushCV.wait_for(lock, std::chrono::milliseconds(timeoutMs), mFlushCV.wait_for(lock, timeout, [&] { return flushesReceived(sensorsToWaitFor, numCallsToFlush); }); } Loading @@ -78,10 +82,9 @@ class EventCallback : public IEventCallback { return mEventMap[sensorHandle]; } void waitForEvents(const std::vector<SensorInfo>& sensorsToWaitFor, int32_t timeoutMs) { void waitForEvents(const std::vector<SensorInfo>& sensorsToWaitFor, milliseconds timeout) { std::unique_lock<std::recursive_mutex> lock(mEventMutex); mEventCV.wait_for(lock, std::chrono::milliseconds(timeoutMs), [&] { return eventsReceived(sensorsToWaitFor); }); mEventCV.wait_for(lock, timeout, [&] { return eventsReceived(sensorsToWaitFor); }); } protected: Loading Loading @@ -372,7 +375,7 @@ TEST_F(SensorsHidlTest, InjectSensorEventData) { } // Wait for events to be written back to the Event FMQ callback.waitForEvents(sensors, 1000 /* timeoutMs */); callback.waitForEvents(sensors, milliseconds(1000) /* timeout */); for (const auto& s : sensors) { auto events = callback.getEvents(s.sensorHandle); Loading Loading @@ -699,7 +702,7 @@ void SensorsHidlTest::runFlushTest(const std::vector<SensorInfo>& sensors, bool } // Wait up to one second for the flush events callback.waitForFlushEvents(sensors, flushCalls, 1000 /* timeoutMs */); callback.waitForFlushEvents(sensors, flushCalls, milliseconds(1000) /* timeout */); // Deactivate all sensors after waiting for flush events so pending flush events are not // abandoned by the HAL. Loading Loading @@ -820,17 +823,18 @@ TEST_F(SensorsHidlTest, Activate) { } TEST_F(SensorsHidlTest, NoStaleEvents) { constexpr int64_t kFiveHundredMilliseconds = 500 * 1000; constexpr int64_t kOneSecond = 1000 * 1000; constexpr milliseconds kFiveHundredMs(500); constexpr milliseconds kOneSecond(1000); // Register the callback to receive sensor events EventCallback callback; getEnvironment()->registerCallback(&callback); const std::vector<SensorInfo> sensors = getSensorsList(); int32_t maxMinDelay = 0; milliseconds maxMinDelay(0); for (const SensorInfo& sensor : getSensorsList()) { maxMinDelay = std::max(maxMinDelay, sensor.minDelay); milliseconds minDelay = duration_cast<milliseconds>(microseconds(sensor.minDelay)); maxMinDelay = milliseconds(std::max(maxMinDelay.count(), minDelay.count())); } // Activate the sensors so that they start generating events Loading @@ -839,7 +843,7 @@ TEST_F(SensorsHidlTest, NoStaleEvents) { // According to the CDD, the first sample must be generated within 400ms + 2 * sample_time // and the maximum reporting latency is 100ms + 2 * sample_time. Wait a sufficient amount // of time to guarantee that a sample has arrived. callback.waitForEvents(sensors, kFiveHundredMilliseconds + (5 * maxMinDelay)); callback.waitForEvents(sensors, kFiveHundredMs + (5 * maxMinDelay)); activateAllSensors(false); // Save the last received event for each sensor Loading @@ -851,21 +855,21 @@ TEST_F(SensorsHidlTest, NoStaleEvents) { } // Allow some time to pass, reset the callback, then reactivate the sensors usleep(kOneSecond + (5 * maxMinDelay)); usleep(duration_cast<microseconds>(kOneSecond + (5 * maxMinDelay)).count()); callback.reset(); activateAllSensors(true); callback.waitForEvents(sensors, kFiveHundredMilliseconds + (5 * maxMinDelay)); callback.waitForEvents(sensors, kFiveHundredMs + (5 * maxMinDelay)); activateAllSensors(false); for (const SensorInfo& sensor : sensors) { // Ensure that the first event received is not stale by ensuring that its timestamp is // sufficiently different from the previous event const Event newEvent = callback.getEvents(sensor.sensorHandle).front(); int64_t delta = newEvent.timestamp - lastEventTimestampMap[sensor.sensorHandle]; ASSERT_GE(delta, kFiveHundredMilliseconds + (3 * sensor.minDelay)); milliseconds delta = duration_cast<milliseconds>( nanoseconds(newEvent.timestamp - lastEventTimestampMap[sensor.sensorHandle])); milliseconds sensorMinDelay = duration_cast<milliseconds>(microseconds(sensor.minDelay)); ASSERT_GE(delta, kFiveHundredMs + (3 * sensorMinDelay)); } getEnvironment()->unregisterCallback(); } void SensorsHidlTest::checkRateLevel(const SensorInfo& sensor, int32_t directChannelHandle, Loading