From 030bef33a505ff87f11ec6293a070a9dcc884a1b Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Wed, 16 Oct 2019 14:45:16 -0700 Subject: [PATCH] Convert VtsHalThermalV*TargetTest to be parameterized test Bug: 142397658 Test: atest Change-Id: I5846cab420671e7c3d2bfe80034a7b612ec2e47b --- thermal/1.0/vts/functional/Android.bp | 2 +- .../VtsHalThermalV1_0TargetTest.cpp | 42 +++++----------- thermal/1.1/vts/functional/Android.bp | 3 +- .../VtsHalThermalV1_1TargetTest.cpp | 38 ++++---------- thermal/2.0/vts/functional/Android.bp | 1 + .../VtsHalThermalV2_0TargetTest.cpp | 50 ++++++------------- 6 files changed, 41 insertions(+), 95 deletions(-) diff --git a/thermal/1.0/vts/functional/Android.bp b/thermal/1.0/vts/functional/Android.bp index 6bda558337..d183bd8a0e 100644 --- a/thermal/1.0/vts/functional/Android.bp +++ b/thermal/1.0/vts/functional/Android.bp @@ -19,6 +19,6 @@ cc_test { defaults: ["VtsHalTargetTestDefaults"], srcs: ["VtsHalThermalV1_0TargetTest.cpp"], static_libs: ["android.hardware.thermal@1.0"], - test_suites: ["general-tests"], + test_suites: ["general-tests", "vts-core"], } diff --git a/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp b/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp index 6f059ef5bb..aa1c0ce425 100644 --- a/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp +++ b/thermal/1.0/vts/functional/VtsHalThermalV1_0TargetTest.cpp @@ -21,11 +21,12 @@ #define LOG_TAG "thermal_hidl_hal_test" -#include -#include #include #include #include +#include +#include +#include #include using ::android::hardware::hidl_string; @@ -46,26 +47,11 @@ using ::android::sp; #define MAX_DEVICE_TEMPERATURE 200 #define MAX_FAN_SPEED 20000 -// Test environment for Thermal HIDL HAL. -class ThermalHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static ThermalHidlEnvironment* Instance() { - static ThermalHidlEnvironment* instance = new ThermalHidlEnvironment; - return instance; - } - - virtual void registerTestServices() override { registerTestService(); } - private: - ThermalHidlEnvironment() {} -}; - // The main test class for THERMAL HIDL HAL. -class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { +class ThermalHidlTest : public testing::TestWithParam { public: virtual void SetUp() override { - thermal_ = ::testing::VtsHalHidlTargetTestBase::getService( - ThermalHidlEnvironment::Instance()->getServiceName()); + thermal_ = IThermal::getService(GetParam()); ASSERT_NE(thermal_, nullptr); baseSize_ = 0; names_.clear(); @@ -178,7 +164,7 @@ class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { }; // Sanity test for Thermal::getTemperatures(). -TEST_F(ThermalHidlTest, TemperatureTest) { +TEST_P(ThermalHidlTest, TemperatureTest) { hidl_vec passed; for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) { thermal_->getTemperatures( @@ -193,7 +179,7 @@ TEST_F(ThermalHidlTest, TemperatureTest) { } // Sanity test for Thermal::getCpuUsages(). -TEST_F(ThermalHidlTest, CpuUsageTest) { +TEST_P(ThermalHidlTest, CpuUsageTest) { hidl_vec passed; for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) { thermal_->getCpuUsages( @@ -208,7 +194,7 @@ TEST_F(ThermalHidlTest, CpuUsageTest) { } // Sanity test for Thermal::getCoolingDevices(). -TEST_F(ThermalHidlTest, CoolingDeviceTest) { +TEST_P(ThermalHidlTest, CoolingDeviceTest) { hidl_vec passed; for (size_t i = 0; i < MONITORING_OPERATION_NUMBER; ++i) { thermal_->getCoolingDevices([&passed]( @@ -222,11 +208,7 @@ TEST_F(ThermalHidlTest, CoolingDeviceTest) { } } -int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - ThermalHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - LOG(INFO) << "Test result = " << status; - return status; -} +INSTANTIATE_TEST_SUITE_P( + PerInstance, ThermalHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)), + android::hardware::PrintInstanceNameToString); diff --git a/thermal/1.1/vts/functional/Android.bp b/thermal/1.1/vts/functional/Android.bp index 9a16c30fba..2c43d79766 100644 --- a/thermal/1.1/vts/functional/Android.bp +++ b/thermal/1.1/vts/functional/Android.bp @@ -22,6 +22,5 @@ cc_test { "android.hardware.thermal@1.0", "android.hardware.thermal@1.1", ], - test_suites: ["general-tests"], + test_suites: ["general-tests", "vts-core"], } - diff --git a/thermal/1.1/vts/functional/VtsHalThermalV1_1TargetTest.cpp b/thermal/1.1/vts/functional/VtsHalThermalV1_1TargetTest.cpp index 91c8b6ec76..bc7b2ee3ce 100644 --- a/thermal/1.1/vts/functional/VtsHalThermalV1_1TargetTest.cpp +++ b/thermal/1.1/vts/functional/VtsHalThermalV1_1TargetTest.cpp @@ -17,10 +17,11 @@ #include #include #include +#include +#include +#include #include -#include -#include using ::android::hardware::thermal::V1_0::Temperature; using ::android::hardware::thermal::V1_0::TemperatureType; @@ -63,26 +64,11 @@ class ThermalCallback } }; -// Test environment for Thermal HIDL HAL. -class ThermalHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { - public: - // get the test environment singleton - static ThermalHidlEnvironment* Instance() { - static ThermalHidlEnvironment* instance = new ThermalHidlEnvironment; - return instance; - } - - virtual void registerTestServices() override { registerTestService(); } - private: - ThermalHidlEnvironment() {} -}; - // The main test class for THERMAL HIDL HAL 1.1. -class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { +class ThermalHidlTest : public testing::TestWithParam { public: virtual void SetUp() override { - mThermal = ::testing::VtsHalHidlTargetTestBase::getService( - ThermalHidlEnvironment::Instance()->getServiceName()); + mThermal = IThermal::getService(GetParam()); ASSERT_NE(mThermal, nullptr); mThermalCallback = new(std::nothrow) ThermalCallback(); ASSERT_NE(mThermalCallback, nullptr); @@ -104,7 +90,7 @@ class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { // This just calls into and back from our local ThermalCallback impl. // Note: a real thermal throttling event from the Thermal HAL could be // inadvertently received here. -TEST_F(ThermalHidlTest, NotifyThrottlingTest) { +TEST_P(ThermalHidlTest, NotifyThrottlingTest) { auto ret = mThermalCallback->notifyThrottling(true, kThrottleTemp); ASSERT_TRUE(ret.isOk()); auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling); @@ -114,11 +100,7 @@ TEST_F(ThermalHidlTest, NotifyThrottlingTest) { EXPECT_EQ(kThrottleTemp, res.args->temperature); } -int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - ThermalHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - cout << "Test result = " << status << std::endl; - return status; -} +INSTANTIATE_TEST_SUITE_P( + PerInstance, ThermalHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)), + android::hardware::PrintInstanceNameToString); \ No newline at end of file diff --git a/thermal/2.0/vts/functional/Android.bp b/thermal/2.0/vts/functional/Android.bp index f4e95f8ae5..09405763a2 100644 --- a/thermal/2.0/vts/functional/Android.bp +++ b/thermal/2.0/vts/functional/Android.bp @@ -22,5 +22,6 @@ cc_test { "android.hardware.thermal@1.0", "android.hardware.thermal@2.0", ], + test_suites: ["general-tests", "vts-core"], } diff --git a/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp b/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp index d0f2e84afd..75536a6057 100644 --- a/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp +++ b/thermal/2.0/vts/functional/VtsHalThermalV2_0TargetTest.cpp @@ -18,9 +18,11 @@ #include #include +#include +#include +#include + #include -#include -#include using ::android::sp; using ::android::hardware::hidl_enum_range; @@ -63,27 +65,11 @@ class ThermalCallback : public ::testing::VtsHalHidlTargetCallbackBase(); } - - private: - ThermalHidlEnvironment() {} -}; - // The main test class for THERMAL HIDL HAL 2.0. -class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { +class ThermalHidlTest : public testing::TestWithParam { public: virtual void SetUp() override { - mThermal = ::testing::VtsHalHidlTargetTestBase::getService( - ThermalHidlEnvironment::Instance()->getServiceName()); + mThermal = IThermal::getService(GetParam()); ASSERT_NE(mThermal, nullptr); mThermalCallback = new (std::nothrow) ThermalCallback(); ASSERT_NE(mThermalCallback, nullptr); @@ -119,7 +105,7 @@ class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { // This just calls into and back from our local ThermalChangedCallback impl. // Note: a real thermal throttling event from the Thermal HAL could be // inadvertently received here. -TEST_F(ThermalHidlTest, NotifyThrottlingTest) { +TEST_P(ThermalHidlTest, NotifyThrottlingTest) { auto ret = mThermalCallback->notifyThrottling(kThrottleTemp); ASSERT_TRUE(ret.isOk()); auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling); @@ -129,7 +115,7 @@ TEST_F(ThermalHidlTest, NotifyThrottlingTest) { } // Test Thermal->registerThermalChangedCallback. -TEST_F(ThermalHidlTest, RegisterThermalChangedCallbackTest) { +TEST_P(ThermalHidlTest, RegisterThermalChangedCallbackTest) { // Expect to fail with same callback auto ret = mThermal->registerThermalChangedCallback( mThermalCallback, false, TemperatureType::SKIN, @@ -159,7 +145,7 @@ TEST_F(ThermalHidlTest, RegisterThermalChangedCallbackTest) { } // Test Thermal->unregisterThermalChangedCallback. -TEST_F(ThermalHidlTest, UnregisterThermalChangedCallbackTest) { +TEST_P(ThermalHidlTest, UnregisterThermalChangedCallbackTest) { sp localThermalCallback = new (std::nothrow) ThermalCallback(); // Expect to fail as the callback was not registered before auto ret = mThermal->unregisterThermalChangedCallback( @@ -184,7 +170,7 @@ TEST_F(ThermalHidlTest, UnregisterThermalChangedCallbackTest) { } // Sanity test for Thermal::getCurrentTemperatures(). -TEST_F(ThermalHidlTest, TemperatureTest) { +TEST_P(ThermalHidlTest, TemperatureTest) { mThermal->getCurrentTemperatures(false, TemperatureType::SKIN, [](ThermalStatus status, hidl_vec temperatures) { if (temperatures.size()) { @@ -214,7 +200,7 @@ TEST_F(ThermalHidlTest, TemperatureTest) { } // Sanity test for Thermal::getTemperatureThresholds(). -TEST_F(ThermalHidlTest, TemperatureThresholdTest) { +TEST_P(ThermalHidlTest, TemperatureThresholdTest) { mThermal->getTemperatureThresholds( false, TemperatureType::SKIN, [](ThermalStatus status, hidl_vec temperatures) { @@ -242,7 +228,7 @@ TEST_F(ThermalHidlTest, TemperatureThresholdTest) { } // Sanity test for Thermal::getCurrentCoolingDevices(). -TEST_F(ThermalHidlTest, CoolingDeviceTest) { +TEST_P(ThermalHidlTest, CoolingDeviceTest) { mThermal->getCurrentCoolingDevices( false, CoolingType::CPU, [](ThermalStatus status, hidl_vec cooling_devices) { if (cooling_devices.size()) { @@ -271,11 +257,7 @@ TEST_F(ThermalHidlTest, CoolingDeviceTest) { } } -int main(int argc, char** argv) { - ::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance()); - ::testing::InitGoogleTest(&argc, argv); - ThermalHidlEnvironment::Instance()->init(&argc, argv); - int status = RUN_ALL_TESTS(); - cout << "Test result = " << status << std::endl; - return status; -} +INSTANTIATE_TEST_SUITE_P( + PerInstance, ThermalHidlTest, + testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)), + android::hardware::PrintInstanceNameToString);