[vts-core] add VtsHalDumpstateV1_0TargetTest to vts-core

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

Bug: 142397658
Test: $atest VtsHalDumpstateV1_0TargetTest
Change-Id: Ifba3b6dac6f7f4e153f50d521e6d2e07f599cf7e
This commit is contained in:
nelsonli
2019-10-18 16:00:01 +08:00
parent 475414d8ef
commit ba31c175d7
2 changed files with 15 additions and 32 deletions

View File

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

View File

@@ -21,32 +21,19 @@
#include <android/hardware/dumpstate/1.0/IDumpstateDevice.h>
#include <cutils/native_handle.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <log/log.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
using ::android::hardware::dumpstate::V1_0::IDumpstateDevice;
using ::android::hardware::Return;
using ::android::sp;
// Test environment for Dumpstate HIDL HAL.
class DumpstateHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
// get the test environment singleton
static DumpstateHidlEnvironment* Instance() {
static DumpstateHidlEnvironment* instance = new DumpstateHidlEnvironment;
return instance;
}
virtual void registerTestServices() override { registerTestService<IDumpstateDevice>(); }
};
class DumpstateHidlTest : public ::testing::VtsHalHidlTargetTestBase {
public:
class DumpstateHidlTest : public ::testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
dumpstate = ::testing::VtsHalHidlTargetTestBase::getService<IDumpstateDevice>(
DumpstateHidlEnvironment::Instance()->getServiceName<IDumpstateDevice>());
dumpstate = IDumpstateDevice::getService(GetParam());
ASSERT_NE(dumpstate, nullptr) << "Could not get HIDL instance";
}
@@ -54,14 +41,14 @@ class DumpstateHidlTest : public ::testing::VtsHalHidlTargetTestBase {
};
// Negative test: make sure dumpstateBoard() doesn't crash when passed a null pointer.
TEST_F(DumpstateHidlTest, TestNullHandle) {
TEST_P(DumpstateHidlTest, TestNullHandle) {
Return<void> status = dumpstate->dumpstateBoard(nullptr);
ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description();
}
// Negative test: make sure dumpstateBoard() ignores a handle with no FD.
TEST_F(DumpstateHidlTest, TestHandleWithNoFd) {
TEST_P(DumpstateHidlTest, TestHandleWithNoFd) {
native_handle_t* handle = native_handle_create(0, 0);
ASSERT_NE(handle, nullptr) << "Could not create native_handle";
@@ -74,7 +61,7 @@ TEST_F(DumpstateHidlTest, TestHandleWithNoFd) {
}
// Positive test: make sure dumpstateBoard() writes something to the FD.
TEST_F(DumpstateHidlTest, TestOk) {
TEST_P(DumpstateHidlTest, TestOk) {
// Index 0 corresponds to the read end of the pipe; 1 to the write end.
int fds[2];
ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno;
@@ -94,7 +81,7 @@ TEST_F(DumpstateHidlTest, TestOk) {
}
// Positive test: make sure dumpstateBoard() doesn't crash with two FDs.
TEST_F(DumpstateHidlTest, TestHandleWithTwoFds) {
TEST_P(DumpstateHidlTest, TestHandleWithTwoFds) {
int fds1[2];
int fds2[2];
ASSERT_EQ(0, pipe2(fds1, O_NONBLOCK)) << errno;
@@ -111,11 +98,7 @@ TEST_F(DumpstateHidlTest, TestHandleWithTwoFds) {
native_handle_close(handle);
}
int main(int argc, char** argv) {
::testing::AddGlobalTestEnvironment(DumpstateHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
DumpstateHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status);
return status;
}
INSTANTIATE_TEST_SUITE_P(
PerInstance, DumpstateHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IDumpstateDevice::descriptor)),
android::hardware::PrintInstanceNameToString);