diff options
author | Brian Stack <bstack@google.com> | 2018-11-05 15:43:28 -0800 |
---|---|---|
committer | Brian Stack <bstack@google.com> | 2018-11-14 15:18:50 -0800 |
commit | 00c4288d665f3bfa90e2443273da4c82fa121eda (patch) | |
tree | dd9d65d518fbafcad2b859a05fe5e2a04ed5c582 /sensors | |
parent | 26427a6bca962a1b6f841f0b8ff1545544d0e8ee (diff) | |
download | android_hardware_interfaces-00c4288d665f3bfa90e2443273da4c82fa121eda.tar.gz android_hardware_interfaces-00c4288d665f3bfa90e2443273da4c82fa121eda.tar.bz2 android_hardware_interfaces-00c4288d665f3bfa90e2443273da4c82fa121eda.zip |
Data Injection Tests for Sensors HAL 2.0
Implements VTS tests for Sensors HAL 2.0 DATA_INJECTION mode. Ensures
that if a sensor reports that it supports data injection, events that
are injected while in data injection mode are written back to the
Event FMQ. Ensures that AdditionalInfo events not written to the
Event FMQ.
Bug: 115969174
Test: Data injection tests pass against default Sensors HAL 2.0
Change-Id: I350956b759e14abfff73de4e20384524bbc00a0f
Diffstat (limited to 'sensors')
-rw-r--r-- | sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp | 111 |
1 files changed, 65 insertions, 46 deletions
diff --git a/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp b/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp index 3e5837bec..cc78af3db 100644 --- a/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp +++ b/sensors/2.0/vts/functional/VtsHalSensorsV2_0TargetTest.cpp @@ -164,6 +164,7 @@ class SensorsHidlTest : public SensorsHidlTestBase { void activateAllSensors(bool enable); std::vector<SensorInfo> getNonOneShotSensors(); std::vector<SensorInfo> getOneShotSensors(); + std::vector<SensorInfo> getInjectEventSensors(); int32_t getInvalidSensorHandle(); }; @@ -243,6 +244,16 @@ std::vector<SensorInfo> SensorsHidlTest::getOneShotSensors() { return sensors; } +std::vector<SensorInfo> SensorsHidlTest::getInjectEventSensors() { + std::vector<SensorInfo> sensors; + for (const SensorInfo& info : getSensorsList()) { + if (info.flags & static_cast<uint32_t>(SensorFlagBits::DATA_INJECTION)) { + sensors.push_back(info); + } + } + return sensors; +} + int32_t SensorsHidlTest::getInvalidSensorHandle() { // Find a sensor handle that does not exist in the sensor list int32_t maxHandle = 0; @@ -297,63 +308,71 @@ TEST_F(SensorsHidlTest, SensorListValid) { }); } -// Test if sensor list returned is valid +// Test that SetOperationMode returns the expected value TEST_F(SensorsHidlTest, SetOperationMode) { - std::vector<SensorInfo> sensorList = getSensorsList(); - - bool needOperationModeSupport = - std::any_of(sensorList.begin(), sensorList.end(), - [](const auto& s) { return (s.flags & SensorFlagBits::DATA_INJECTION) != 0; }); - if (!needOperationModeSupport) { - return; + std::vector<SensorInfo> sensors = getInjectEventSensors(); + if (getInjectEventSensors().size() > 0) { + ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL)); + ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::DATA_INJECTION)); + ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL)); + } else { + ASSERT_EQ(Result::BAD_VALUE, getSensors()->setOperationMode(OperationMode::DATA_INJECTION)); } - - ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL)); - ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::DATA_INJECTION)); - ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL)); } -// Test if sensor list returned is valid +// Test that an injected event is written back to the Event FMQ TEST_F(SensorsHidlTest, InjectSensorEventData) { - std::vector<SensorInfo> sensorList = getSensorsList(); - std::vector<SensorInfo> sensorSupportInjection; - - bool needOperationModeSupport = - std::any_of(sensorList.begin(), sensorList.end(), [&sensorSupportInjection](const auto& s) { - bool ret = (s.flags & SensorFlagBits::DATA_INJECTION) != 0; - if (ret) { - sensorSupportInjection.push_back(s); - } - return ret; - }); - if (!needOperationModeSupport) { + std::vector<SensorInfo> sensors = getInjectEventSensors(); + if (sensors.size() == 0) { return; } - ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL)); ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::DATA_INJECTION)); - for (const auto& s : sensorSupportInjection) { - switch (s.type) { - case SensorType::ACCELEROMETER: - case SensorType::GYROSCOPE: - case SensorType::MAGNETIC_FIELD: { - usleep(100000); // sleep 100ms - - Event dummy; - dummy.timestamp = android::elapsedRealtimeNano(); - dummy.sensorType = s.type; - dummy.sensorHandle = s.sensorHandle; - Vec3 v = {1, 2, 3, SensorStatus::ACCURACY_HIGH}; - dummy.u.vec3 = v; - - EXPECT_EQ(Result::OK, getSensors()->injectSensorData(dummy)); - break; - } - default: - break; - } + EventCallback callback; + getEnvironment()->registerCallback(&callback); + + // AdditionalInfo event should not be sent to Event FMQ + Event additionalInfoEvent; + additionalInfoEvent.sensorType = SensorType::ADDITIONAL_INFO; + additionalInfoEvent.timestamp = android::elapsedRealtimeNano(); + + Event injectedEvent; + injectedEvent.timestamp = android::elapsedRealtimeNano(); + Vec3 data = {1, 2, 3, SensorStatus::ACCURACY_HIGH}; + injectedEvent.u.vec3 = data; + + for (const auto& s : sensors) { + additionalInfoEvent.sensorHandle = s.sensorHandle; + EXPECT_EQ(Result::OK, getSensors()->injectSensorData(additionalInfoEvent)); + + injectedEvent.sensorType = s.type; + injectedEvent.sensorHandle = s.sensorHandle; + EXPECT_EQ(Result::OK, getSensors()->injectSensorData(injectedEvent)); + } + + // Wait for events to be written back to the Event FMQ + callback.waitForEvents(sensors, 1000 /* timeoutMs */); + + for (const auto& s : sensors) { + auto events = callback.getEvents(s.sensorHandle); + auto lastEvent = events.back(); + + // Verify that only a single event has been received + ASSERT_EQ(events.size(), 1); + + // Verify that the event received matches the event injected and is not the additional + // info event + ASSERT_EQ(lastEvent.sensorType, s.type); + ASSERT_EQ(lastEvent.sensorType, s.type); + ASSERT_EQ(lastEvent.timestamp, injectedEvent.timestamp); + ASSERT_EQ(lastEvent.u.vec3.x, injectedEvent.u.vec3.x); + ASSERT_EQ(lastEvent.u.vec3.y, injectedEvent.u.vec3.y); + ASSERT_EQ(lastEvent.u.vec3.z, injectedEvent.u.vec3.z); + ASSERT_EQ(lastEvent.u.vec3.status, injectedEvent.u.vec3.status); } + + getEnvironment()->unregisterCallback(); ASSERT_EQ(Result::OK, getSensors()->setOperationMode(OperationMode::NORMAL)); } |