Fix VtsHalSensorsV2_0TargetTest am: 3beaf4faca am: d65c459061

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/3115968

Change-Id: I0a5674590186e7d3d2a9b1e8166369167fd7a883
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
lichen yu 2024-06-13 01:58:50 +00:00 committed by Automerger Merge Worker
commit 49d05decfe

View file

@ -603,42 +603,55 @@ void SensorsHidlTest::runFlushTest(const std::vector<SensorInfoType>& sensors, b
EventCallback callback; EventCallback callback;
getEnvironment()->registerCallback(&callback); getEnvironment()->registerCallback(&callback);
for (const SensorInfoType& sensor : sensors) { // 10 sensors per group
// Configure and activate the sensor constexpr size_t kSensorsPerGroup = 10;
batch(sensor.sensorHandle, sensor.maxDelay, 0 /* maxReportLatencyNs */); for (size_t sensorOffset = 0; sensorOffset < sensors.size();
activate(sensor.sensorHandle, activateSensor); sensorOffset += kSensorsPerGroup) {
std::vector<SensorInfoType> sensorGroup(
sensors.begin() + sensorOffset,
sensors.begin() +
std::min(sensorOffset + kSensorsPerGroup, sensors.size()));
// Flush the sensor for (const SensorInfoType& sensor : sensorGroup) {
for (int32_t i = 0; i < flushCalls; i++) { // 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<int>(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,
std::chrono::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() SCOPED_TRACE(::testing::Message()
<< "Flush " << i << "/" << flushCalls << ": "
<< " handle=0x" << std::hex << std::setw(8) << std::setfill('0') << " handle=0x" << std::hex << std::setw(8) << std::setfill('0')
<< sensor.sensorHandle << std::dec << sensor.sensorHandle << std::dec
<< " type=" << static_cast<int>(sensor.type) << " name=" << sensor.name); << " type=" << static_cast<int>(sensor.type)
<< " name=" << sensor.name);
Result flushResult = flush(sensor.sensorHandle); ASSERT_EQ(callback.getFlushCount(sensor.sensorHandle), expectedFlushCount);
EXPECT_EQ(flushResult, expectedResponse);
} }
} }
// Wait up to one second for the flush events
callback.waitForFlushEvents(sensors, flushCalls, std::chrono::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(); 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<int>(sensor.type)
<< " name=" << sensor.name);
ASSERT_EQ(callback.getFlushCount(sensor.sensorHandle), expectedFlushCount);
}
} }
TEST_P(SensorsHidlTest, FlushSensor) { TEST_P(SensorsHidlTest, FlushSensor) {