Convert VtsHalThermalV*TargetTest to be parameterized test

Bug: 142397658
Test: atest
Change-Id: I5846cab420671e7c3d2bfe80034a7b612ec2e47b
diff --git a/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp b/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp
index 6f059ef..aa1c0ce 100644
--- a/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp
+++ b/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp
@@ -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 @@
 #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 @@
 };
 
 // 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 @@
 }
 
 // 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 @@
 }
 
 // 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 @@
   }
 }
 
-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);