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

Commit ff4de289 authored by nelsonli's avatar nelsonli Committed by Nelson Li
Browse files

[vts-core] add VtsHalAuthSecretV1_0TargetTest to vts-core

Convert VtsHalAuthSecretV1_0TargetTest to be parameterized test
and add it to vts-core

Bug: 142397658
Test: $atste VtsHalAuthSecretV1_0TargetTest
Change-Id: I6cf21977e1fef8b11bf0517540ef831a52a44937
parent ab017f20
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -19,5 +19,9 @@ cc_test {
    defaults: ["VtsHalTargetTestDefaults"],
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: ["VtsHalAuthSecretV1_0TargetTest.cpp"],
    srcs: ["VtsHalAuthSecretV1_0TargetTest.cpp"],
    static_libs: ["android.hardware.authsecret@1.0"],
    static_libs: ["android.hardware.authsecret@1.0"],
    test_suites: ["general-tests"],
    test_suites: [
        "general-tests",
        "vts-core",
    ],
    require_root: true,
}
}
+14 −32
Original line number Original line Diff line number Diff line
@@ -16,36 +16,22 @@


#include <android/hardware/authsecret/1.0/IAuthSecret.h>
#include <android/hardware/authsecret/1.0/IAuthSecret.h>


#include <VtsHalHidlTargetTestBase.h>
#include <gtest/gtest.h>
#include <VtsHalHidlTargetTestEnvBase.h>
#include <hidl/GtestPrinter.h>
#include <hidl/ServiceManagement.h>


using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_vec;
using ::android::hardware::authsecret::V1_0::IAuthSecret;
using ::android::hardware::authsecret::V1_0::IAuthSecret;
using ::android::sp;
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
 * There is no expected behaviour that can be tested so these tests check the
 * HAL doesn't crash with different execution orders.
 * HAL doesn't crash with different execution orders.
 */
 */
struct AuthSecretHidlTest : public ::testing::VtsHalHidlTargetTestBase {
class AuthSecretHidlTest : public testing::TestWithParam<std::string> {
  public:
    virtual void SetUp() override {
    virtual void SetUp() override {
        authsecret = ::testing::VtsHalHidlTargetTestBase::getService<IAuthSecret>(
        authsecret = IAuthSecret::getService(GetParam());
            AuthSecretHidlEnvironment::Instance()->getServiceName<IAuthSecret>());
        ASSERT_NE(authsecret, nullptr);
        ASSERT_NE(authsecret, nullptr);


        // All tests must enroll the correct secret first as this cannot be changed
        // All tests must enroll the correct secret first as this cannot be changed
@@ -59,18 +45,18 @@ struct AuthSecretHidlTest : public ::testing::VtsHalHidlTargetTestBase {
};
};


/* Provision the primary user with a secret. */
/* Provision the primary user with a secret. */
TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredential) {
TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredential) {
    // Secret provisioned by SetUp()
    // Secret provisioned by SetUp()
}
}


/* Provision the primary user with a secret and pass the secret again. */
/* Provision the primary user with a secret and pass the secret again. */
TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgain) {
TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgain) {
    // Secret provisioned by SetUp()
    // Secret provisioned by SetUp()
    authsecret->primaryUserCredential(CORRECT_SECRET);
    authsecret->primaryUserCredential(CORRECT_SECRET);
}
}


/* Provision the primary user with a secret and pass the secret again repeatedly. */
/* Provision the primary user with a secret and pass the secret again repeatedly. */
TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTimes) {
TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTimes) {
    // Secret provisioned by SetUp()
    // Secret provisioned by SetUp()
    constexpr int N = 5;
    constexpr int N = 5;
    for (int i = 0; i < N; ++i) {
    for (int i = 0; i < N; ++i) {
@@ -82,16 +68,12 @@ TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndPassAgainMultipleTim
 * should never happen and is an framework bug if it does. As the secret is
 * should never happen and is an framework bug if it does. As the secret is
 * wrong, the HAL implementation may not be able to function correctly but it
 * wrong, the HAL implementation may not be able to function correctly but it
 * should fail gracefully. */
 * should fail gracefully. */
TEST_F(AuthSecretHidlTest, provisionPrimaryUserCredentialAndWrongSecret) {
TEST_P(AuthSecretHidlTest, provisionPrimaryUserCredentialAndWrongSecret) {
    // Secret provisioned by SetUp()
    // Secret provisioned by SetUp()
    authsecret->primaryUserCredential(WRONG_SECRET);
    authsecret->primaryUserCredential(WRONG_SECRET);
}
}


int main(int argc, char** argv) {
INSTANTIATE_TEST_SUITE_P(
    ::testing::AddGlobalTestEnvironment(AuthSecretHidlEnvironment::Instance());
        PerInstance, AuthSecretHidlTest,
    ::testing::InitGoogleTest(&argc, argv);
        testing::ValuesIn(android::hardware::getAllHalInstanceNames(IAuthSecret::descriptor)),
    AuthSecretHidlEnvironment::Instance()->init(&argc, argv);
        android::hardware::PrintInstanceNameToString);
    int status = RUN_ALL_TESTS();
    ALOGI("Test result = %d", status);
    return status;
}