Convert VtsHalThermalV*TargetTest to be parameterized test

Bug: 142397658
Test: atest
Change-Id: I5846cab420671e7c3d2bfe80034a7b612ec2e47b
diff --git a/thermal/2.0/vts/functional/Android.bp b/thermal/2.0/vts/functional/Android.bp
index f4e95f8..0940576 100644
--- a/thermal/2.0/vts/functional/Android.bp
+++ b/thermal/2.0/vts/functional/Android.bp
@@ -22,5 +22,6 @@
         "android.hardware.thermal@1.0",
         "android.hardware.thermal@2.0",
     ],
+    test_suites: ["general-tests", "vts-core"],
 }
 
diff --git a/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp b/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp
index d0f2e84..75536a6 100644
--- a/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp
+++ b/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp
@@ -18,9 +18,11 @@
 #include <android/hardware/thermal/2.0/IThermalChangedCallback.h>
 #include <android/hardware/thermal/2.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::sp;
 using ::android::hardware::hidl_enum_range;
@@ -63,27 +65,11 @@
     }
 };
 
-// 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;
-    }
-
-    void registerTestServices() override { registerTestService<IThermal>(); }
-
-   private:
-    ThermalHidlEnvironment() {}
-};
-
 // The main test class for THERMAL HIDL HAL 2.0.
-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);
@@ -119,7 +105,7 @@
 // This just calls into and back from our local ThermalChangedCallback 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(kThrottleTemp);
     ASSERT_TRUE(ret.isOk());
     auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling);
@@ -129,7 +115,7 @@
 }
 
 // Test Thermal->registerThermalChangedCallback.
-TEST_F(ThermalHidlTest, RegisterThermalChangedCallbackTest) {
+TEST_P(ThermalHidlTest, RegisterThermalChangedCallbackTest) {
     // Expect to fail with same callback
     auto ret = mThermal->registerThermalChangedCallback(
             mThermalCallback, false, TemperatureType::SKIN,
@@ -159,7 +145,7 @@
 }
 
 // Test Thermal->unregisterThermalChangedCallback.
-TEST_F(ThermalHidlTest, UnregisterThermalChangedCallbackTest) {
+TEST_P(ThermalHidlTest, UnregisterThermalChangedCallbackTest) {
     sp<ThermalCallback> localThermalCallback = new (std::nothrow) ThermalCallback();
     // Expect to fail as the callback was not registered before
     auto ret = mThermal->unregisterThermalChangedCallback(
@@ -184,7 +170,7 @@
 }
 
 // Sanity test for Thermal::getCurrentTemperatures().
-TEST_F(ThermalHidlTest, TemperatureTest) {
+TEST_P(ThermalHidlTest, TemperatureTest) {
     mThermal->getCurrentTemperatures(false, TemperatureType::SKIN,
                                      [](ThermalStatus status, hidl_vec<Temperature> temperatures) {
                                          if (temperatures.size()) {
@@ -214,7 +200,7 @@
 }
 
 // Sanity test for Thermal::getTemperatureThresholds().
-TEST_F(ThermalHidlTest, TemperatureThresholdTest) {
+TEST_P(ThermalHidlTest, TemperatureThresholdTest) {
     mThermal->getTemperatureThresholds(
         false, TemperatureType::SKIN,
         [](ThermalStatus status, hidl_vec<TemperatureThreshold> temperatures) {
@@ -242,7 +228,7 @@
 }
 
 // Sanity test for Thermal::getCurrentCoolingDevices().
-TEST_F(ThermalHidlTest, CoolingDeviceTest) {
+TEST_P(ThermalHidlTest, CoolingDeviceTest) {
     mThermal->getCurrentCoolingDevices(
         false, CoolingType::CPU, [](ThermalStatus status, hidl_vec<CoolingDevice> cooling_devices) {
             if (cooling_devices.size()) {
@@ -271,11 +257,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();
-    cout << "Test result = " << status << std::endl;
-    return status;
-}
+INSTANTIATE_TEST_SUITE_P(
+        PerInstance, ThermalHidlTest,
+        testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)),
+        android::hardware::PrintInstanceNameToString);