Merge "Convert VtsHalThermalV*TargetTest to be parameterized test"

am: 11c4534f3f

Change-Id: Ifdbfd8ace962fff427affb58d8c064b172002e52
This commit is contained in:
Dan Shi
2019-10-17 17:59:00 -07:00
committed by android-build-merger
6 changed files with 41 additions and 95 deletions

View File

@@ -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"],
}

View File

@@ -21,11 +21,12 @@
#define LOG_TAG "thermal_hidl_hal_test"
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <android-base/logging.h>
#include <android/hardware/thermal/1.0/IThermal.h>
#include <android/hardware/thermal/1.0/types.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <unistd.h>
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<IThermal>(); }
private:
ThermalHidlEnvironment() {}
};
// The main test class for THERMAL HIDL HAL.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class ThermalHidlTest : public testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
thermal_ = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
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<Temperature> 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<CpuUsage> 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<CoolingDevice> 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);

View File

@@ -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"],
}

View File

@@ -17,10 +17,11 @@
#include <android/hardware/thermal/1.1/IThermal.h>
#include <android/hardware/thermal/1.1/IThermalCallback.h>
#include <android/hardware/thermal/1.0/types.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
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<IThermal>(); }
private:
ThermalHidlEnvironment() {}
};
// The main test class for THERMAL HIDL HAL 1.1.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class ThermalHidlTest : public testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
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);

View File

@@ -22,5 +22,6 @@ cc_test {
"android.hardware.thermal@1.0",
"android.hardware.thermal@2.0",
],
test_suites: ["general-tests", "vts-core"],
}

View File

@@ -18,9 +18,11 @@
#include <android/hardware/thermal/2.0/IThermalChangedCallback.h>
#include <android/hardware/thermal/2.0/types.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
using ::android::sp;
using ::android::hardware::hidl_enum_range;
@@ -63,27 +65,11 @@ class ThermalCallback : public ::testing::VtsHalHidlTargetCallbackBase<ThermalCa
}
};
// 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;
}
void registerTestServices() override { registerTestService<IThermal>(); }
private:
ThermalHidlEnvironment() {}
};
// The main test class for THERMAL HIDL HAL 2.0.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class ThermalHidlTest : public testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
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<ThermalCallback> 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<Temperature> 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<TemperatureThreshold> 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<CoolingDevice> 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);