From de3b298e13a63994f68fb073a577b95412ef4960 Mon Sep 17 00:00:00 2001 From: Tony Zlatinski Date: Sun, 24 Jan 2016 14:50:51 -0600 Subject: [PATCH] CTS Memory tests fix invalid allocation sizes allocateRandom() routine sometime requests enormous sizes because of incorrect random size calculation logic. Within the following formula: m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage - 1ull If m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage is "0" the result is negative, but since the number is unsigned max takes the max of 1 and the (unsigned long long)-1. The change, makes the comparison signed and also introduces explicit test checks on the allocation sizes. --- .../vulkancts/modules/vulkan/memory/vktMemoryAllocationTests.cpp | 5 +++++ external/vulkancts/modules/vulkan/memory/vktMemoryMappingTests.cpp | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/external/vulkancts/modules/vulkan/memory/vktMemoryAllocationTests.cpp b/external/vulkancts/modules/vulkan/memory/vktMemoryAllocationTests.cpp index af0cac0..8a3ff92 100644 --- a/external/vulkancts/modules/vulkan/memory/vktMemoryAllocationTests.cpp +++ b/external/vulkancts/modules/vulkan/memory/vktMemoryAllocationTests.cpp @@ -378,6 +378,11 @@ tcu::TestStatus RandomAllocFreeTestInstance::iterate (void) const MemoryType& memoryType = m_rng.choose(heap.types.begin(), heap.types.end()); const VkDeviceSize allocationSize = 1 + (m_rng.getUint64() % (deUint64)(heap.maxMemoryUsage - heap.memoryUsage)); + + if ((allocationSize > (deUint64)(heap.maxMemoryUsage - heap.memoryUsage)) && (allocationSize != 1)) + TCU_THROW(InternalError, "Test Error: trying to allocate memory more than the available heap size."); + + const MemoryObject object = { (VkDeviceMemory)0, diff --git a/external/vulkancts/modules/vulkan/memory/vktMemoryMappingTests.cpp b/external/vulkancts/modules/vulkan/memory/vktMemoryMappingTests.cpp index ea3cd65..5d23556 100644 --- a/external/vulkancts/modules/vulkan/memory/vktMemoryMappingTests.cpp +++ b/external/vulkancts/modules/vulkan/memory/vktMemoryMappingTests.cpp @@ -539,8 +539,12 @@ public: MemoryObject* allocateRandom (const DeviceInterface& vkd, VkDevice device, de::Random& rng) { - const VkDeviceSize size = 1 + (rng.getUint64() % (de::max((m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage - 1ull, 1ull))); + const VkDeviceSize size = 1 + (rng.getUint64() % (de::max((deInt64)((m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage - 1ull), (deInt64)1))); const deUint32 type = rng.choose(m_memoryTypes.begin(), m_memoryTypes.end()); + + if ( (size > (VkDeviceSize)((m_heap.size / MAX_MEMORY_USAGE_DIV) - m_usage)) && (size != 1)) + TCU_THROW(InternalError, "Test Error: trying to allocate memory more than the available heap size."); + MemoryObject* const object = new MemoryObject(vkd, device, size, type); m_usage += size; -- 2.7.4