From 91456084c29c6f4a3f629d7c44631ee3ee3b29e6 Mon Sep 17 00:00:00 2001 From: Zhuoyao Zhang Date: Thu, 8 Feb 2018 20:55:27 -0800 Subject: [PATCH] Convert health hal test to use VtsHalHidlTargetTestEnvBase Bug: 64203181 Test: make vts vts-tradefed run vts -m VtsHalHealthV1_0Target Change-Id: Ibbe9421b5a737d7eb2d021bd64757a548d3c95fc --- .../functional/VtsHalHealthV1_0TargetTest.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/health/1.0/vts/functional/VtsHalHealthV1_0TargetTest.cpp b/health/1.0/vts/functional/VtsHalHealthV1_0TargetTest.cpp index 324eb9ff95..335d15d172 100644 --- a/health/1.0/vts/functional/VtsHalHealthV1_0TargetTest.cpp +++ b/health/1.0/vts/functional/VtsHalHealthV1_0TargetTest.cpp @@ -19,7 +19,9 @@ #include #include #include + #include +#include using HealthConfig = ::android::hardware::health::V1_0::HealthConfig; using HealthInfo = ::android::hardware::health::V1_0::HealthInfo; @@ -28,10 +30,25 @@ using Result = ::android::hardware::health::V1_0::Result; using ::android::sp; +// Test environment for Health HIDL HAL. +class HealthHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static HealthHidlEnvironment* Instance() { + static HealthHidlEnvironment* instance = new HealthHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService(); } + private: + HealthHidlEnvironment() {} +}; + class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase { public: virtual void SetUp() override { - health = ::testing::VtsHalHidlTargetTestBase::getService(); + health = ::testing::VtsHalHidlTargetTestBase::getService( + HealthHidlEnvironment::Instance()->getServiceName()); ASSERT_NE(health, nullptr); health->init(config, [&](const auto& halConfigOut) { config = halConfigOut; }); @@ -57,7 +74,9 @@ TEST_F(HealthHidlTest, TestEnergyCounter) { } int main(int argc, char **argv) { + ::testing::AddGlobalTestEnvironment(HealthHidlEnvironment::Instance()); ::testing::InitGoogleTest(&argc, argv); + HealthHidlEnvironment::Instance()->init(&argc, argv); int status = RUN_ALL_TESTS(); ALOGI("Test result = %d", status); return status;