Fix the limitation in allocation test
authorArkadiusz Sarwa <arkadiusz.sarwa@amd.com>
Mon, 21 Jan 2019 14:50:34 +0000 (15:50 +0100)
committerArkadiusz Sarwa <arkadiusz.sarwa@amd.com>
Thu, 7 Mar 2019 12:25:29 +0000 (13:25 +0100)
Change removes the limitation for number of allocations
in the test.

Components: Vulkan

VK-GL-CTS issue: 1569

Affects:
dEQP-VK.api.device_init.create_instance_device_intentional_alloc_fail

Change-Id: I038fcfcae46a6baaf691163166c74ea0d3831043

external/vulkancts/modules/vulkan/api/vktApiDeviceInitializationTests.cpp

index 8294b70..5aec40a 100644 (file)
@@ -1061,10 +1061,12 @@ std::vector<AllocTrack> g_allocatedVector;
 bool                                   g_intentionalFailEnabled        = false;
 deUint32                               g_intenionalFailIndex           = 0;
 deUint32                               g_intenionalFailCount           = 0;
+size_t                                 g_allocationsCount                      = 0;
 
 void freeAllocTracker (void)
 {
        g_allocatedVector.clear();
+       g_allocationsCount = 0;
 }
 
 void initAllocTracker (size_t size, deUint32 intentionalFailIndex = (deUint32)~0)
@@ -1086,6 +1088,8 @@ void initAllocTracker (size_t size, deUint32 intentionalFailIndex = (deUint32)~0
                g_intenionalFailIndex           = 0;
                g_intenionalFailCount           = 0;
        }
+
+       g_allocationsCount = 0;
 }
 
 bool isAllocTrackerEmpty ()
@@ -1134,6 +1138,7 @@ VKAPI_ATTR void *VKAPI_CALL allocCallbackFunc (void *pUserData, size_t size, siz
                                g_allocatedVector[vectorIdx].wasAllocated                       = true;
                        }
 
+                       g_allocationsCount++;
                        return g_allocatedVector[vectorIdx].alignedStartAddress;
                }
        }
@@ -1235,14 +1240,25 @@ tcu::TestStatus createInstanceDeviceIntentionalAllocFail (Context& context)
                DE_NULL                                                                 // ppEnabledExtensionNames
        };
        deUint32                                        failIndex                       = 0;
-       VkResult                                        result                          = VK_ERROR_OUT_OF_HOST_MEMORY;
+       VkResult                                        result                          = VK_SUCCESS;
+       size_t                                          max_allowed_alloc       = 0;
 
-       while (result == VK_ERROR_OUT_OF_HOST_MEMORY)
+       do
        {
-               initAllocTracker(9999, failIndex++);
+               if (max_allowed_alloc == 0)
+               {
+                       if (result != VK_SUCCESS)
+                               return tcu::TestStatus::fail("Could not create instance and device");
+
+                       initAllocTracker(99999);
+               }
+               else
+               {
+                       initAllocTracker(max_allowed_alloc, failIndex++);
 
-               if (failIndex >= 9999u)
-                       return tcu::TestStatus::fail("Out of retries, could not create instance and device");
+                       if (failIndex >= static_cast<deUint32>(max_allowed_alloc))
+                               return tcu::TestStatus::fail("Out of retries, could not create instance and device");
+               }
 
                result = vkp.createInstance(&instanceCreateInfo, &allocationCallbacks, &instance);
 
@@ -1353,8 +1369,14 @@ tcu::TestStatus createInstanceDeviceIntentionalAllocFail (Context& context)
 
                DeviceDriver(vkp, instance, device).destroyDevice(device, &allocationCallbacks);
                vki.destroyInstance(instance, &allocationCallbacks);
+               if (max_allowed_alloc == 0)
+               {
+                       max_allowed_alloc       = g_allocationsCount + 100;
+                       result                          = VK_ERROR_OUT_OF_HOST_MEMORY;
+               }
                freeAllocTracker();
        }
+       while (result == VK_ERROR_OUT_OF_HOST_MEMORY);
 
        return tcu::TestStatus::pass("Pass");
 }