test: Refactor tests that use VK_ICD_FILENAMES
authorCharles Giessen <charles@lunarg.com>
Sun, 6 Jun 2021 18:40:34 +0000 (12:40 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 7 Jun 2021 21:07:38 +0000 (14:07 -0700)
Change-Id: I34117fd500f7110669ae19d32ff1e1be920238a9

tests/framework/test_environment.cpp
tests/framework/test_environment.h
tests/loader_version_tests.cpp

index c87a8412015cf0c299e7bc6580d5c3af4a7c207d..96b49cef8fefa94331cdde0e52f0c0a65fc9e6a2 100644 (file)
@@ -95,6 +95,22 @@ void FrameworkEnvironment::AddExplicitLayer(ManifestLayer layer_manifest, const
     platform_shim->add_manifest(ManifestCategory::explicit_layer, layer_loc);
 }
 
+EnvVarICDOverrideShim::EnvVarICDOverrideShim(DebugMode debug_mode) : FrameworkEnvironment(debug_mode) {}
+
+void EnvVarICDOverrideShim::SetEnvOverrideICD(const char* icd_path, const char* manifest_name) {
+    ManifestICD icd_manifest;
+    icd_manifest.lib_path = icd_path;
+    icd_manifest.api_version = VK_MAKE_VERSION(1, 0, 0);
+
+    icd_folder.write(manifest_name, icd_manifest);
+    set_env_var("VK_ICD_FILENAMES", (icd_folder.location() / manifest_name).str());
+
+    driver_wrapper = LibraryWrapper(fs::path(icd_path));
+
+    get_new_test_icd = driver_wrapper.get_symbol<GetNewTestICDFunc>(GET_NEW_TEST_ICD_FUNC_STR);
+
+}
+
 SingleICDShim::SingleICDShim(TestICDDetails icd_details, DebugMode debug_mode) : FrameworkEnvironment(debug_mode) {
     icd_handle = detail::TestICDHandle(icd_details.icd_path);
 
index 087f8915488a5fe5d65e6b6cbab587fbbac866ed..8ec46f696b1213c8a10f80785218996949bd6041 100644 (file)
@@ -115,6 +115,16 @@ struct FrameworkEnvironment {
     VulkanFunctions vulkan_functions;
 };
 
+struct EnvVarICDOverrideShim : FrameworkEnvironment {
+    EnvVarICDOverrideShim(DebugMode debug_mode = DebugMode::none);
+
+    void SetEnvOverrideICD(const char* icd_path, const char* manifest_name);
+
+    LibraryWrapper driver_wrapper;
+    GetNewTestICDFunc get_new_test_icd;
+};
+
+
 struct SingleICDShim : FrameworkEnvironment {
     SingleICDShim(TestICDDetails icd_details, DebugMode debug_mode = DebugMode::none);
 
index 87b5426d574d74a240c541c9c155955be762ca14..71a698ead376ccc5001a0d82ed55a70df0dcd488 100644 (file)
 
 #include "test_environment.h"
 
-class ICDEnvVarSetup : public ::testing::Test {
+class EnvVarICDOverrideSetup : public ::testing::Test {
    protected:
-    virtual void SetUp() {}
+    virtual void SetUp() { env = std::unique_ptr<EnvVarICDOverrideShim>(new EnvVarICDOverrideShim()); }
 
     virtual void TearDown() {
         remove_env_var("VK_ICD_FILENAMES");
-        platform_shim->platform_shim->clear_override();
-
-        driver_store->remove(manifest_name);
-        vulkan_functions.reset();
-        platform_shim.reset();
-        driver_store.reset();
-    }
-
-   public:
-    std::string manifest_name;
-    std::unique_ptr<detail::PlatformShimWrapper> platform_shim;
-    std::unique_ptr<fs::FolderManager> driver_store;
-    std::unique_ptr<fs::FolderManager> null_dir;
-    LibraryWrapper driver_wrapper;
-    GetNewTestICDFunc get_new_test_icd;
-    std::unique_ptr<VulkanFunctions> vulkan_functions;
+        env.reset(); }
+    std::unique_ptr<EnvVarICDOverrideShim> env;
 };
 
-void SetupICDEnvVar(ICDEnvVarSetup& env, const char* icd_path, const char* manifest_name) {
-    env.manifest_name = manifest_name;
-    env.platform_shim = std::unique_ptr<detail::PlatformShimWrapper>(new detail::PlatformShimWrapper());
-    env.platform_shim->platform_shim->setup_override();
-    env.driver_store =
-        std::unique_ptr<fs::FolderManager>(new fs::FolderManager(FRAMEWORK_BUILD_DIRECTORY, "version_test_manifests"));
-    env.null_dir = std::unique_ptr<fs::FolderManager>(new fs::FolderManager(FRAMEWORK_BUILD_DIRECTORY, "null_dir"));
-    env.platform_shim->platform_shim->redirect_all_paths(env.null_dir->location());
-    env.driver_wrapper = LibraryWrapper(fs::path(icd_path));
-    env.get_new_test_icd = env.driver_wrapper.get_symbol<GetNewTestICDFunc>(GET_NEW_TEST_ICD_FUNC_STR);
-#if defined(WIN32)
-    env.platform_shim->platform_shim->set_elevation_level(SECURITY_MANDATORY_LOW_RID);
-#endif
-    ManifestICD icd_manifest;
-    icd_manifest.lib_path = icd_path;
-    icd_manifest.api_version = VK_MAKE_VERSION(1, 0, 0);
-
-    env.driver_store->write(manifest_name, icd_manifest);
-    set_env_var("VK_ICD_FILENAMES", (env.driver_store->location() / manifest_name).str());
-    env.vulkan_functions = std::unique_ptr<VulkanFunctions>(new VulkanFunctions());
-}
 
 // Don't support vk_icdNegotiateLoaderICDInterfaceVersion
 // Loader calls vk_icdGetInstanceProcAddr second
 // does not support vk_icdGetInstanceProcAddr
 // must export vkGetInstanceProcAddr, vkCreateInstance, vkEnumerateInstanceExtensionProperties
-TEST_F(ICDEnvVarSetup, version_0_none) {
-    SetupICDEnvVar(*this, TEST_ICD_PATH_EXPORT_NONE, "test_icd_export_none.json");
-    auto* driver = get_new_test_icd();
+TEST_F(EnvVarICDOverrideSetup, version_0_none) {
+    env->SetEnvOverrideICD(TEST_ICD_PATH_EXPORT_NONE, "test_icd_export_none.json");
+    auto* driver = env->get_new_test_icd();
 
-    InstWrapper inst{*vulkan_functions};
+    InstWrapper inst{env->vulkan_functions};
     InstanceCreateInfo inst_create_info;
     ASSERT_EQ(CreateInst(inst, inst_create_info), VK_SUCCESS);
 
@@ -90,11 +55,11 @@ TEST_F(ICDEnvVarSetup, version_0_none) {
 
 // Don't support vk_icdNegotiateLoaderICDInterfaceVersion
 // the loader calls vk_icdGetInstanceProcAddr first
-TEST_F(ICDEnvVarSetup, version_1_icd_gipa) {
-    SetupICDEnvVar(*this, TEST_ICD_PATH_EXPORT_ICD_GIPA, "test_icd_export_icd_gipa.json");
-    auto* driver = get_new_test_icd();
+TEST_F(EnvVarICDOverrideSetup, version_1_icd_gipa) {
+    env->SetEnvOverrideICD(TEST_ICD_PATH_EXPORT_ICD_GIPA, "test_icd_export_icd_gipa.json");
+    auto* driver = env->get_new_test_icd();
 
-    InstWrapper inst{*vulkan_functions};
+    InstWrapper inst{env->vulkan_functions};
     InstanceCreateInfo inst_create_info;
     ASSERT_EQ(CreateInst(inst, inst_create_info), VK_SUCCESS);
 
@@ -103,12 +68,10 @@ TEST_F(ICDEnvVarSetup, version_1_icd_gipa) {
 
 // support vk_icdNegotiateLoaderICDInterfaceVersion but not vk_icdGetInstanceProcAddr
 // should assert that `interface_vers == 0` due to version mismatch, only checkable in Debug Mode
-TEST_F(ICDEnvVarSetup, version_negotiate_interface_version_death_test) {
-    // may be needed to surpress debug assert popups on windows
-    //::testing::FLAGS_gtest_death_test_style = "threadsafe";
-    SetupICDEnvVar(*this, TEST_ICD_PATH_EXPORT_NEGOTIATE_INTERFACE_VERSION, "test_icd_export_negotiate_interface_version.json");
+TEST_F(EnvVarICDOverrideSetup, version_negotiate_interface_version_death_test) {
+    env->SetEnvOverrideICD(TEST_ICD_PATH_EXPORT_NEGOTIATE_INTERFACE_VERSION, "test_icd_export_negotiate_interface_version.json");
 
-    InstWrapper inst{*vulkan_functions};
+    InstWrapper inst{env->vulkan_functions};
     InstanceCreateInfo inst_create_info;
 #if !defined(NDEBUG)
 #if defined(WIN32)
@@ -122,11 +85,11 @@ TEST_F(ICDEnvVarSetup, version_negotiate_interface_version_death_test) {
 }
 
 // export vk_icdNegotiateLoaderICDInterfaceVersion and vk_icdGetInstanceProcAddr
-TEST_F(ICDEnvVarSetup, version_2_negotiate_interface_version_and_icd_gipa) {
-    SetupICDEnvVar(*this, TEST_ICD_PATH_VERSION_2, "test_icd_version_2.json");
-    auto* driver = get_new_test_icd();
+TEST_F(EnvVarICDOverrideSetup, version_2_negotiate_interface_version_and_icd_gipa) {
+    env->SetEnvOverrideICD(TEST_ICD_PATH_VERSION_2, "test_icd_version_2.json");
+    auto* driver = env->get_new_test_icd();
 
-    InstWrapper inst{*vulkan_functions};
+    InstWrapper inst{env->vulkan_functions};
     InstanceCreateInfo inst_create_info;
     ASSERT_EQ(CreateInst(inst, inst_create_info), VK_SUCCESS);