[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:
parent
6e82d1abd5
commit
cb460b6dae
2 changed files with 11 additions and 30 deletions
|
@ -19,5 +19,5 @@ cc_test {
|
|||
defaults: ["VtsHalTargetTestDefaults"],
|
||||
srcs: ["VtsHalHealthV1_0TargetTest.cpp"],
|
||||
static_libs: ["android.hardware.health@1.0"],
|
||||
test_suites: ["general-tests"],
|
||||
test_suites: ["general-tests", "vts-core"],
|
||||
}
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
|
||||
#include <android/hardware/health/1.0/IHealth.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 <VtsHalHidlTargetTestBase.h>
|
||||
#include <VtsHalHidlTargetTestEnvBase.h>
|
||||
|
||||
using HealthConfig = ::android::hardware::health::V1_0::HealthConfig;
|
||||
using HealthInfo = ::android::hardware::health::V1_0::HealthInfo;
|
||||
using IHealth = ::android::hardware::health::V1_0::IHealth;
|
||||
|
@ -30,25 +30,10 @@ using Result = ::android::hardware::health::V1_0::Result;
|
|||
|
||||
using ::android::sp;
|
||||
|
||||
// Test environment for Health HIDL HAL.
|
||||
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 {
|
||||
class HealthHidlTest : public ::testing::TestWithParam<std::string> {
|
||||
public:
|
||||
virtual void SetUp() override {
|
||||
health = ::testing::VtsHalHidlTargetTestBase::getService<IHealth>(
|
||||
HealthHidlEnvironment::Instance()->getServiceName<IHealth>());
|
||||
health = IHealth::getService(GetParam());
|
||||
ASSERT_NE(health, nullptr);
|
||||
health->init(config,
|
||||
[&](const auto& halConfigOut) { config = halConfigOut; });
|
||||
|
@ -61,7 +46,7 @@ class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase {
|
|||
/**
|
||||
* Ensure EnergyCounter call returns positive energy counter or NOT_SUPPORTED
|
||||
*/
|
||||
TEST_F(HealthHidlTest, TestEnergyCounter) {
|
||||
TEST_P(HealthHidlTest, TestEnergyCounter) {
|
||||
Result result;
|
||||
int64_t energy = 0;
|
||||
health->energyCounter([&](Result ret, int64_t energyOut) {
|
||||
|
@ -73,11 +58,7 @@ TEST_F(HealthHidlTest, TestEnergyCounter) {
|
|||
ASSERT_TRUE(result != Result::SUCCESS || energy > 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::AddGlobalTestEnvironment(HealthHidlEnvironment::Instance());
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
HealthHidlEnvironment::Instance()->init(&argc, argv);
|
||||
int status = RUN_ALL_TESTS();
|
||||
ALOGI("Test result = %d", status);
|
||||
return status;
|
||||
}
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
PerInstance, HealthHidlTest,
|
||||
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHealth::descriptor)),
|
||||
android::hardware::PrintInstanceNameToString);
|
||||
|
|
Loading…
Reference in a new issue