Fix duplicate layer test which used /etc
authorCharles Giessen <charles@lunarg.com>
Mon, 3 Jul 2023 20:18:10 +0000 (14:18 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Tue, 18 Jul 2023 21:49:15 +0000 (15:49 -0600)
The ImplicitLayers.DuplicateLayers test requires there to be two separate
files on the file system, located in different paths. To accomplish that, the
test writes a file to /etc and another to the default location. By default,
that is typically /usr/local/share. If the project is configured to set /etc
as that default location, only one file will be written.

The fix is to move the duplicate file from /etc to the default home directory,
since that is configured from inside the tests itself. This does change the
order the layers are found in, so the logic of the test had to be flipped.

tests/framework/test_environment.h
tests/loader_layer_tests.cpp
tests/loader_testing_main.cpp

index 5ac61636523c0f27d89152795d08b36328ac5ea0..42f19f987478d69351c58accf2684a6d9182683a 100644 (file)
 
 #include "layer/test_layer.h"
 
+// Useful defines
+#if COMMON_UNIX_PLATFORMS
+#define HOME_DIR "/home/fake_home"
+#define USER_LOCAL_SHARE_DIR HOME_DIR "/.local/share"
+#define ETC_DIR "/etc"
+#endif
+
 // handle checking
 template <typename T>
 void handle_assert_has_value(T const& handle) {
index 4e9a22e33fc7cd78608f52ce712f52bb0b3bb36d..60bd5ded596f3773b4da0e8cb9a1f5f3b65b7d1b 100644 (file)
@@ -957,6 +957,7 @@ TEST(ImplicitLayers, EnableAndDisableWithFilter) {
 }
 
 // Add 2 implicit layers with the same layer name and expect only one to be loaded.
+// Expect the second layer to be found first, because it'll be in a path that is searched first.
 TEST(ImplicitLayers, DuplicateLayers) {
     FrameworkEnvironment env;
     env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device({});
@@ -968,28 +969,28 @@ TEST(ImplicitLayers, DuplicateLayers) {
                                                                           .set_description("actually_layer_1")
                                                                           .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
                                                                           .set_disable_environment("if_you_can")),
-                                            "regular_layer_1.json")
-                               // use override folder as just a folder and manually add it to the implicit layer search paths
-                               .set_discovery_type(ManifestDiscoveryType::override_folder));
+                                            "regular_layer_1.json"));
     auto& layer1 = env.get_test_layer(0);
     layer1.set_description("actually_layer_1");
     layer1.set_make_spurious_log_in_create_instance("actually_layer_1");
-#if defined(WIN32)
-    env.platform_shim->add_manifest(ManifestCategory::implicit_layer, env.get_folder(ManifestLocation::override_layer).location());
-#elif COMMON_UNIX_PLATFORMS
-    env.platform_shim->redirect_path(fs::path("/etc/vulkan/implicit_layer.d"),
-                                     env.get_folder(ManifestLocation::override_layer).location());
-#endif
 
     env.add_implicit_layer(TestLayerDetails(ManifestLayer{}.add_layer(ManifestLayer::LayerDescription{}
                                                                           .set_name(same_layer_name_1)
                                                                           .set_description("actually_layer_2")
                                                                           .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
                                                                           .set_disable_environment("if_you_can")),
-                                            "regular_layer_1.json"));
+                                            "regular_layer_1.json")
+                               // use override folder as just a folder and manually add it to the implicit layer search paths
+                               .set_discovery_type(ManifestDiscoveryType::override_folder));
     auto& layer2 = env.get_test_layer(1);
     layer2.set_description("actually_layer_2");
     layer2.set_make_spurious_log_in_create_instance("actually_layer_2");
+#if defined(WIN32)
+    env.platform_shim->add_manifest(ManifestCategory::implicit_layer, env.get_folder(ManifestLocation::override_layer).location());
+#elif COMMON_UNIX_PLATFORMS
+    env.platform_shim->redirect_path(fs::path(USER_LOCAL_SHARE_DIR "/vulkan/implicit_layer.d"),
+                                     env.get_folder(ManifestLocation::override_layer).location());
+#endif
 
     auto layer_props = env.GetLayerProperties(2);
     ASSERT_TRUE(string_eq(same_layer_name_1, layer_props[0].layerName));
index 46f006bc5fc6333688a1d3d7d1242b4f66307a18..75e145d63fbd929e59c0e1d616189ee4e69ea61c 100644 (file)
@@ -83,11 +83,11 @@ int main(int argc, char** argv) {
 
 #if COMMON_UNIX_PLATFORMS
     // Set only one of the 4 XDG variables to /etc, let everything else be empty
-    EnvVarWrapper xdg_config_home_env_var{"XDG_CONFIG_HOME", "/etc"};
+    EnvVarWrapper xdg_config_home_env_var{"XDG_CONFIG_HOME", ETC_DIR};
     EnvVarWrapper xdg_config_dirs_env_var{"XDG_CONFIG_DIRS"};
     EnvVarWrapper xdg_data_home_env_var{"XDG_DATA_HOME"};
     EnvVarWrapper xdg_data_dirs_env_var{"XDG_DATA_DIRS"};
-    EnvVarWrapper home_env_var{"HOME", "/home/fake_home"};
+    EnvVarWrapper home_env_var{"HOME", HOME_DIR};
 #endif
     ::testing::InitGoogleTest(&argc, argv);
     ::testing::UnitTest::GetInstance()->listeners().Append(new ThrowListener);