[vts-core] add VtsHalHealthV1_0TargetTest to vts-core

Convert VtsHalHealthV1_0TargetTest. to be parameterized test
and add it to vts-core

Bug: 142397658
Test: $atest VtsHalHealthV1_0TargetTest.
Change-Id: I3abfbfe0c20a5fe595f32c4793b2c53f6ad13e28
This commit is contained in:
nelsonli 2019-10-25 17:24:18 +08:00 committed by Nelson Li
parent 6e82d1abd5
commit cb460b6dae
2 changed files with 11 additions and 30 deletions

View file

@ -19,5 +19,5 @@ cc_test {
defaults: ["VtsHalTargetTestDefaults"], defaults: ["VtsHalTargetTestDefaults"],
srcs: ["VtsHalHealthV1_0TargetTest.cpp"], srcs: ["VtsHalHealthV1_0TargetTest.cpp"],
static_libs: ["android.hardware.health@1.0"], static_libs: ["android.hardware.health@1.0"],
test_suites: ["general-tests"], test_suites: ["general-tests", "vts-core"],
} }

View file

@ -18,11 +18,11 @@
#include <android/hardware/health/1.0/IHealth.h> #include <android/hardware/health/1.0/IHealth.h>
#include <android/hardware/health/1.0/types.h> #include <android/hardware/health/1.0/types.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <log/log.h> #include <log/log.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
using HealthConfig = ::android::hardware::health::V1_0::HealthConfig; using HealthConfig = ::android::hardware::health::V1_0::HealthConfig;
using HealthInfo = ::android::hardware::health::V1_0::HealthInfo; using HealthInfo = ::android::hardware::health::V1_0::HealthInfo;
using IHealth = ::android::hardware::health::V1_0::IHealth; using IHealth = ::android::hardware::health::V1_0::IHealth;
@ -30,25 +30,10 @@ using Result = ::android::hardware::health::V1_0::Result;
using ::android::sp; using ::android::sp;
// Test environment for Health HIDL HAL. class HealthHidlTest : public ::testing::TestWithParam<std::string> {
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<IHealth>(); }
private:
HealthHidlEnvironment() {}
};
class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public: public:
virtual void SetUp() override { virtual void SetUp() override {
health = ::testing::VtsHalHidlTargetTestBase::getService<IHealth>( health = IHealth::getService(GetParam());
HealthHidlEnvironment::Instance()->getServiceName<IHealth>());
ASSERT_NE(health, nullptr); ASSERT_NE(health, nullptr);
health->init(config, health->init(config,
[&](const auto& halConfigOut) { config = halConfigOut; }); [&](const auto& halConfigOut) { config = halConfigOut; });
@ -61,7 +46,7 @@ class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase {
/** /**
* Ensure EnergyCounter call returns positive energy counter or NOT_SUPPORTED * Ensure EnergyCounter call returns positive energy counter or NOT_SUPPORTED
*/ */
TEST_F(HealthHidlTest, TestEnergyCounter) { TEST_P(HealthHidlTest, TestEnergyCounter) {
Result result; Result result;
int64_t energy = 0; int64_t energy = 0;
health->energyCounter([&](Result ret, int64_t energyOut) { health->energyCounter([&](Result ret, int64_t energyOut) {
@ -73,11 +58,7 @@ TEST_F(HealthHidlTest, TestEnergyCounter) {
ASSERT_TRUE(result != Result::SUCCESS || energy > 0); ASSERT_TRUE(result != Result::SUCCESS || energy > 0);
} }
int main(int argc, char **argv) { INSTANTIATE_TEST_SUITE_P(
::testing::AddGlobalTestEnvironment(HealthHidlEnvironment::Instance()); PerInstance, HealthHidlTest,
::testing::InitGoogleTest(&argc, argv); testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHealth::descriptor)),
HealthHidlEnvironment::Instance()->init(&argc, argv); android::hardware::PrintInstanceNameToString);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}