Fix device_memory_report test
allocation_failed test for VK_EXT_device_memory_report attempts to
allocate UINT64_MAX bytes of memory in order to deliberately trigger
an allocation failure. However, vkAllocateMemory also has VU in which
allocationSize must be less than or equal to
VkPhysicalDeviceMemoryProperties::memoryHeaps[memindex].size .
VK-GL-CTS issue: 3775
Components: Vulkan
Affects:
dEQP-VK.memory.device_memory_report.vk_device_memory.allocation_failed
Change-Id: I0b9db1beb1e7b01d369d5ee6bbfb93c2eb3e1c97
diff --git a/external/vulkancts/modules/vulkan/memory/vktMemoryDeviceMemoryReportTests.cpp b/external/vulkancts/modules/vulkan/memory/vktMemoryDeviceMemoryReportTests.cpp
index 05ffbc1..f22c098 100644
--- a/external/vulkancts/modules/vulkan/memory/vktMemoryDeviceMemoryReportTests.cpp
+++ b/external/vulkancts/modules/vulkan/memory/vktMemoryDeviceMemoryReportTests.cpp
@@ -1832,30 +1832,44 @@
const Unique<VkDevice> device (createDeviceWithMemoryReport(isValidationEnabled, vkp, instance, vki, physicalDevice, queueFamilyIndex, &recorder));
const DeviceDriver vkd (vkp, instance, *device);
const VkPhysicalDeviceMemoryProperties memoryProperties = getPhysicalDeviceMemoryProperties(vki, physicalDevice);
- const VkDeviceSize testSize = std::numeric_limits<deUint64>::max();
const deUint32 testTypeIndex = 0;
const deUint32 testHeapIndex = memoryProperties.memoryTypes[testTypeIndex].heapIndex;
+ const VkDeviceSize testSize = memoryProperties.memoryHeaps[testHeapIndex].size;
{
recorder.setCallbackMarker(MARKER_ALLOCATION_FAILED);
- VkResult result = VK_SUCCESS;
- VkDeviceMemory memory = DE_NULL;
- const VkMemoryAllocateInfo memoryAllocateInfo =
+ VkDeviceMemory memory1 = DE_NULL;
+ VkDeviceMemory memory2 = DE_NULL;
+ VkMemoryAllocateInfo memoryAllocateInfo
{
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType;
DE_NULL, // const void* pNext;
- testSize, // VkDeviceSize allocationSize;
+ 128, // VkDeviceSize allocationSize;
testHeapIndex, // uint32_t memoryTypeIndex;
};
- result = vkd.allocateMemory(*device, &memoryAllocateInfo, (const VkAllocationCallbacks*)DE_NULL, &memory);
+ // first do a small allocation to prevent LowMemoryKiller on android from culling this app
+ VkResult result = vkd.allocateMemory(*device, &memoryAllocateInfo, (const VkAllocationCallbacks*)DE_NULL, &memory1);
+ if (result != VK_SUCCESS)
+ TCU_THROW(NotSupportedError, "Unable to do a small allocation");
+
+ // if small allocation succeeded then we can try to trigger an allocation failure by allocating as much memory as there is on the heap
+ memoryAllocateInfo.allocationSize = testSize;
+ result = vkd.allocateMemory(*device, &memoryAllocateInfo, (const VkAllocationCallbacks*)DE_NULL, &memory2);
if (result == VK_SUCCESS)
{
- return tcu::TestStatus::fail("Should not be able to allocate UINT64_MAX bytes of memory");
+ vkd.freeMemory(*device, memory1, DE_NULL);
+ vkd.freeMemory(*device, memory2, DE_NULL);
+ return tcu::TestStatus::fail(std::string("Should not be able to allocate ") + std::to_string(testSize) + " bytes of memory");
}
recorder.setCallbackMarker(MARKER_UNKNOWN);
+
+ if (!!memory1)
+ vkd.freeMemory(*device, memory1, DE_NULL);
+ if (!!memory2)
+ vkd.freeMemory(*device, memory2, DE_NULL);
}
deBool allocationFailedEvent = false;