Merge "[vts-core] add VtsHalMemtrackV1_0TargetTest to vts-core"

This commit is contained in:
Treehugger Robot 2019-10-25 05:41:19 +00:00 committed by Gerrit Code Review
commit 53b86ff792
2 changed files with 13 additions and 29 deletions

View file

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

View file

@ -20,8 +20,9 @@
#include <android/hardware/memtrack/1.0/IMemtrack.h>
#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <gtest/gtest.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>
#include <fcntl.h>
#include <algorithm>
@ -39,23 +40,10 @@ using ::android::base::unique_fd;
using std::vector;
using std::count_if;
// Test environment for Memtrack HIDL HAL.
class MemtrackHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
// get the test environment singleton
static MemtrackHidlEnvironment* Instance() {
static MemtrackHidlEnvironment* instance = new MemtrackHidlEnvironment;
return instance;
}
virtual void registerTestServices() override { registerTestService<IMemtrack>(); }
};
class MemtrackHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class MemtrackHidlTest : public ::testing::TestWithParam<std::string> {
public:
virtual void SetUp() override {
memtrack = ::testing::VtsHalHidlTargetTestBase::getService<IMemtrack>(
MemtrackHidlEnvironment::Instance()->getServiceName<IMemtrack>());
memtrack = IMemtrack::getService(GetParam());
ASSERT_NE(memtrack, nullptr);
}
@ -93,7 +81,7 @@ auto generate_cb(MemtrackStatus *s, hidl_vec<MemtrackRecord> *v) {
/* Sanity check results when getMemory() is passed a negative PID
*/
TEST_F(MemtrackHidlTest, BadPidTest) {
TEST_P(MemtrackHidlTest, BadPidTest) {
MemtrackStatus s;
hidl_vec<MemtrackRecord> v;
auto cb = generate_cb(&s, &v);
@ -108,7 +96,7 @@ TEST_F(MemtrackHidlTest, BadPidTest) {
/* Sanity check results when getMemory() is passed a bad memory usage type
*/
TEST_F(MemtrackHidlTest, BadTypeTest) {
TEST_P(MemtrackHidlTest, BadTypeTest) {
MemtrackStatus s;
hidl_vec<MemtrackRecord> v;
auto cb = generate_cb(&s, &v);
@ -121,7 +109,7 @@ TEST_F(MemtrackHidlTest, BadTypeTest) {
* for all memory types, including valid flag combinations for every
* MemtrackRecord returned.
*/
TEST_F(MemtrackHidlTest, GetMemoryTest) {
TEST_P(MemtrackHidlTest, GetMemoryTest) {
/* Opening this device causes the kernel to provide memtrack with memory
* info for this process.
*/
@ -172,11 +160,7 @@ TEST_F(MemtrackHidlTest, GetMemoryTest) {
static_cast<uint32_t>(MemtrackType::NUM_TYPES));
}
int main(int argc, char **argv) {
::testing::AddGlobalTestEnvironment(MemtrackHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv);
MemtrackHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS();
LOG(INFO) << "Test result = " << status;
return status;
}
INSTANTIATE_TEST_SUITE_P(
PerInstance, MemtrackHidlTest,
testing::ValuesIn(android::hardware::getAllHalInstanceNames(IMemtrack::descriptor)),
android::hardware::PrintInstanceNameToString);