From 2aba02af56bee0cb756ee4a47cf77b54d380476f Mon Sep 17 00:00:00 2001 From: Zhuoyao Zhang Date: Mon, 20 Nov 2017 17:36:47 -0800 Subject: Convert boot, memtrack and power hal to use service name aware testing. Motivation: 1) Support running the test against each hal service instance for the registered hal. 2) Support testability checker to determine whether we should run the test on the taget device. 3) Help to determine the process we want to profile for coverage data if running on coverage build. Bug: 64203181 Test: make vts vts-tradefed run vts -m VtsHalBootV1_0Target vts-tradefed run vts -m VtsHalMemtrackV1_0Target vts-tradefed run vts -m VtsHalPowerV1_0Target vts-tradefed run vts -m VtsHalPowerV1_1Target Change-Id: Ie0bbd9ef9d9fbe11de5aee70fad9028fa0ae897c --- .../vts/functional/VtsHalPowerV1_0TargetTest.cpp | 28 +++++++++++++++++----- .../vts/functional/VtsHalPowerV1_1TargetTest.cpp | 28 +++++++++++++++++----- 2 files changed, 44 insertions(+), 12 deletions(-) (limited to 'power') diff --git a/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp b/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp index da49dfcf3..999b2b420 100644 --- a/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp +++ b/power/1.0/vts/functional/VtsHalPowerV1_0TargetTest.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -44,11 +45,24 @@ using std::vector; #define AVAILABLE_GOVERNORS_PATH \ "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors" +// Test environment for Power HIDL HAL. +class PowerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static PowerHidlEnvironment* Instance() { + static PowerHidlEnvironment* instance = new PowerHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService(); } +}; + class PowerHidlTest : public ::testing::VtsHalHidlTargetTestBase { public: virtual void SetUp() override { - power = ::testing::VtsHalHidlTargetTestBase::getService(); - ASSERT_NE(power, nullptr); + power = ::testing::VtsHalHidlTargetTestBase::getService( + PowerHidlEnvironment::Instance()->getServiceName()); + ASSERT_NE(power, nullptr); } virtual void TearDown() override {} @@ -178,8 +192,10 @@ TEST_F(PowerHidlTest, GetPlatformLowPowerStats) { } int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; + ::testing::AddGlobalTestEnvironment(PowerHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + PowerHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; } diff --git a/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp b/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp index dc843f49d..4427b1550 100644 --- a/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp +++ b/power/1.1/vts/functional/VtsHalPowerV1_1TargetTest.cpp @@ -19,6 +19,7 @@ #include #include +#include using ::android::hardware::power::V1_1::IPower; using ::android::hardware::power::V1_1::PowerStateSubsystem; @@ -28,11 +29,24 @@ using ::android::hardware::hidl_vec; using ::android::hardware::Return; using ::android::sp; +// Test environment for Power HIDL HAL. +class PowerHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { + public: + // get the test environment singleton + static PowerHidlEnvironment* Instance() { + static PowerHidlEnvironment* instance = new PowerHidlEnvironment; + return instance; + } + + virtual void registerTestServices() override { registerTestService(); } +}; + class PowerHidlTest : public ::testing::VtsHalHidlTargetTestBase { public: virtual void SetUp() override { - power = ::testing::VtsHalHidlTargetTestBase::getService(); - ASSERT_NE(power, nullptr); + power = ::testing::VtsHalHidlTargetTestBase::getService( + PowerHidlEnvironment::Instance()->getServiceName()); + ASSERT_NE(power, nullptr); } virtual void TearDown() override {} @@ -91,8 +105,10 @@ TEST_F(PowerHidlTest, PowerHintAsync) { } int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; + ::testing::AddGlobalTestEnvironment(PowerHidlEnvironment::Instance()); + ::testing::InitGoogleTest(&argc, argv); + PowerHidlEnvironment::Instance()->init(&argc, argv); + int status = RUN_ALL_TESTS(); + LOG(INFO) << "Test result = " << status; + return status; } -- cgit v1.2.3