Make test_layer delete destroyed devices
authorCharles Giessen <charles@lunarg.com>
Fri, 8 Sep 2023 20:28:35 +0000 (14:28 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Fri, 8 Sep 2023 21:56:37 +0000 (15:56 -0600)
Destroyed devices need to be removed from the test_layer's created_devices
vector, so that it doesn't accidentally mistake dead devices for alive ones
when checking for whether a device extension is supported or not.

This caused multiple days of debugging headache as it caused sporadic test
failures due to the re-use of VkDevice handle values (which is caused by
the memory manager reusing allocations). Since a second VkDevice could share
the handle value of the first, and the first wasn't removed from the vector,
test_layer would use the data assocated with the first device by mistake.

tests/framework/layer/test_layer.cpp
tests/loader_debug_ext_tests.cpp

index c2747c8b6143d275508ac9cfab94b25c1f11a887..2764f665c15c3d3e2513de0c58bb9ded81fd3cd0 100644 (file)
@@ -654,11 +654,11 @@ VKAPI_ATTR void VKAPI_CALL test_vkDestroyDevice(VkDevice device, const VkAllocat
                                        layer.second_device_created_during_create_device.dispatch_table.DestroyDevice);
     }
 
-    for (auto& created_device : layer.created_devices) {
-        if (created_device.device_handle == device) {
-            created_device.dispatch_table.DestroyDevice(device, pAllocator);
-            break;
-        }
+    auto it = std::find_if(std::begin(layer.created_devices), std::end(layer.created_devices),
+                           [device](const TestLayer::Device& dev) { return device == dev.device_handle; });
+    if (it != std::end(layer.created_devices)) {
+        it->dispatch_table.DestroyDevice(device, pAllocator);
+        layer.created_devices.erase(it);
     }
 }
 
index e5472e49d643b19ad26b2003558ea3363b22a5d1..aa6b7f0e7c7f0127c5df3fa96033c4b1af9a2b37 100644 (file)
@@ -1074,11 +1074,11 @@ TEST(GetProcAddr, DebugFuncsWithTrampoline) {
     driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"});
     // Hardware doesn't support the debug extensions
 
-    // // Use getDeviceProcAddr & vary enabling the debug extensions
+    // Use getDeviceProcAddr & vary enabling the debug extensions
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, false));
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, false));
 
-    // // Use getInstanceProcAddr & vary enabling the debug extensions
+    // Use getInstanceProcAddr & vary enabling the debug extensions
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, false));
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, false));
 
@@ -1108,11 +1108,11 @@ TEST(GetProcAddr, DebugFuncsWithDebugExtsForceAdded) {
     driver.physical_devices.at(0).add_extensions({"VK_KHR_swapchain"});
     // Hardware doesn't support the debug extensions
 
-    // // Use getDeviceProcAddr & vary enabling the debug extensions
+    // Use getDeviceProcAddr & vary enabling the debug extensions
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, false));
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, false));
 
-    // // Use getInstanceProcAddr & vary enabling the debug extensions
+    // Use getInstanceProcAddr & vary enabling the debug extensions
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, false, false));
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, true, true, false));
 
@@ -1126,7 +1126,7 @@ TEST(GetProcAddr, DebugFuncsWithDebugExtsForceAdded) {
         .add_injected_instance_extensions({{VK_EXT_DEBUG_REPORT_EXTENSION_NAME}, {VK_EXT_DEBUG_UTILS_EXTENSION_NAME}})
         .add_injected_device_extension({VK_EXT_DEBUG_MARKER_EXTENSION_NAME});
 
-    // // Use getDeviceProcAddr & vary enabling the debug extensions
+    // Use getDeviceProcAddr & vary enabling the debug extensions
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, false, true));
     ASSERT_NO_FATAL_FAILURE(CheckDeviceFunctions(env, false, true, true));