Merge "Convert gnss hal test to use VtsHalHidlTargetTestEnvBase"
diff --git a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
index 6c9aa18..b9f505d 100644
--- a/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
+++ b/bluetooth/1.0/vts/functional/VtsHalBluetoothV1_0TargetTest.cpp
@@ -25,6 +25,7 @@
 
 #include <VtsHalHidlTargetCallbackBase.h>
 #include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <queue>
 
 using ::android::hardware::bluetooth::V1_0::IBluetoothHci;
@@ -126,6 +127,23 @@
   std::chrono::steady_clock::time_point start_time_;
 };
 
+// Test environment for Bluetooth HIDL HAL.
+class BluetoothHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+ public:
+  // get the test environment singleton
+  static BluetoothHidlEnvironment* Instance() {
+    static BluetoothHidlEnvironment* instance = new BluetoothHidlEnvironment;
+    return instance;
+  }
+
+  virtual void registerTestServices() override {
+    registerTestService<IBluetoothHci>();
+  }
+
+ private:
+  BluetoothHidlEnvironment() {}
+};
+
 // The main test class for Bluetooth HIDL HAL.
 class BluetoothHidlTest : public ::testing::VtsHalHidlTargetTestBase {
  public:
@@ -251,15 +269,6 @@
   int max_sco_data_packets;
 };
 
-// A class for test environment setup (kept since this file is a template).
-class BluetoothHidlEnvironment : public ::testing::Environment {
- public:
-  virtual void SetUp() {}
-  virtual void TearDown() {}
-
- private:
-};
-
 // Receive and check status events until a COMMAND_COMPLETE is received.
 void BluetoothHidlTest::wait_for_command_complete_event(hidl_vec<uint8_t> cmd) {
   // Allow intermediate COMMAND_STATUS events
@@ -662,8 +671,9 @@
 }
 
 int main(int argc, char** argv) {
-  ::testing::AddGlobalTestEnvironment(new BluetoothHidlEnvironment);
+  ::testing::AddGlobalTestEnvironment(BluetoothHidlEnvironment::Instance());
   ::testing::InitGoogleTest(&argc, argv);
+  BluetoothHidlEnvironment::Instance()->init(&argc, argv);
   int status = RUN_ALL_TESTS();
   ALOGI("Test result = %d", status);
   return status;
diff --git a/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp b/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp
index 3405422..13290d9 100644
--- a/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp
+++ b/light/2.0/vts/functional/VtsHalLightV2_0TargetTest.cpp
@@ -16,12 +16,13 @@
 
 #define LOG_TAG "light_hidl_hal_test"
 
+#include <VtsHalHidlTargetTestBase.h>
+#include <VtsHalHidlTargetTestEnvBase.h>
 #include <android-base/logging.h>
 #include <android/hardware/light/2.0/ILight.h>
 #include <android/hardware/light/2.0/types.h>
-#include <VtsHalHidlTargetTestBase.h>
-#include <set>
 #include <unistd.h>
+#include <set>
 
 using ::android::hardware::light::V2_0::Brightness;
 using ::android::hardware::light::V2_0::Flash;
@@ -72,10 +73,25 @@
     Type::WIFI
 };
 
+// Test environment for Light HIDL HAL.
+class LightHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
+   public:
+    // get the test environment singleton
+    static LightHidlEnvironment* Instance() {
+        static LightHidlEnvironment* instance = new LightHidlEnvironment;
+        return instance;
+    }
+
+    virtual void registerTestServices() override { registerTestService<ILight>(); }
+   private:
+    LightHidlEnvironment() {}
+};
+
 class LightHidlTest : public ::testing::VtsHalHidlTargetTestBase {
 public:
     virtual void SetUp() override {
-        light = ::testing::VtsHalHidlTargetTestBase::getService<ILight>();
+        light = ::testing::VtsHalHidlTargetTestBase::getService<ILight>(
+            LightHidlEnvironment::Instance()->getServiceName<ILight>());
 
         ASSERT_NE(light, nullptr);
         LOG(INFO) << "Test is remote " << light->isRemote();
@@ -149,7 +165,9 @@
 }
 
 int main(int argc, char **argv) {
+    ::testing::AddGlobalTestEnvironment(LightHidlEnvironment::Instance());
     ::testing::InitGoogleTest(&argc, argv);
+    LightHidlEnvironment::Instance()->init(&argc, argv);
     int status = RUN_ALL_TESTS();
     LOG(INFO) << "Test result = " << status;
     return status;