Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c3b000d authored by Zhuoyao Zhang's avatar Zhuoyao Zhang
Browse files

Convert auth secret hal test to use VtsHalHidlTargetTestEnvBase

Test: make vts
      vts-tradefed run vts-hal -m VtsHalAuthSecretV1_0Target

Change-Id: Ib66e101a78b4b6d66a426c36112b1cf0b95afda3
parent ccacc1de
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -17,18 +17,35 @@
#include <android/hardware/authsecret/1.0/IAuthSecret.h>

#include <VtsHalHidlTargetTestBase.h>
#include <VtsHalHidlTargetTestEnvBase.h>

using ::android::hardware::hidl_vec;
using ::android::hardware::authsecret::V1_0::IAuthSecret;
using ::android::sp;

// Test environment for Boot HIDL HAL.
class AuthSecretHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
   public:
    // get the test environment singleton
    static AuthSecretHidlEnvironment* Instance() {
        static AuthSecretHidlEnvironment* instance = new AuthSecretHidlEnvironment;
        return instance;
    }

    virtual void registerTestServices() override { registerTestService<IAuthSecret>(); }

   private:
    AuthSecretHidlEnvironment() {}
};

/**
 * There is no expected behaviour that can be tested so these tests check the
 * HAL doesn't crash with different execution orders.
 */
struct AuthSecretHidlTest : public ::testing::VtsHalHidlTargetTestBase {
    virtual void SetUp() override {
        authsecret = ::testing::VtsHalHidlTargetTestBase::getService<IAuthSecret>();
        authsecret = ::testing::VtsHalHidlTargetTestBase::getService<IAuthSecret>(
            AuthSecretHidlEnvironment::Instance()->getServiceName<IAuthSecret>());
        ASSERT_NE(authsecret, nullptr);

        // All tests must enroll the correct secret first as this cannot be changed
@@ -69,3 +86,12 @@ TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndWrongSecret) {
    // Secret provisioned by SetUp()
    authsecret->primaryUserCredential(WRONG_SECRET);
}

int main(int argc, char** argv) {
    ::testing::AddGlobalTestEnvironment(AuthSecretHidlEnvironment::Instance());
    ::testing::InitGoogleTest(&argc, argv);
    AuthSecretHidlEnvironment::Instance()->init(&argc, argv);
    int status = RUN_ALL_TESTS();
    ALOGI("Test result = %d", status);
    return status;
}