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
This commit is contained in:
Anthony Stange
2020-03-04 13:34:14 -05:00
parent 4a936e3751
commit e969e81bee
3 changed files with 26 additions and 17 deletions

View File

@@ -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;
}
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);
}
});
for (const auto& e : events) {
env->addEvent(e);
}
})
.isOk()) {
break;
}
}
ALOGD("polling thread end");
}

View File

@@ -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) {}

View File

@@ -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.