Convert VtsHalKeymasterV*_0TargetTest to be parameterized test

Bug: 142397658
Test: atest VtsHalKeymasterV3_0TargetTest \
  VtsHalKeymasterV4_0TargetTest

Change-Id: I0fbda4d9ab810a4ef616f8741919c522d5d58cc0
diff --git a/keymaster/4.0/vts/functional/KeymasterHidlTest.h b/keymaster/4.0/vts/functional/KeymasterHidlTest.h
index b09da45..adceead 100644
--- a/keymaster/4.0/vts/functional/KeymasterHidlTest.h
+++ b/keymaster/4.0/vts/functional/KeymasterHidlTest.h
@@ -14,14 +14,13 @@
  * limitations under the License.
  */
 
-#ifndef HARDWARE_INTERFACES_KEYMASTER_40_VTS_FUNCTIONAL_KEYMASTER_HIDL_TEST_H_
-#define HARDWARE_INTERFACES_KEYMASTER_40_VTS_FUNCTIONAL_KEYMASTER_HIDL_TEST_H_
+#pragma once
 
 #include <android/hardware/keymaster/4.0/IKeymasterDevice.h>
 #include <android/hardware/keymaster/4.0/types.h>
-
-#include <VtsHalHidlTargetTestBase.h>
-
+#include <gtest/gtest.h>
+#include <hidl/GtestPrinter.h>
+#include <hidl/ServiceManagement.h>
 #include <keymaster/keymaster_configuration.h>
 
 #include <keymasterV4_0/authorization_set.h>
@@ -69,43 +68,24 @@
 
 constexpr uint64_t kOpHandleSentinel = 0xFFFFFFFFFFFFFFFF;
 
-class KeymasterHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
-   public:
-    // get the test environment singleton
-    static KeymasterHidlEnvironment* Instance() {
-        static KeymasterHidlEnvironment* instance = new KeymasterHidlEnvironment;
-        return instance;
-    }
-
-    void registerTestServices() override { registerTestService<IKeymasterDevice>(); }
-
-   private:
-    KeymasterHidlEnvironment(){};
-
-    GTEST_DISALLOW_COPY_AND_ASSIGN_(KeymasterHidlEnvironment);
-};
-
-class KeymasterHidlTest : public ::testing::VtsHalHidlTargetTestBase {
-   public:
+class KeymasterHidlTest : public ::testing::TestWithParam<std::string> {
+  public:
+    void SetUp();
     void TearDown() override {
         if (key_blob_.size()) {
             CheckedDeleteKey();
         }
         AbortIfNeeded();
-    }
-
-    // SetUpTestCase runs only once per test case, not once per test.
-    static void SetUpTestCase();
-    static void InitializeKeymaster();
-    static void TearDownTestCase() {
         keymaster_.clear();
         all_keymasters_.clear();
     }
 
-    static IKeymasterDevice& keymaster() { return *keymaster_; }
-    static const std::vector<sp<IKeymasterDevice>>& all_keymasters() { return all_keymasters_; }
-    static uint32_t os_version() { return os_version_; }
-    static uint32_t os_patch_level() { return os_patch_level_; }
+    void InitializeKeymaster();
+
+    IKeymasterDevice& keymaster() { return *keymaster_; }
+    const std::vector<sp<IKeymasterDevice>>& all_keymasters() { return all_keymasters_; }
+    uint32_t os_version() { return os_version_; }
+    uint32_t os_patch_level() { return os_patch_level_; }
 
     ErrorCode GenerateKey(const AuthorizationSet& key_desc, HidlBuf* key_blob,
                           KeyCharacteristics* key_characteristics);
@@ -216,8 +196,8 @@
 
     std::pair<ErrorCode, HidlBuf> UpgradeKey(const HidlBuf& key_blob);
 
-    static bool IsSecure() { return securityLevel_ != SecurityLevel::SOFTWARE; }
-    static SecurityLevel SecLevel() { return securityLevel_; }
+    bool IsSecure() { return securityLevel_ != SecurityLevel::SOFTWARE; }
+    SecurityLevel SecLevel() { return securityLevel_; }
 
     std::vector<uint32_t> ValidKeySizes(Algorithm algorithm);
     std::vector<uint32_t> InvalidKeySizes(Algorithm algorithm);
@@ -233,15 +213,15 @@
     OperationHandle op_handle_ = kOpHandleSentinel;
 
    private:
-    static sp<IKeymasterDevice> keymaster_;
-    static std::vector<sp<IKeymasterDevice>> all_keymasters_;
-    static uint32_t os_version_;
-    static uint32_t os_patch_level_;
+     sp<IKeymasterDevice> keymaster_;
+     std::vector<sp<IKeymasterDevice>> all_keymasters_;
+     uint32_t os_version_;
+     uint32_t os_patch_level_;
 
-    static SecurityLevel securityLevel_;
-    static hidl_string name_;
-    static hidl_string author_;
-    static string service_name_;
+     SecurityLevel securityLevel_;
+     hidl_string name_;
+     hidl_string author_;
+     string service_name_;
 };
 
 }  // namespace test
@@ -249,5 +229,3 @@
 }  // namespace keymaster
 }  // namespace hardware
 }  // namespace android
-
-#endif  // HARDWARE_INTERFACES_KEYMASTER_40_VTS_FUNCTIONAL_KEYMASTER_HIDL_TEST_H_