summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Lehmer <alehmer@google.com>2019-08-02 14:01:57 -0700
committerAndrew Lehmer <alehmer@google.com>2019-08-23 14:45:09 +0000
commitbf23abb7455376f2a0f6c65b7de2b3ff35ac39bc (patch)
tree596c6c5cac4e8423fb980a99e1b837602786de28
parenta54bf6ed5a011a7261124fbe19a011f9c75cc133 (diff)
downloadandroid_hardware_interfaces-bf23abb7455376f2a0f6c65b7de2b3ff35ac39bc.tar.gz
android_hardware_interfaces-bf23abb7455376f2a0f6c65b7de2b3ff35ac39bc.tar.bz2
android_hardware_interfaces-bf23abb7455376f2a0f6c65b7de2b3ff35ac39bc.zip
Fix assumptions in SensorsHidlTest.NoStaleEvents
This test was making a couple of false assumptions which were causing it to fail. The fixes are related to the following assertions: 1. One-shot sensors do not report an initial event. 2. Special sensors may not report an initial event. 2. Some on-change sensors may not report an initial event. The test now only checks for a stale event if the sensor reports an initial event consistently. Bug: 138758242 Test: ran on C2 DVT; only fails due to an improperly configured sensor Change-Id: I83f0cb2f6e878244f3d94ae77f64bb8ed2f78e0b Merged-In: I83f0cb2f6e878244f3d94ae77f64bb8ed2f78e0b (cherry picked from commit d8b212ec3e70b47e8b352a9d4abb7840403b4f2b)
-rw-r--r--sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp b/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp
index 62c533444..c2b72e441 100644
--- a/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp
+++ b/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp
@@ -169,6 +169,7 @@ class SensorsHidlTest : public SensorsHidlTestBase {
// Helper functions
void activateAllSensors(bool enable);
std::vector<SensorInfo> getNonOneShotSensors();
+ std::vector<SensorInfo> getNonOneShotAndNonSpecialSensors();
std::vector<SensorInfo> getOneShotSensors();
std::vector<SensorInfo> getInjectEventSensors();
int32_t getInvalidSensorHandle();
@@ -250,6 +251,18 @@ std::vector<SensorInfo> SensorsHidlTest::getNonOneShotSensors() {
return sensors;
}
+std::vector<SensorInfo> SensorsHidlTest::getNonOneShotAndNonSpecialSensors() {
+ std::vector<SensorInfo> sensors;
+ for (const SensorInfo& info : getSensorsList()) {
+ SensorFlagBits reportMode = extractReportMode(info.flags);
+ if (reportMode != SensorFlagBits::ONE_SHOT_MODE &&
+ reportMode != SensorFlagBits::SPECIAL_REPORTING_MODE) {
+ sensors.push_back(info);
+ }
+ }
+ return sensors;
+}
+
std::vector<SensorInfo> SensorsHidlTest::getOneShotSensors() {
std::vector<SensorInfo> sensors;
for (const SensorInfo& info : getSensorsList()) {
@@ -814,9 +827,10 @@ TEST_F(SensorsHidlTest, NoStaleEvents) {
EventCallback callback;
getEnvironment()->registerCallback(&callback);
- const std::vector<SensorInfo> sensors = getSensorsList();
+ // This test is not valid for one-shot or special-report-mode sensors
+ const std::vector<SensorInfo> sensors = getNonOneShotAndNonSpecialSensors();
int32_t maxMinDelay = 0;
- for (const SensorInfo& sensor : getSensorsList()) {
+ for (const SensorInfo& sensor : sensors) {
maxMinDelay = std::max(maxMinDelay, sensor.minDelay);
}
@@ -832,9 +846,14 @@ TEST_F(SensorsHidlTest, NoStaleEvents) {
// Save the last received event for each sensor
std::map<int32_t, int64_t> lastEventTimestampMap;
for (const SensorInfo& sensor : sensors) {
- ASSERT_GE(callback.getEvents(sensor.sensorHandle).size(), 1);
- lastEventTimestampMap[sensor.sensorHandle] =
- callback.getEvents(sensor.sensorHandle).back().timestamp;
+ // Some on-change sensors may not report an event without stimulus
+ if (extractReportMode(sensor.flags) != SensorFlagBits::ON_CHANGE_MODE) {
+ ASSERT_GE(callback.getEvents(sensor.sensorHandle).size(), 1);
+ }
+ if (callback.getEvents(sensor.sensorHandle).size() >= 1) {
+ lastEventTimestampMap[sensor.sensorHandle] =
+ callback.getEvents(sensor.sensorHandle).back().timestamp;
+ }
}
// Allow some time to pass, reset the callback, then reactivate the sensors
@@ -845,6 +864,14 @@ TEST_F(SensorsHidlTest, NoStaleEvents) {
activateAllSensors(false);
for (const SensorInfo& sensor : sensors) {
+ // Skip sensors that did not previously report an event
+ if (lastEventTimestampMap.find(sensor.sensorHandle) == lastEventTimestampMap.end()) {
+ continue;
+ }
+ // Skip on-change sensors that do not consistently report an initial event
+ if (callback.getEvents(sensor.sensorHandle).size() < 1) {
+ continue;
+ }
// 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();