Merge "Convert thermal hal test to use VtsHalHidlTargetTestEnvBase"

am: 118f90b3b2

Change-Id: Ie1537a7007e246ffde0f4be12fe0fed4fddad1a8
This commit is contained in:
Zhuoyao Zhang
2018-02-15 23:44:01 +00:00
committed by android-build-merger
2 changed files with 39 additions and 3 deletions

View File

@@ -21,10 +21,11 @@
#define LOG_TAG "thermal_hidl_hal_test" #define LOG_TAG "thermal_hidl_hal_test"
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android/hardware/thermal/1.0/IThermal.h> #include <android/hardware/thermal/1.0/IThermal.h>
#include <android/hardware/thermal/1.0/types.h> #include <android/hardware/thermal/1.0/types.h>
#include <VtsHalHidlTargetTestBase.h>
#include <unistd.h> #include <unistd.h>
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
@@ -45,11 +46,26 @@ using ::android::sp;
#define MAX_DEVICE_TEMPERATURE 200 #define MAX_DEVICE_TEMPERATURE 200
#define MAX_FAN_SPEED 20000 #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. // The main test class for THERMAL HIDL HAL.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public: public:
virtual void SetUp() override { virtual void SetUp() override {
thermal_ = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(); thermal_ = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
ASSERT_NE(thermal_, nullptr); ASSERT_NE(thermal_, nullptr);
baseSize_ = 0; baseSize_ = 0;
names_.clear(); names_.clear();
@@ -207,7 +223,9 @@ TEST_F(ThermalHidlTest, CoolingDeviceTest) {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
ThermalHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS(); int status = RUN_ALL_TESTS();
LOG(INFO) << "Test result = " << status; LOG(INFO) << "Test result = " << status;
return status; return status;

View File

@@ -20,6 +20,7 @@
#include <VtsHalHidlTargetCallbackBase.h> #include <VtsHalHidlTargetCallbackBase.h>
#include <VtsHalHidlTargetTestBase.h> #include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
using ::android::hardware::thermal::V1_0::Temperature; using ::android::hardware::thermal::V1_0::Temperature;
using ::android::hardware::thermal::V1_0::TemperatureType; using ::android::hardware::thermal::V1_0::TemperatureType;
@@ -62,11 +63,26 @@ 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. // The main test class for THERMAL HIDL HAL 1.1.
class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase { class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public: public:
virtual void SetUp() override { virtual void SetUp() override {
mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(); mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
ASSERT_NE(mThermal, nullptr); ASSERT_NE(mThermal, nullptr);
mThermalCallback = new(std::nothrow) ThermalCallback(); mThermalCallback = new(std::nothrow) ThermalCallback();
ASSERT_NE(mThermalCallback, nullptr); ASSERT_NE(mThermalCallback, nullptr);
@@ -99,7 +115,9 @@ TEST_F(ThermalHidlTest, NotifyThrottlingTest) {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
ThermalHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS(); int status = RUN_ALL_TESTS();
cout << "Test result = " << status << std::endl; cout << "Test result = " << status << std::endl;
return status; return status;