diff --git a/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp b/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp index 91e75fe1d7..8b3185dd0d 100644 --- a/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp +++ b/gnss/1.0/vts/functional/VtsHalGnssV1_0TargetTest.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -41,6 +42,21 @@ using android::sp; bool sAgpsIsPresent = false; // if SUPL or XTRA assistance available bool sSignalIsWeak = false; // if GNSS signals are weak (e.g. light indoor) +// Test environment for GNSS HIDL HAL. +class GnssHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static GnssHidlEnvironment* Instance() { + static GnssHidlEnvironment* instance = new GnssHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService(); } + + private: + GnssHidlEnvironment() {} +}; + // The main test class for GNSS HAL. class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { public: @@ -51,7 +67,8 @@ class GnssHalTest : public ::testing::VtsHalHidlTargetTestBase { info_called_count_ = 0; notify_count_ = 0; - gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService(); + gnss_hal_ = ::testing::VtsHalHidlTargetTestBase::getService( + GnssHidlEnvironment::Instance()->getServiceName()); ASSERT_NE(gnss_hal_, nullptr); gnss_cb_ = new GnssCallback(*this); @@ -449,17 +466,19 @@ TEST_F(GnssHalTest, MeasurementCapabilites) { } int main(int argc, char** argv) { + ::testing::AddGlobalTestEnvironment(GnssHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); + GnssHidlEnvironment::Instance()->init(&argc, argv); /* * These arguments not used by automated VTS testing. * Only for use in manual testing, when wanting to run * stronger tests that require the presence of GPS signal. */ for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-agps") == 0) { - sAgpsIsPresent = true; - } else if (strcmp(argv[i], "-weak") == 0) { - sSignalIsWeak = true; + if (strcmp(argv[i], "-agps") == 0) { + sAgpsIsPresent = true; + } else if (strcmp(argv[i], "-weak") == 0) { + sSignalIsWeak = true; } } int status = RUN_ALL_TESTS();