From 8659a96281f108259c047c1fd6e9fd181241ee7a Mon Sep 17 00:00:00 2001 From: lichen yu Date: Thu, 6 Jun 2024 03:40:43 +0000 Subject: [PATCH] Fix VtsHalSensorsV2_0TargetTest During VTS testing, when many sensors are quickly enabled, the load on the Sensorhub side will be too heavy, and then continue to send sensor enable instructions and Sensor Flush instructions. These instructions sent by the Kernel driver to the Sensorhub through inter-core communication cannot be responded to in a timely manner. After the Kernel side judges the timeout, it will determine that the enable fails; after the enable fails, it cannot continue to test the flush or return the expected flush data. ten sensors is tested as a group Bug: 339763843 Test: run vts -m VtsHalSensorsV2_0TargetTest (cherry picked from https://android-review.googlesource.com/q/commit:09952885e441bcf0d8f0bf0834ff46608b07e0d0) Merged-In: I6f6d36d1e3c98b85b412189c3f97163c0945a7ab Change-Id: I6f6d36d1e3c98b85b412189c3f97163c0945a7ab --- .../vts/2_X/VtsHalSensorsV2_XTargetTest.h | 70 +++++++++++-------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h b/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h index aa6e8814a2..b17ecb8df0 100644 --- a/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h +++ b/sensors/common/vts/2_X/VtsHalSensorsV2_XTargetTest.h @@ -604,42 +604,54 @@ void SensorsHidlTest::runFlushTest(const std::vector& sensors, b EventCallback callback; getEnvironment()->registerCallback(&callback); - for (const SensorInfoType& sensor : sensors) { - // Configure and activate the sensor - batch(sensor.sensorHandle, sensor.maxDelay, 0 /* maxReportLatencyNs */); - activate(sensor.sensorHandle, activateSensor); + // 10 sensors per group + constexpr size_t kSensorsPerGroup = 10; + for (size_t sensorOffset = 0; sensorOffset < sensors.size(); + sensorOffset += kSensorsPerGroup) { + std::vector sensorGroup( + sensors.begin() + sensorOffset, + sensors.begin() + + std::min(sensorOffset + kSensorsPerGroup, sensors.size())); - // Flush the sensor - for (int32_t i = 0; i < flushCalls; i++) { + for (const SensorInfoType& sensor : sensorGroup) { + // Configure and activate the sensor + batch(sensor.sensorHandle, sensor.maxDelay, 0 /* maxReportLatencyNs */); + activate(sensor.sensorHandle, activateSensor); + + // Flush the sensor + for (int32_t i = 0; i < flushCalls; i++) { + SCOPED_TRACE(::testing::Message() + << "Flush " << i << "/" << flushCalls << ": " + << " handle=0x" << std::hex << std::setw(8) << std::setfill('0') + << sensor.sensorHandle << std::dec + << " type=" << static_cast(sensor.type) + << " name=" << sensor.name); + + Result flushResult = flush(sensor.sensorHandle); + EXPECT_EQ(flushResult, expectedResponse); + } + } + + // Wait up to one second for the flush events + callback.waitForFlushEvents(sensorGroup, flushCalls, milliseconds(1000) /* timeout */); + + // Deactivate all sensors after waiting for flush events so pending flush events are not + // abandoned by the HAL. + for (const SensorInfoType& sensor : sensorGroup) { + activate(sensor.sensorHandle, false); + } + + // Check that the correct number of flushes are present for each sensor + for (const SensorInfoType& sensor : sensorGroup) { SCOPED_TRACE(::testing::Message() - << "Flush " << i << "/" << flushCalls << ": " << " handle=0x" << std::hex << std::setw(8) << std::setfill('0') << sensor.sensorHandle << std::dec - << " type=" << static_cast(sensor.type) << " name=" << sensor.name); - - Result flushResult = flush(sensor.sensorHandle); - EXPECT_EQ(flushResult, expectedResponse); + << " type=" << static_cast(sensor.type) + << " name=" << sensor.name); + ASSERT_EQ(callback.getFlushCount(sensor.sensorHandle), expectedFlushCount); } } - - // Wait up to one second for the flush events - 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. - for (const SensorInfoType& sensor : sensors) { - activate(sensor.sensorHandle, false); - } getEnvironment()->unregisterCallback(); - - // Check that the correct number of flushes are present for each sensor - for (const SensorInfoType& sensor : sensors) { - SCOPED_TRACE(::testing::Message() - << " handle=0x" << std::hex << std::setw(8) << std::setfill('0') - << sensor.sensorHandle << std::dec << " type=" << static_cast(sensor.type) - << " name=" << sensor.name); - ASSERT_EQ(callback.getFlushCount(sensor.sensorHandle), expectedFlushCount); - } } TEST_P(SensorsHidlTest, FlushSensor) {