Add test for layer_prop_list out of bounds indexing
authorCharles Giessen <charles@lunarg.com>
Fri, 23 Jun 2023 03:42:26 +0000 (21:42 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 23 Jun 2023 04:27:45 +0000 (22:27 -0600)
This test makes sure that we correctly query for unknown functions implemented
only in a single layer while there are other layers present. This commit
successfully reproduces the error that the previous commit fixes. It was
difficult to reproduce because to get an crash, the test has to have the
instance_layer_list be in a different order than how they appear in
expanded_activated_layer_list.

tests/loader_unknown_ext_tests.cpp

index 569234e..dd918b8 100644 (file)
@@ -1263,3 +1263,49 @@ TEST(UnknownFunction, ManyCombinations) {
         unknown_funcs.at(5).check<Functions::zero::physical_device>(env.vulkan_functions, inst.inst, phys_dev);
     }
 }
+
+TEST(UnknownFunction, PhysicalDeviceFunctionInLayer) {
+    FrameworkEnvironment env{};
+    env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_2_EXPORT_ICD_GPDPA)).add_physical_device({});
+
+    env.add_implicit_layer(ManifestLayer{}
+                               .add_layer(ManifestLayer::LayerDescription{}
+                                              .set_name("VK_LAYER_implicit_layer_1")
+                                              .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_0)
+                                              .set_disable_environment("DISABLE_ME"))
+                               .set_file_format_version({1, 0, 0}),
+                           "implicit_layer_1.json");
+
+    UnknownFunction unknown_func{"vkPhysicalDeviceFunctionInLayer"};
+    const char* ext_name = "VK_EXT_not_funny";
+
+    const char* explicit_layer_unknown_function_implement = "VK_LAYER_implement_unknown_function";
+    env.add_explicit_layer(
+        ManifestLayer{}
+            .add_layer(ManifestLayer::LayerDescription{}
+                           .set_name(explicit_layer_unknown_function_implement)
+                           .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2)
+                           .add_instance_extension(ManifestLayer::LayerDescription::Extension{ext_name, 0, {unknown_func.name}}))
+            .set_file_format_version({1, 1, 0}),
+        "implement_unknown_function.json");
+    auto& layer0 = env.get_test_layer(1);
+
+    const char* explicit_layer_to_enable_1 = "VK_LAYER_explicit_layer_1";
+    env.add_explicit_layer(ManifestLayer{}
+                               .add_layer(ManifestLayer::LayerDescription{}
+                                              .set_name(explicit_layer_to_enable_1)
+                                              .set_lib_path(TEST_LAYER_PATH_EXPORT_VERSION_2))
+                               .set_file_format_version({1, 2, 0}),
+                           "explicit_layer_2.json");
+
+    Functions::four::physical_device::add_implementation_to_layer(unknown_func, layer0);
+
+    InstWrapper inst{env.vulkan_functions};
+    inst.create_info.add_layer(explicit_layer_to_enable_1);
+    inst.create_info.add_layer(explicit_layer_unknown_function_implement);
+    inst.CheckCreate();
+
+    VkPhysicalDevice phys_dev = inst.GetPhysDev();
+
+    unknown_func.check<Functions::four::physical_device>(env.vulkan_functions, inst.inst, phys_dev);
+}