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

Commit 11c4534f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Convert VtsHalThermalV*TargetTest to be parameterized test"

parents b046c4eb 030bef33
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,6 +19,6 @@ cc_test {
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: ["VtsHalThermalV1_0TargetTest.cpp"],
    static_libs: ["android.hardware.thermal@1.0"],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}
+12 −30
Original line number Diff line number Diff line
@@ -21,11 +21,12 @@

#define LOG_TAG "thermal_hidl_hal_test"

#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <android-base/logging.h>
#include <android/hardware/thermal/1.0/IThermal.h>
#include <android/hardware/thermal/1.0/types.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <unistd.h>

using ::android::hardware::hidl_string;
@@ -46,26 +47,11 @@ using ::android::sp;
#define MAX_DEVICE_TEMPERATURE 200
#define MAX_FAN_SPEED 20000

// Test environment for Thermal HIDL HAL.
class ThermalHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
 public:
  // get the test environment singleton
  static ThermalHidlEnvironment* Instance() {
    static ThermalHidlEnvironment* instance = new ThermalHidlEnvironment;
    return instance;
  }

  virtual void registerTestServices() override { registerTestService<IThermal>(); }
 private:
  ThermalHidlEnvironment() {}
};

// The main test class for THERMAL HIDL HAL.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class ThermalHidlTest : public testing::TestWithParam<std::string> {
 public:
  virtual void SetUp() override {
    thermal_ = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
        ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
    thermal_ = IThermal::getService(GetParam());
    ASSERT_NE(thermal_, nullptr);
    baseSize_ = 0;
    names_.clear();
@@ -178,7 +164,7 @@ class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
};

// Sanity test for Thermal::getTemperatures().
TEST_F(ThermalHidlTest, TemperatureTest) {
TEST_P(ThermalHidlTest, TemperatureTest) {
  hidl_vec<Temperature> passed;
  for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) {
    thermal_->getTemperatures(
@@ -193,7 +179,7 @@ TEST_F(ThermalHidlTest, TemperatureTest) {
}

// Sanity test for Thermal::getCpuUsages().
TEST_F(ThermalHidlTest, CpuUsageTest) {
TEST_P(ThermalHidlTest, CpuUsageTest) {
  hidl_vec<CpuUsage> passed;
  for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) {
    thermal_->getCpuUsages(
@@ -208,7 +194,7 @@ TEST_F(ThermalHidlTest, CpuUsageTest) {
}

// Sanity test for Thermal::getCoolingDevices().
TEST_F(ThermalHidlTest, CoolingDeviceTest) {
TEST_P(ThermalHidlTest, CoolingDeviceTest) {
  hidl_vec<CoolingDevice> passed;
  for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) {
    thermal_->getCoolingDevices([&passed](
@@ -222,11 +208,7 @@ TEST_F(ThermalHidlTest, CoolingDeviceTest) {
  }
}

int main(int argc, char** argv) {
  ::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance());
  ::testing::InitGoogleTest(&argc, argv);
  ThermalHidlEnvironment::Instance()->init(&argc, argv);
  int status = RUN_ALL_TESTS();
  LOG(INFO) << "Test result = " << status;
  return status;
}
INSTANTIATE_TEST_SUITE_P(
        PerInstance, ThermalHidlTest,
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)),
        android::hardware::PrintInstanceNameToString);
+1 −2
Original line number Diff line number Diff line
@@ -22,6 +22,5 @@ cc_test {
        "android.hardware.thermal@1.0",
        "android.hardware.thermal@1.1",
    ],
    test_suites: ["general-tests"],
    test_suites: ["general-tests", "vts-core"],
}
+10 −28
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@
#include <android/hardware/thermal/1.1/IThermal.h>
#include <android/hardware/thermal/1.1/IThermalCallback.h>
#include <android/hardware/thermal/1.0/types.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>

#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>

using ::android::hardware::thermal::V1_0::Temperature;
using ::android::hardware::thermal::V1_0::TemperatureType;
@@ -63,26 +64,11 @@ class ThermalCallback
    }
};

// Test environment for Thermal HIDL HAL.
class ThermalHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
   public:
    // get the test environment singleton
    static ThermalHidlEnvironment* Instance() {
        static ThermalHidlEnvironment* instance = new ThermalHidlEnvironment;
        return instance;
    }

    virtual void registerTestServices() override { registerTestService<IThermal>(); }
   private:
    ThermalHidlEnvironment() {}
};

// The main test class for THERMAL HIDL HAL 1.1.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class ThermalHidlTest : public testing::TestWithParam<std::string> {
   public:
    virtual void SetUp() override {
        mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
            ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
        mThermal = IThermal::getService(GetParam());
        ASSERT_NE(mThermal, nullptr);
        mThermalCallback = new(std::nothrow) ThermalCallback();
        ASSERT_NE(mThermalCallback, nullptr);
@@ -104,7 +90,7 @@ class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
// This just calls into and back from our local ThermalCallback impl.
// Note: a real thermal throttling event from the Thermal HAL could be
// inadvertently received here.
TEST_F(ThermalHidlTest, NotifyThrottlingTest) {
TEST_P(ThermalHidlTest, NotifyThrottlingTest) {
    auto ret = mThermalCallback->notifyThrottling(true, kThrottleTemp);
    ASSERT_TRUE(ret.isOk());
    auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling);
@@ -114,11 +100,7 @@ TEST_F(ThermalHidlTest, NotifyThrottlingTest) {
    EXPECT_EQ(kThrottleTemp, res.args->temperature);
}

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance());
    ::testing::InitGoogleTest(&argc, argv);
    ThermalHidlEnvironment::Instance()->init(&argc, argv);
    int status = RUN_ALL_TESTS();
    cout << "Test result = " << status << std::endl;
    return status;
}
INSTANTIATE_TEST_SUITE_P(
        PerInstance, ThermalHidlTest,
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)),
        android::hardware::PrintInstanceNameToString);
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -22,5 +22,6 @@ cc_test {
        "android.hardware.thermal@1.0",
        "android.hardware.thermal@2.0",
    ],
    test_suites: ["general-tests", "vts-core"],
}
Loading