• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 The Khronos Group Inc.
3  * Copyright (c) 2021-2023 Valve Corporation
4  * Copyright (c) 2021-2023 LunarG, Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and/or associated documentation files (the "Materials"), to
8  * deal in the Materials without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Materials, and to permit persons to whom the Materials are
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice(s) and this permission notice shall be included in
14  * all copies or substantial portions of the Materials.
15  *
16  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  *
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE
23  * USE OR OTHER DEALINGS IN THE MATERIALS.
24  *
25  * Author: Charles Giessen <charles@lunarg.com>
26  * Author: Mark Young <markylunarg.com>
27  */
28 
29 #include "test_environment.h"
30 
31 // Don't support vk_icdNegotiateLoaderICDInterfaceVersion
32 // Loader calls vk_icdGetInstanceProcAddr second
33 // does not support vk_icdGetInstanceProcAddr
34 // must export vkGetInstanceProcAddr, vkCreateInstance, vkEnumerateInstanceExtensionProperties
TEST(EnvVarICDOverrideSetup,version_0_none)35 TEST(EnvVarICDOverrideSetup, version_0_none) {
36     FrameworkEnvironment env{};
37     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
38 
39     InstWrapper inst{env.vulkan_functions};
40     inst.CheckCreate();
41 
42     ASSERT_EQ(env.get_test_icd(0).called_vk_icd_gipa, CalledICDGIPA::vk_gipa);
43 }
44 
45 // Don't support vk_icdNegotiateLoaderICDInterfaceVersion
46 // the loader calls vk_icdGetInstanceProcAddr first
TEST(EnvVarICDOverrideSetup,version_1_icd_gipa)47 TEST(EnvVarICDOverrideSetup, version_1_icd_gipa) {
48     FrameworkEnvironment env{};
49     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_ICD_GIPA).set_discovery_type(ManifestDiscoveryType::env_var));
50 
51     InstWrapper inst{env.vulkan_functions};
52     inst.CheckCreate();
53 
54     ASSERT_EQ(env.get_test_icd(0).called_vk_icd_gipa, CalledICDGIPA::vk_icd_gipa);
55 }
56 
57 // support vk_icdNegotiateLoaderICDInterfaceVersion but not vk_icdGetInstanceProcAddr
TEST(EnvVarICDOverrideSetup,version_negotiate_interface_version_death_test)58 TEST(EnvVarICDOverrideSetup, version_negotiate_interface_version_death_test) {
59     FrameworkEnvironment env{};
60     env.add_icd(
61         TestICDDetails(TEST_ICD_PATH_EXPORT_NEGOTIATE_INTERFACE_VERSION).set_discovery_type(ManifestDiscoveryType::env_var));
62 
63     InstWrapper inst{env.vulkan_functions};
64     inst.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
65 }
66 
67 // export vk_icdNegotiateLoaderICDInterfaceVersion and vk_icdGetInstanceProcAddr
TEST(EnvVarICDOverrideSetup,version_2_negotiate_interface_version_and_icd_gipa)68 TEST(EnvVarICDOverrideSetup, version_2_negotiate_interface_version_and_icd_gipa) {
69     FrameworkEnvironment env{};
70     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2).set_discovery_type(ManifestDiscoveryType::env_var));
71 
72     InstWrapper inst{env.vulkan_functions};
73     inst.CheckCreate();
74 
75     ASSERT_EQ(env.get_test_icd(0).called_vk_icd_gipa, CalledICDGIPA::vk_icd_gipa);
76 }
77 
78 // export vk_icdNegotiateLoaderICDInterfaceVersion and vk_icdGetInstanceProcAddr
TEST(EnvVarICDOverrideSetup,version_2_negotiate_interface_version_and_icd_gipa_unicode)79 TEST(EnvVarICDOverrideSetup, version_2_negotiate_interface_version_and_icd_gipa_unicode) {
80     FrameworkEnvironment env{};
81     env.add_icd(TestICDDetails(widen(TEST_ICD_PATH_VERSION_2_UNICODE))
82                     .set_discovery_type(ManifestDiscoveryType::env_var)
83                     .set_json_name(widen(TEST_JSON_NAME_VERSION_2_UNICODE)));
84 
85     InstWrapper inst{env.vulkan_functions};
86     inst.CheckCreate();
87 
88     ASSERT_EQ(env.get_test_icd(0).called_vk_icd_gipa, CalledICDGIPA::vk_icd_gipa);
89 }
90 
91 // Test VK_DRIVER_FILES environment variable
TEST(EnvVarICDOverrideSetup,TestOnlyDriverEnvVar)92 TEST(EnvVarICDOverrideSetup, TestOnlyDriverEnvVar) {
93     FrameworkEnvironment env{};
94     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
95     env.get_test_icd(0).add_physical_device("pd0");
96 
97     InstWrapper inst1{env.vulkan_functions};
98     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
99     inst1.CheckCreate();
100     EXPECT_FALSE(
101         env.debug_log.find("Ignoring override VK_ICD_FILENAMES, VK_DRIVER_FILES, and VK_ADD_DRIVER_FILES due to high-integrity"));
102 
103     std::array<VkPhysicalDevice, 5> phys_devs_array;
104     uint32_t phys_dev_count = 1;
105     ASSERT_EQ(inst1->vkEnumeratePhysicalDevices(inst1.inst, &phys_dev_count, phys_devs_array.data()), VK_SUCCESS);
106     ASSERT_EQ(phys_dev_count, 1U);
107 
108     for (uint32_t add = 0; add < 2; ++add) {
109         env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var))
110             .add_physical_device("pd" + std::to_string(add) + "0")
111             .add_physical_device("pd" + std::to_string(add) + "1");
112     }
113 
114     env.debug_log.clear();
115 
116     InstWrapper inst2{env.vulkan_functions};
117     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
118     inst2.CheckCreate();
119 
120     phys_dev_count = 5;
121     ASSERT_EQ(inst2->vkEnumeratePhysicalDevices(inst2.inst, &phys_dev_count, phys_devs_array.data()), VK_SUCCESS);
122     ASSERT_EQ(phys_dev_count, 5U);
123 
124     env.debug_log.clear();
125 
126     env.platform_shim->set_elevated_privilege(true);
127 
128     InstWrapper inst3{env.vulkan_functions};
129     FillDebugUtilsCreateDetails(inst3.create_info, env.debug_log);
130     inst3.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
131 
132     EXPECT_TRUE(env.debug_log.find("vkCreateInstance: Found no drivers!"));
133 
134     env.platform_shim->set_elevated_privilege(false);
135 }
136 
137 // Test VK_DRIVER_FILES environment variable containing a path to a folder
TEST(EnvVarICDOverrideSetup,TestOnlyDriverEnvVarInFolder)138 TEST(EnvVarICDOverrideSetup, TestOnlyDriverEnvVarInFolder) {
139     FrameworkEnvironment env{};
140     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var).set_is_dir(false));
141     env.get_test_icd(0).add_physical_device("pd0");
142 
143     InstWrapper inst1{env.vulkan_functions};
144     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
145     inst1.CheckCreate();
146     EXPECT_FALSE(
147         env.debug_log.find("Ignoring override VK_ICD_FILENAMES, VK_DRIVER_FILES, and VK_ADD_DRIVER_FILES due to high-integrity"));
148 
149     std::array<VkPhysicalDevice, 5> phys_devs_array;
150     uint32_t phys_dev_count = 1;
151     ASSERT_EQ(inst1->vkEnumeratePhysicalDevices(inst1.inst, &phys_dev_count, phys_devs_array.data()), VK_SUCCESS);
152     ASSERT_EQ(phys_dev_count, 1U);
153 
154     for (uint32_t add = 0; add < 2; ++add) {
155         env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var))
156             .add_physical_device("pd" + std::to_string(add) + "0")
157             .add_physical_device("pd" + std::to_string(add) + "1");
158     }
159 
160     env.debug_log.clear();
161 
162     InstWrapper inst2{env.vulkan_functions};
163     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
164     inst2.CheckCreate();
165 
166     phys_dev_count = 5;
167     ASSERT_EQ(inst2->vkEnumeratePhysicalDevices(inst2.inst, &phys_dev_count, phys_devs_array.data()), VK_SUCCESS);
168     ASSERT_EQ(phys_dev_count, 5U);
169 
170     env.debug_log.clear();
171 
172     env.platform_shim->set_elevated_privilege(true);
173 
174     InstWrapper inst3{env.vulkan_functions};
175     FillDebugUtilsCreateDetails(inst3.create_info, env.debug_log);
176     inst3.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
177 
178     EXPECT_TRUE(env.debug_log.find("vkCreateInstance: Found no drivers!"));
179 
180     env.platform_shim->set_elevated_privilege(false);
181 }
182 
183 #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__) || defined(__QNX__)
184 // Make sure the loader reports the correct message based on if LOADER_USE_UNSAFE_FILE_SEARCH is set or not
TEST(EnvVarICDOverrideSetup,NonSecureEnvVarLookup)185 TEST(EnvVarICDOverrideSetup, NonSecureEnvVarLookup) {
186     FrameworkEnvironment env{};
187     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
188 
189     DebugUtilsLogger log{VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT};
190     InstWrapper inst{env.vulkan_functions};
191     FillDebugUtilsCreateDetails(inst.create_info, log);
192     inst.CheckCreate();
193 
194 #if !defined(LOADER_USE_UNSAFE_FILE_SEARCH)
195     ASSERT_FALSE(log.find("Loader is using non-secure environment variable lookup for"));
196 #else
197     ASSERT_TRUE(log.find("Loader is using non-secure environment variable lookup for"));
198 #endif
199 }
200 
201 // Check for proper handling of paths specified via environment variables.
TEST(EnvVarICDOverrideSetup,XDG)202 TEST(EnvVarICDOverrideSetup, XDG) {
203     // Set up a layer path that includes default and user-specified locations,
204     // so that the test app can find them.  Include some badly specified elements as well.
205     // Need to redirect the 'home' directory
206     std::filesystem::path HOME = "/home/fake_home";
207     EnvVarWrapper home_env_var{"HOME", HOME};
208     EnvVarWrapper xdg_config_dirs_env_var{"XDG_CONFIG_DIRS", ":/tmp/goober:::::/tmp/goober/::::"};
209     EnvVarWrapper xdg_config_home_env_var{"XDG_CONFIG_HOME", ":/tmp/goober:::::/tmp/goober2/::::"};
210     EnvVarWrapper xdg_data_dirs_env_var{"XDG_DATA_DIRS", "::::/tmp/goober3:/tmp/goober4/with spaces:::"};
211     EnvVarWrapper xdg_data_home_env_var{"XDG_DATA_HOME", "::::/tmp/goober3:/tmp/goober4/with spaces:::"};
212 
213     FrameworkEnvironment env{};
214     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
215 
216     InstWrapper inst{env.vulkan_functions};
217     FillDebugUtilsCreateDetails(inst.create_info, env.debug_log);
218     inst.CheckCreate();
219 
220     auto check_paths = [](DebugUtilsLogger const& debug_log, ManifestCategory category) {
221         EXPECT_TRUE(debug_log.find((std::filesystem::path("/tmp/goober/vulkan") / category_path_name(category))));
222         EXPECT_TRUE(debug_log.find((std::filesystem::path("/tmp/goober2/vulkan") / category_path_name(category))));
223         EXPECT_TRUE(debug_log.find((std::filesystem::path("/tmp/goober3/vulkan") / category_path_name(category))));
224         EXPECT_TRUE(debug_log.find((std::filesystem::path("/tmp/goober4/with spaces/vulkan") / category_path_name(category))));
225     };
226     check_paths(env.debug_log, ManifestCategory::icd);
227     check_paths(env.debug_log, ManifestCategory::implicit_layer);
228     check_paths(env.debug_log, ManifestCategory::explicit_layer);
229 }
230 // Check that a json file in the paths don't cause the loader to crash
TEST(EnvVarICDOverrideSetup,XDGContainsJsonFile)231 TEST(EnvVarICDOverrideSetup, XDGContainsJsonFile) {
232     // Set up a layer path that includes default and user-specified locations,
233     // so that the test app can find them.  Include some badly specified elements as well.
234     // Need to redirect the 'home' directory
235     EnvVarWrapper xdg_config_dirs_env_var{"XDG_CONFIG_DIRS", "bad_file.json"};
236 
237     FrameworkEnvironment env{};
238     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
239 
240     InstWrapper inst{env.vulkan_functions};
241     FillDebugUtilsCreateDetails(inst.create_info, env.debug_log);
242     inst.CheckCreate();
243 }
244 #endif
245 
246 // Test VK_ADD_DRIVER_FILES environment variable
TEST(EnvVarICDOverrideSetup,TestOnlyAddDriverEnvVar)247 TEST(EnvVarICDOverrideSetup, TestOnlyAddDriverEnvVar) {
248     FrameworkEnvironment env{};
249     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::add_env_var));
250     env.get_test_icd(0).physical_devices.emplace_back("pd0");
251 
252     InstWrapper inst1{env.vulkan_functions};
253     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
254     inst1.CheckCreate();
255 
256     std::array<VkPhysicalDevice, 1> phys_devs_array;
257     uint32_t phys_dev_count = 1;
258     ASSERT_EQ(inst1->vkEnumeratePhysicalDevices(inst1.inst, &phys_dev_count, phys_devs_array.data()), VK_SUCCESS);
259     ASSERT_EQ(phys_dev_count, 1U);
260 
261     env.platform_shim->set_elevated_privilege(true);
262 
263     InstWrapper inst2{env.vulkan_functions};
264     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
265     inst2.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
266 
267     EXPECT_TRUE(env.debug_log.find("vkCreateInstance: Found no drivers!"));
268 
269     env.platform_shim->set_elevated_privilege(false);
270 }
271 
272 // Test Both VK_DRIVER_FILES and VK_ADD_DRIVER_FILES environment variable
TEST(EnvVarICDOverrideSetup,TestBothDriverEnvVars)273 TEST(EnvVarICDOverrideSetup, TestBothDriverEnvVars) {
274     FrameworkEnvironment env{};
275 
276     // Add a driver that isn't enabled with the environment variable
277     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::env_var));
278     env.get_test_icd(0).add_physical_device("pd0").add_physical_device("pd1");
279 
280     env.add_icd(TestICDDetails(TEST_ICD_PATH_EXPORT_NONE).set_discovery_type(ManifestDiscoveryType::add_env_var));
281     env.get_test_icd(0).add_physical_device("pd2");
282 
283     InstWrapper inst{env.vulkan_functions};
284     inst.CheckCreate();
285 
286     // The enumerate should now detect both drivers because we used the add
287     std::array<VkPhysicalDevice, 3> phys_devs_array;
288     uint32_t phys_dev_count = 3;
289     ASSERT_EQ(inst->vkEnumeratePhysicalDevices(inst.inst, &phys_dev_count, phys_devs_array.data()), VK_SUCCESS);
290     ASSERT_EQ(phys_dev_count, 3U);
291 }
292 
293 #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__GNU__) || defined(__QNX__)
294 // Test VK_LAYER_PATH environment variable
TEST(EnvVarICDOverrideSetup,TestOnlyLayerEnvVar)295 TEST(EnvVarICDOverrideSetup, TestOnlyLayerEnvVar) {
296     FrameworkEnvironment env{};
297     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
298     env.platform_shim->redirect_path("/tmp/carol", env.get_folder(ManifestLocation::explicit_layer_env_var).location());
299 
300     const char* layer_name = "TestLayer";
301     env.add_explicit_layer(
302         TestLayerDetails(ManifestLayer{}.add_layer(
303                              ManifestLayer::LayerDescription{}.set_name(layer_name).set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)),
304                          "test_layer.json")
305             .set_discovery_type(ManifestDiscoveryType::env_var));
306 
307     // Now set up a layer path that includes default and user-specified locations,
308     // so that the test app can find them.  Include some badly specified elements as well.
309     // Need to redirect the 'home' directory
310     std::filesystem::path HOME = "/home/fake_home";
311     EnvVarWrapper home_env_var{"HOME", HOME};
312     std::string vk_layer_path = ":/tmp/carol::::/:";
313     vk_layer_path += (HOME / "/ with spaces/:::::/tandy:");
314     EnvVarWrapper layer_path_env_var{"VK_LAYER_PATH", vk_layer_path};
315     InstWrapper inst1{env.vulkan_functions};
316     inst1.create_info.add_layer(layer_name);
317     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
318     inst1.CheckCreate();
319 
320     // look for VK_LAYER_PATHS
321     EXPECT_TRUE(env.debug_log.find("/tmp/carol"));
322     EXPECT_TRUE(env.debug_log.find("/tandy"));
323     EXPECT_TRUE(env.debug_log.find((HOME / "/ with spaces/")));
324 
325     env.debug_log.clear();
326 
327     env.platform_shim->set_elevated_privilege(true);
328 
329     InstWrapper inst2{env.vulkan_functions};
330     inst2.create_info.add_layer(layer_name);
331     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
332     inst2.CheckCreate(VK_ERROR_LAYER_NOT_PRESENT);
333 
334     EXPECT_FALSE(env.debug_log.find("/tmp/carol"));
335 
336     env.platform_shim->set_elevated_privilege(false);
337 }
338 
339 // Test VK_ADD_LAYER_PATH environment variable
TEST(EnvVarICDOverrideSetup,TestOnlyAddLayerEnvVar)340 TEST(EnvVarICDOverrideSetup, TestOnlyAddLayerEnvVar) {
341     FrameworkEnvironment env{};
342     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
343     env.platform_shim->redirect_path("/tmp/carol", env.get_folder(ManifestLocation::explicit_layer_add_env_var).location());
344 
345     const char* layer_name = "TestLayer";
346     env.add_explicit_layer(
347         TestLayerDetails(ManifestLayer{}.add_layer(
348                              ManifestLayer::LayerDescription{}.set_name(layer_name).set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)),
349                          "test_layer.json")
350             .set_discovery_type(ManifestDiscoveryType::add_env_var));
351 
352     // Set up a layer path that includes default and user-specified locations,
353     // so that the test app can find them.  Include some badly specified elements as well.
354     // Need to redirect the 'home' directory
355     std::filesystem::path HOME = "/home/fake_home";
356     EnvVarWrapper home_env_var{"HOME", HOME};
357     std::string vk_layer_path = ":/tmp/carol::::/:";
358     vk_layer_path += (HOME / "/ with spaces/:::::/tandy:");
359     EnvVarWrapper add_layer_path_env_var{"VK_ADD_LAYER_PATH", vk_layer_path};
360 
361     InstWrapper inst1{env.vulkan_functions};
362     inst1.create_info.add_layer(layer_name);
363     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
364     inst1.CheckCreate();
365 
366     // look for VK_ADD_LAYER_PATHS
367     EXPECT_TRUE(env.debug_log.find("/tmp/carol"));
368     EXPECT_TRUE(env.debug_log.find("/tandy"));
369     EXPECT_TRUE(env.debug_log.find((HOME / "/ with spaces/")));
370 
371     env.debug_log.clear();
372 
373     env.platform_shim->set_elevated_privilege(true);
374 
375     InstWrapper inst2{env.vulkan_functions};
376     inst2.create_info.add_layer(layer_name);
377     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
378     inst2.CheckCreate(VK_ERROR_LAYER_NOT_PRESENT);
379 
380     EXPECT_FALSE(env.debug_log.find("/tmp/carol"));
381 
382     env.platform_shim->set_elevated_privilege(false);
383 }
384 
385 // Test VK_IMPLICIT_LAYER_PATH environment variable
TEST(EnvVarICDOverrideSetup,TestOnlyImplicitLayerEnvVar)386 TEST(EnvVarICDOverrideSetup, TestOnlyImplicitLayerEnvVar) {
387     FrameworkEnvironment env{};
388     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
389     env.platform_shim->redirect_path("/tmp/carol", env.get_folder(ManifestLocation::implicit_layer_env_var).location());
390 
391     const char* layer_name = "TestLayer";
392     env.add_implicit_layer(TestLayerDetails(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
393                                                                           .set_name(layer_name)
394                                                                           .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
395                                                                           .set_disable_environment("DISABLE_ENV")),
396                                             "test_layer.json")
397                                .set_discovery_type(ManifestDiscoveryType::env_var));
398 
399     // Now set up a layer path that includes default and user-specified locations,
400     // so that the test app can find them.  Include some badly specified elements as well.
401     // Need to redirect the 'home' directory
402     std::filesystem::path HOME = "/home/fake_home";
403     EnvVarWrapper home_env_var{"HOME", HOME};
404     std::string vk_implicit_layer_path = ":/tmp/carol::::/:";
405     vk_implicit_layer_path += (HOME / "/ with spaces/:::::/tandy:");
406     EnvVarWrapper implicit_layer_path_env_var{"VK_IMPLICIT_LAYER_PATH", vk_implicit_layer_path};
407     InstWrapper inst1{env.vulkan_functions};
408     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
409     inst1.CheckCreate();
410 
411     auto active_layers1 = inst1.GetActiveLayers(inst1.GetPhysDev(), 1);
412     ASSERT_TRUE(string_eq(active_layers1.at(0).layerName, layer_name));
413 
414     // look for VK_IMPLICIT_LAYER_PATHS
415     EXPECT_TRUE(env.debug_log.find("/tmp/carol"));
416     EXPECT_TRUE(env.debug_log.find("/tandy"));
417     EXPECT_TRUE(env.debug_log.find((HOME / "/ with spaces/")));
418 
419     env.debug_log.clear();
420 
421     env.platform_shim->set_elevated_privilege(true);
422 
423     InstWrapper inst2{env.vulkan_functions};
424     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
425     inst2.CheckCreate();
426 
427     auto active_layers2 = inst2.GetActiveLayers(inst2.GetPhysDev(), 0);
428     ASSERT_TRUE(active_layers2.empty());
429 
430     EXPECT_FALSE(env.debug_log.find("/tmp/carol"));
431 
432     env.platform_shim->set_elevated_privilege(false);
433 }
434 
435 // Test VK_ADD_IMPLICIT_LAYER_PATH environment variable
TEST(EnvVarICDOverrideSetup,TestOnlyAddImplicitLayerEnvVar)436 TEST(EnvVarICDOverrideSetup, TestOnlyAddImplicitLayerEnvVar) {
437     FrameworkEnvironment env{};
438     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device("physical_device_0");
439     env.platform_shim->redirect_path("/tmp/carol", env.get_folder(ManifestLocation::implicit_layer_add_env_var).location());
440 
441     const char* layer_name = "TestLayer";
442     env.add_implicit_layer(TestLayerDetails(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
443                                                                           .set_name(layer_name)
444                                                                           .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
445                                                                           .set_disable_environment("DISABLE_ENV")),
446                                             "test_layer.json")
447                                .set_discovery_type(ManifestDiscoveryType::add_env_var));
448 
449     // Set up a layer path that includes default and user-specified locations,
450     // so that the test app can find them.  Include some badly specified elements as well.
451     // Need to redirect the 'home' directory
452     std::filesystem::path HOME = "/home/fake_home";
453     EnvVarWrapper home_env_var{"HOME", HOME};
454     std::string vk_add_implicit_layer_path = ":/tmp/carol::::/:";
455     vk_add_implicit_layer_path += (HOME / "/ with spaces/:::::/tandy:");
456     EnvVarWrapper add_implicit_layer_path_env_var{"VK_ADD_LAYER_PATH", vk_add_implicit_layer_path};
457 
458     InstWrapper inst1{env.vulkan_functions};
459     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
460     inst1.CheckCreate();
461 
462     auto active_layers1 = inst1.GetActiveLayers(inst1.GetPhysDev(), 1);
463     ASSERT_TRUE(string_eq(active_layers1.at(0).layerName, layer_name));
464 
465     // look for VK_ADD_IMPLICIT_LAYER_PATHS
466     EXPECT_TRUE(env.debug_log.find("/tmp/carol"));
467     EXPECT_TRUE(env.debug_log.find("/tandy"));
468     EXPECT_TRUE(env.debug_log.find((HOME / "/ with spaces/")));
469 
470     env.debug_log.clear();
471 
472     env.platform_shim->set_elevated_privilege(true);
473 
474     InstWrapper inst2{env.vulkan_functions};
475     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
476     inst2.CheckCreate();
477 
478     auto active_layers2 = inst2.GetActiveLayers(inst2.GetPhysDev(), 0);
479     ASSERT_TRUE(active_layers2.empty());
480 
481     EXPECT_FALSE(env.debug_log.find("/tmp/carol"));
482 
483     env.platform_shim->set_elevated_privilege(false);
484 }
485 
486 #endif
487 
488 // Test that the driver filter select will only enable driver manifest files that match the filter
TEST(EnvVarICDOverrideSetup,FilterSelectDriver)489 TEST(EnvVarICDOverrideSetup, FilterSelectDriver) {
490     FrameworkEnvironment env{};
491     EnvVarWrapper filter_select_env_var{"VK_LOADER_DRIVERS_SELECT"};
492 
493     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6).set_disable_icd_inc(true).set_json_name("ABC_ICD"));
494     env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_2}.set_disable_icd_inc(true).set_json_name("BCD_ICD"));
495     env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_3}.set_disable_icd_inc(true).set_json_name("CDE_ICD"));
496 
497     InstWrapper inst1{env.vulkan_functions};
498     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
499     inst1.CheckCreate();
500 
501     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
502     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
503     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
504     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
505     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
506     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
507     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
508     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
509     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
510 
511     // Match full-name
512     env.debug_log.clear();
513     filter_select_env_var.set_new_value("ABC_ICD.json");
514 
515     InstWrapper inst2{env.vulkan_functions};
516     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
517     inst2.CheckCreate();
518 
519     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
520     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
521     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
522     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
523     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
524     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
525     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
526     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
527     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
528 
529     // Match prefix
530     env.debug_log.clear();
531     filter_select_env_var.set_new_value("ABC*");
532 
533     InstWrapper inst3{env.vulkan_functions};
534     FillDebugUtilsCreateDetails(inst3.create_info, env.debug_log);
535     inst3.CheckCreate();
536 
537     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
538     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
539     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
540     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
541     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
542     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
543     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
544     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
545     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
546 
547     // Match suffix
548     env.debug_log.clear();
549     filter_select_env_var.set_new_value("*C_ICD.json");
550 
551     InstWrapper inst4{env.vulkan_functions};
552     FillDebugUtilsCreateDetails(inst4.create_info, env.debug_log);
553     inst4.CheckCreate();
554 
555     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
556     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
557     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
558     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
559     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
560     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
561     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
562     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
563     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
564 
565     // Match sub-string
566     env.debug_log.clear();
567     filter_select_env_var.set_new_value("*BC*");
568 
569     InstWrapper inst5{env.vulkan_functions};
570     FillDebugUtilsCreateDetails(inst5.create_info, env.debug_log);
571     inst5.CheckCreate();
572 
573     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
574     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
575     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
576     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
577     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
578     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
579     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
580     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
581     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
582 
583     // Match all with star '*'
584     env.debug_log.clear();
585     filter_select_env_var.set_new_value("*");
586 
587     InstWrapper inst6{env.vulkan_functions};
588     FillDebugUtilsCreateDetails(inst6.create_info, env.debug_log);
589     inst6.CheckCreate();
590 
591     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
592     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
593     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
594     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
595     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
596     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
597     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
598     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
599     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
600 
601     // Match all with special name
602     env.debug_log.clear();
603     filter_select_env_var.set_new_value("~all~");
604 
605     InstWrapper inst7{env.vulkan_functions};
606     FillDebugUtilsCreateDetails(inst7.create_info, env.debug_log);
607     inst7.CheckCreate();
608 
609     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
610     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
611     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
612     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
613     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
614     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
615     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
616     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
617     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
618 
619     // The full-name string is not a valid match if it doesn't also include the file extension
620     env.debug_log.clear();
621     filter_select_env_var.set_new_value("ABC_ICD");
622 
623     InstWrapper inst8{env.vulkan_functions};
624     FillDebugUtilsCreateDetails(inst8.create_info, env.debug_log);
625     inst8.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
626 
627     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
628     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
629     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
630     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
631     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
632     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
633     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
634     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
635     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
636 }
637 
638 // Test that the driver filter disable disables driver manifest files that match the filter
TEST(EnvVarICDOverrideSetup,FilterDisableDriver)639 TEST(EnvVarICDOverrideSetup, FilterDisableDriver) {
640     FrameworkEnvironment env{};
641     EnvVarWrapper filter_disable_env_var{"VK_LOADER_DRIVERS_DISABLE"};
642 
643     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6).set_disable_icd_inc(true).set_json_name("ABC_ICD"));
644     env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_2}.set_disable_icd_inc(true).set_json_name("BCD_ICD"));
645     env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_3}.set_disable_icd_inc(true).set_json_name("CDE_ICD"));
646 
647     InstWrapper inst1{env.vulkan_functions};
648     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
649     inst1.CheckCreate();
650 
651     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
652     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
653     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
654     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
655     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
656     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
657     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
658     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
659     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
660 
661     // Match full-name
662     env.debug_log.clear();
663     filter_disable_env_var.set_new_value("ABC_ICD.json");
664 
665     InstWrapper inst2{env.vulkan_functions};
666     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
667     inst2.CheckCreate();
668 
669     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
670     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
671     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
672     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
673     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
674     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
675     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
676     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
677     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
678 
679     // Match prefix
680     env.debug_log.clear();
681     filter_disable_env_var.set_new_value("ABC_*");
682 
683     InstWrapper inst3{env.vulkan_functions};
684     FillDebugUtilsCreateDetails(inst3.create_info, env.debug_log);
685     inst3.CheckCreate();
686 
687     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
688     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
689     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
690     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
691     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
692     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
693     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
694     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
695     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
696 
697     // Match suffix
698     env.debug_log.clear();
699     filter_disable_env_var.set_new_value("*C_ICD.json");
700 
701     InstWrapper inst4{env.vulkan_functions};
702     FillDebugUtilsCreateDetails(inst4.create_info, env.debug_log);
703     inst4.CheckCreate();
704 
705     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
706     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
707     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
708     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
709     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
710     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
711     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
712     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
713     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
714 
715     // Match substring
716     env.debug_log.clear();
717     filter_disable_env_var.set_new_value("*BC*");
718 
719     InstWrapper inst5{env.vulkan_functions};
720     FillDebugUtilsCreateDetails(inst5.create_info, env.debug_log);
721     inst5.CheckCreate();
722 
723     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
724     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
725     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
726     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
727     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
728     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
729     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
730     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
731     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
732 
733     // Match all with star '*'
734     env.debug_log.clear();
735     filter_disable_env_var.set_new_value("*");
736 
737     InstWrapper inst6{env.vulkan_functions};
738     FillDebugUtilsCreateDetails(inst6.create_info, env.debug_log);
739     inst6.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
740 
741     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
742     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
743     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
744     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
745     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
746     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
747     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
748     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
749     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
750 
751     // Match all with special name
752     env.debug_log.clear();
753     filter_disable_env_var.set_new_value("~all~");
754 
755     InstWrapper inst7{env.vulkan_functions};
756     FillDebugUtilsCreateDetails(inst7.create_info, env.debug_log);
757     inst7.CheckCreate(VK_ERROR_INCOMPATIBLE_DRIVER);
758 
759     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
760     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
761     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
762     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
763     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
764     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
765     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
766     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
767     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
768 }
769 
770 // Test that the when both driver filter select and disable environment variables are present, that the
771 // appropriate drivers are enabled and disabled
TEST(EnvVarICDOverrideSetup,FilterSelectAndDisableDriver)772 TEST(EnvVarICDOverrideSetup, FilterSelectAndDisableDriver) {
773     FrameworkEnvironment env{};
774     EnvVarWrapper filter_disable_env_var{"VK_LOADER_DRIVERS_DISABLE"};
775     EnvVarWrapper filter_select_env_var{"VK_LOADER_DRIVERS_SELECT"};
776 
777     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6).set_disable_icd_inc(true).set_json_name("ABC_ICD"));
778     env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_2}.set_disable_icd_inc(true).set_json_name("BCD_ICD"));
779     env.add_icd(TestICDDetails{TEST_ICD_PATH_VERSION_6, VK_API_VERSION_1_3}.set_disable_icd_inc(true).set_json_name("CDE_ICD"));
780 
781     InstWrapper inst1{env.vulkan_functions};
782     FillDebugUtilsCreateDetails(inst1.create_info, env.debug_log);
783     inst1.CheckCreate();
784 
785     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
786     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
787     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
788     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
789     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
790     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
791     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
792     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
793     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
794 
795     // Disable two, but enable one
796     env.debug_log.clear();
797     filter_disable_env_var.set_new_value("*BC*");
798     filter_select_env_var.set_new_value("BCD*");
799 
800     InstWrapper inst2{env.vulkan_functions};
801     FillDebugUtilsCreateDetails(inst2.create_info, env.debug_log);
802     inst2.CheckCreate();
803 
804     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
805     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
806     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
807     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
808     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
809     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
810     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
811     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
812     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
813 
814     // Disable all, but enable two
815     env.debug_log.clear();
816     filter_disable_env_var.set_new_value("*");
817     filter_select_env_var.set_new_value("*BC*");
818 
819     InstWrapper inst3{env.vulkan_functions};
820     FillDebugUtilsCreateDetails(inst3.create_info, env.debug_log);
821     inst3.CheckCreate();
822 
823     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
824     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
825     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
826     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
827     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
828     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
829     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
830     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
831     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
832 
833     // Disable all, but enable all
834     env.debug_log.clear();
835     filter_disable_env_var.set_new_value("*");
836     filter_select_env_var.set_new_value("*");
837 
838     InstWrapper inst4{env.vulkan_functions};
839     FillDebugUtilsCreateDetails(inst4.create_info, env.debug_log);
840     inst4.CheckCreate();
841 
842     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "ABC_ICD.json"));
843     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because not selected by env var"));
844     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("ABC_ICD.json", "ignored because it was disabled by env var"));
845     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "BCD_ICD.json"));
846     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because not selected by env var"));
847     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("BCD_ICD.json", "ignored because it was disabled by env var"));
848     ASSERT_TRUE(env.debug_log.find_prefix_then_postfix("Found ICD manifest file", "CDE_ICD.json"));
849     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because not selected by env var"));
850     ASSERT_FALSE(env.debug_log.find_prefix_then_postfix("CDE_ICD.json", "ignored because it was disabled by env var"));
851 }
852