Convert gatekeeper hal test to use VtsHalHidlTargetTestEnvBase

Bug: 64203181
Test: make vts
      vts-tradefed run vts -m VtsHalGatekeeperV1_0Target

Change-Id: I55aa7abbb8c5ffa504aac1ed79a07de1139d606b
This commit is contained in:
Zhuoyao Zhang 2018-02-08 20:52:37 -08:00
parent 8f7ff5730b
commit fce6cdc995

View file

@ -33,6 +33,7 @@
#include <log/log.h> #include <log/log.h>
#include <VtsHalHidlTargetTestBase.h> #include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>
using ::android::hardware::hidl_string; using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec; using ::android::hardware::hidl_vec;
@ -77,6 +78,20 @@ static const hw_auth_token_t *toAuthToken(GatekeeperResponse &rsp) {
return auth_token; return auth_token;
} }
// Test environment for Gatekeeper HIDL HAL.
class GatekeeperHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
public:
// get the test environment singleton
static GatekeeperHidlEnvironment* Instance() {
static GatekeeperHidlEnvironment* instance = new GatekeeperHidlEnvironment;
return instance;
}
virtual void registerTestServices() override { registerTestService<IGatekeeper>(); }
private:
GatekeeperHidlEnvironment() {}
};
// The main test class for Gatekeeper HIDL HAL. // The main test class for Gatekeeper HIDL HAL.
class GatekeeperHidlTest : public ::testing::VtsHalHidlTargetTestBase { class GatekeeperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
protected: protected:
@ -189,7 +204,8 @@ class GatekeeperHidlTest : public ::testing::VtsHalHidlTargetTestBase {
GatekeeperHidlTest() : uid_(0) {} GatekeeperHidlTest() : uid_(0) {}
virtual void SetUp() override { virtual void SetUp() override {
GatekeeperResponse rsp; GatekeeperResponse rsp;
gatekeeper_ = ::testing::VtsHalHidlTargetTestBase::getService<IGatekeeper>(); gatekeeper_ = ::testing::VtsHalHidlTargetTestBase::getService<IGatekeeper>(
GatekeeperHidlEnvironment::Instance()->getServiceName<IGatekeeper>());
ASSERT_NE(nullptr, gatekeeper_.get()); ASSERT_NE(nullptr, gatekeeper_.get());
doDeleteAllUsers(rsp); doDeleteAllUsers(rsp);
} }
@ -433,7 +449,9 @@ TEST_F(GatekeeperHidlTest, DeleteAllUsersTest) {
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
::testing::AddGlobalTestEnvironment(GatekeeperHidlEnvironment::Instance());
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
GatekeeperHidlEnvironment::Instance()->init(&argc, argv);
int status = RUN_ALL_TESTS(); int status = RUN_ALL_TESTS();
ALOGI("Test result = %d", status); ALOGI("Test result = %d", status);
return status; return status;