summaryrefslogtreecommitdiffstats
path: root/sensors
diff options
context:
space:
mode:
authorAnthony Stange <stange@google.com>2020-03-04 13:34:14 -0500
committerAnthony Stange <stange@google.com>2020-03-04 18:44:06 +0000
commite969e81bee10d2d5b6b64b9b0d48af69c3f8b5fe (patch)
treeae82fdd8a876ee3bf743caaade50c1788f793f2c /sensors
parent4a936e375194afd857fcbd849904dba50e19fc93 (diff)
downloadplatform_hardware_interfaces-e969e81bee10d2d5b6b64b9b0d48af69c3f8b5fe.tar.gz
platform_hardware_interfaces-e969e81bee10d2d5b6b64b9b0d48af69c3f8b5fe.tar.bz2
platform_hardware_interfaces-e969e81bee10d2d5b6b64b9b0d48af69c3f8b5fe.zip
Fix Sensors HAL 1.0 VTS tests
HAL 1.0 VTS tests need to detach the polling thread or it will never exit on its own. Additionally, the poll() methods return status needs to be checked or HIDL will assert and cause the program to crash. Bug: 150475314 Test: atest VtsHalSensorsV1_0TargetTest VtsHalSensorsV2_0TargetTest Change-Id: I626b7aa064a1f258c968d1787872b9c67786dede
Diffstat (limited to 'sensors')
-rw-r--r--sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.cpp36
-rw-r--r--sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.h2
-rw-r--r--sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlEnvironmentBase.h7
3 files changed, 27 insertions, 18 deletions
diff --git a/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.cpp b/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.cpp
index 1e5e886288..aca6961e0d 100644
--- a/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.cpp
+++ b/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.cpp
@@ -25,6 +25,13 @@ using ::android::hardware::sensors::V1_0::ISensors;
using ::android::hardware::sensors::V1_0::Result;
using ::android::hardware::sensors::V1_0::SensorInfo;
+void SensorsHidlEnvironmentV1_0::HidlTearDown() {
+ mStopThread = true;
+ if (mPollThread.joinable()) {
+ mPollThread.detach();
+ }
+}
+
bool SensorsHidlEnvironmentV1_0::resetHal() {
// wait upto 100ms * 10 = 1s for hidl service.
constexpr auto RETRY_DELAY = std::chrono::milliseconds(100);
@@ -103,18 +110,23 @@ void SensorsHidlEnvironmentV1_0::pollingThread(SensorsHidlEnvironmentV1_0* env,
ALOGD("polling thread start");
while (!stop) {
- env->sensors->poll(
- 64, [&](auto result, const auto& events, const auto& dynamicSensorsAdded) {
- if (result != Result::OK ||
- (events.size() == 0 && dynamicSensorsAdded.size() == 0) || stop) {
- stop = true;
- return;
- }
-
- for (const auto& e : events) {
- env->addEvent(e);
- }
- });
+ if (!env->sensors
+ ->poll(64,
+ [&](auto result, const auto& events, const auto& dynamicSensorsAdded) {
+ if (result != Result::OK ||
+ (events.size() == 0 && dynamicSensorsAdded.size() == 0) ||
+ stop) {
+ stop = true;
+ return;
+ }
+
+ for (const auto& e : events) {
+ env->addEvent(e);
+ }
+ })
+ .isOk()) {
+ break;
+ }
}
ALOGD("polling thread end");
} \ No newline at end of file
diff --git a/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.h b/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.h
index 485ed1ed87..168777d8be 100644
--- a/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.h
+++ b/sensors/1.0/vts/functional/SensorsHidlEnvironmentV1_0.h
@@ -32,6 +32,8 @@ class SensorsHidlTest;
class SensorsHidlEnvironmentV1_0
: public SensorsHidlEnvironmentBase<::android::hardware::sensors::V1_0::Event> {
public:
+ void HidlTearDown() override;
+
using Event = ::android::hardware::sensors::V1_0::Event;
SensorsHidlEnvironmentV1_0(const std::string& service_name)
: SensorsHidlEnvironmentBase(service_name) {}
diff --git a/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlEnvironmentBase.h b/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlEnvironmentBase.h
index 781427d827..19dfbe55e4 100644
--- a/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlEnvironmentBase.h
+++ b/sensors/common/vts/utils/include/sensors-vts-utils/SensorsHidlEnvironmentBase.h
@@ -46,12 +46,7 @@ class SensorsHidlEnvironmentBase {
std::this_thread::sleep_for(std::chrono::seconds(3));
}
- virtual void HidlTearDown() {
- mStopThread = true;
- if (mPollThread.joinable()) {
- mPollThread.join();
- }
- }
+ virtual void HidlTearDown() = 0;
// Get and clear all events collected so far (like "cat" shell command).
// If output is nullptr, it clears all collected events.