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

Commit 733ee165 authored by Zhuoyao Zhang's avatar Zhuoyao Zhang
Browse files

Convert sensors HAL test to use VtsHalHidlTargetTestEnvBase

Bug: 64203181
Test: make vts
      vts-tradefed run vts -m VtsHalSensorsV1_0Target

Change-Id: I1f7e3a8adf58bbeeb0928185a61f16610dd76223
parent 204314ac
Loading
Loading
Loading
Loading
+49 −44
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
 */

#define LOG_TAG "sensors_hidl_hal_test"
#include "GrallocWrapper.h"
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <android-base/logging.h>
#include <android/hardware/sensors/1.0/ISensors.h>
#include <android/hardware/sensors/1.0/types.h>
@@ -24,6 +24,7 @@
#include <hardware/sensors.h>  // for sensor type strings
#include <log/log.h>
#include <utils/SystemClock.h>
#include "GrallocWrapper.h"

#include <algorithm>
#include <cinttypes>
@@ -46,7 +47,7 @@ using namespace ::android::hardware::sensors::V1_0;

// Test environment for sensors
class SensorsHidlTest;
class SensorsHidlEnvironment : public ::testing::Environment {
class SensorsHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
   public:
    // get the test environment singleton
    static SensorsHidlEnvironment* Instance() {
@@ -54,8 +55,10 @@ class SensorsHidlEnvironment : public ::testing::Environment {
        return instance;
    }

  virtual void SetUp();
  virtual void TearDown();
    virtual void HidlSetUp() override;
    virtual void HidlTearDown() override;

    virtual void registerTestServices() override { registerTestService<ISensors>(); }

    // Get and clear all events collected so far (like "cat" shell command).
    // If output is nullptr, it clears all collected events.
@@ -85,7 +88,7 @@ class SensorsHidlEnvironment : public ::testing::Environment {
    GTEST_DISALLOW_COPY_AND_ASSIGN_(SensorsHidlEnvironment);
};

void SensorsHidlEnvironment::SetUp() {
void SensorsHidlEnvironment::HidlSetUp() {
    resetHal();

    ASSERT_NE(sensors, nullptr) << "sensors is nullptr, cannot get hidl service";
@@ -98,7 +101,7 @@ void SensorsHidlEnvironment::SetUp() {
    std::this_thread::sleep_for(std::chrono::seconds(3));
}

void SensorsHidlEnvironment::TearDown() {
void SensorsHidlEnvironment::HidlTearDown() {
    if (stopThread) {
        *stopThread = true;
    }
@@ -115,7 +118,8 @@ void SensorsHidlEnvironment::resetHal() {
    // this do ... while is for easy error handling
    do {
      step = "getService()";
      sensors = ISensors::getService();
      sensors = ISensors::getService(
          SensorsHidlEnvironment::Instance()->getServiceName<ISensors>());
      if (sensors == nullptr) {
        break;
      }
@@ -1500,6 +1504,7 @@ TEST_F(SensorsHidlTest, MagnetometerGrallocDirectReportOperationVeryFast) {
int main(int argc, char **argv) {
  ::testing::AddGlobalTestEnvironment(SensorsHidlEnvironment::Instance());
  ::testing::InitGoogleTest(&argc, argv);
  SensorsHidlEnvironment::Instance()->init(&argc, argv);
  int status = RUN_ALL_TESTS();
  ALOGI("Test result = %d", status);
  return status;