From f62c91f057bb6d8962f6cfc686e382cb8cada4ad Mon Sep 17 00:00:00 2001 From: Zhuoyao Zhang Date: Tue, 23 Jan 2018 18:16:27 -0800 Subject: [PATCH] Convert audio hal test to use VtsHalHidlTargetTestEnvBase Bug: 64203181 Test: make vts vts-tradefed run vts -m VtsHalAudioV2_0Target Change-Id: I1f85216c992eabf70f7e907b5d2afc4fb59cbb4a --- .../utility/include/utility/EnvironmentTearDown.h | 5 +++-- .../2.0/vts/functional/AudioPrimaryHidlHalTest.cpp | 13 ++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h b/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h index 81d92c2470..a96d06e048 100644 --- a/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h +++ b/audio/common/all-versions/test/utility/include/utility/EnvironmentTearDown.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace android { @@ -33,13 +34,13 @@ namespace utility { * Avoid destroying static objects after main return. * Post main return destruction leads to incorrect gtest timing measurements as * well as harder debuging if anything goes wrong during destruction. */ -class Environment : public ::testing::Environment { +class Environment : public ::testing::VtsHalHidlTargetTestEnvBase { public: using TearDownFunc = std::function; void registerTearDown(TearDownFunc&& tearDown) { tearDowns.push_back(std::move(tearDown)); } private: - void TearDown() override { + void HidlTearDown() override { // Call the tear downs in reverse order of insertion for (auto& tearDown : tearDowns) { tearDown(); diff --git a/audio/core/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/core/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp index 6c09da7e24..bb1d26f928 100644 --- a/audio/core/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp @@ -88,8 +88,13 @@ using ::android::hardware::audio::common::V2_0::ThreadInfo; using namespace ::android::hardware::audio::common::test::utility; +class AudioHidlTestEnvironment : public ::Environment { + public: + virtual void registerTestServices() override { registerTestService(); } +}; + // Instance to register global tearDown -static Environment* environment; +static AudioHidlTestEnvironment* environment; class HidlTest : public ::testing::VtsHalHidlTargetTestBase { protected: @@ -109,7 +114,8 @@ class AudioHidlTest : public HidlTest { if (devicesFactory == nullptr) { environment->registerTearDown([] { devicesFactory.clear(); }); - devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService(); + devicesFactory = ::testing::VtsHalHidlTargetTestBase::getService( + environment->getServiceName("default")); } ASSERT_TRUE(devicesFactory != nullptr); } @@ -1265,9 +1271,10 @@ TEST_F(BoolAccessorPrimaryHidlTest, setGetHac) { ////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { - environment = new Environment; + environment = new AudioHidlTestEnvironment; ::testing::AddGlobalTestEnvironment(environment); ::testing::InitGoogleTest(&argc, argv); + environment->init(&argc, argv); int status = RUN_ALL_TESTS(); return status; }