Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e969e81b authored by Anthony Stange's avatar Anthony Stange
Browse files

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
parent 4a936e37
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -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,10 +110,12 @@ 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 (!env->sensors
                     ->poll(64,
                            [&](auto result, const auto& events, const auto& dynamicSensorsAdded) {
                                if (result != Result::OK ||
                    (events.size() == 0 && dynamicSensorsAdded.size() == 0) || stop) {
                                    (events.size() == 0 && dynamicSensorsAdded.size() == 0) ||
                                    stop) {
                                    stop = true;
                                    return;
                                }
@@ -114,7 +123,10 @@ void SensorsHidlEnvironmentV1_0::pollingThread(SensorsHidlEnvironmentV1_0* env,
                                for (const auto& e : events) {
                                    env->addEvent(e);
                                }
            });
                            })
                     .isOk()) {
            break;
        }
    }
    ALOGD("polling thread end");
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -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) {}
+1 −6
Original line number Diff line number Diff line
@@ -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.