From: Kristof Kosztyo Date: Fri, 22 Jan 2016 10:33:06 +0000 (+0100) Subject: Fix potential resource leaks in buffer tests X-Git-Tag: upstream/0.1.0~812^2~86^2~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6afafbfeedf51c3354d4c296bb10ac3f2e7f4d1d;p=platform%2Fupstream%2FVK-GL-CTS.git Fix potential resource leaks in buffer tests Fixes #46 --- diff --git a/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp index 7f98e8bf2..55a2745a2 100644 --- a/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp +++ b/external/vulkancts/modules/vulkan/api/vktApiBufferTests.cpp @@ -40,6 +40,7 @@ #include "tcuTestLog.hpp" #include "vkPrograms.hpp" #include "vkQueryUtil.hpp" +#include "vkRefUtil.hpp" #include "vktTestCase.hpp" namespace vkt @@ -102,9 +103,9 @@ private: { const VkDevice vkDevice = m_context.getDevice(); const DeviceInterface& vk = m_context.getDeviceInterface(); - VkBuffer testBuffer; + Move testBuffer; VkMemoryRequirements memReqs; - VkDeviceMemory memory; + Move memory; const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex(); // Create buffer @@ -121,10 +122,16 @@ private: &queueFamilyIndex, }; - if (vk.createBuffer(vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL, &testBuffer) != VK_SUCCESS) - return tcu::TestStatus::fail("Buffer creation failed! (requested memory size: " + de::toString(size) + ")"); + try + { + testBuffer = createBuffer(vk, vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL); + } + catch (const vk::Error& error) + { + return tcu::TestStatus::fail("Buffer creation failed! (requested memory size: " + de::toString(size) + ", Error code: " + de::toString(error.getMessage()) + ")"); + } - vk.getBufferMemoryRequirements(vkDevice, testBuffer, &memReqs); + vk.getBufferMemoryRequirements(vkDevice, *testBuffer, &memReqs); if (size > memReqs.size) { @@ -144,9 +151,14 @@ private: 0 // deUint32 memoryTypeIndex }; - if (vk.allocateMemory(vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL, &memory) != VK_SUCCESS) - return tcu::TestStatus::fail("Alloc memory failed! (requested memory size: " + de::toString(size) + ")"); - + try + { + memory = allocateMemory(vk, vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL); + } + catch (const vk::Error& error) + { + return tcu::TestStatus::fail("Alloc memory failed! (requested memory size: " + de::toString(size) + ", Error code: " + de::toString(error.getMessage()) + ")"); + } if ((m_testCase.flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) || (m_testCase.flags & VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT) || @@ -160,14 +172,14 @@ private: { 0, // VkDeviceSize resourceOffset; memReqs.size, // VkDeviceSize size; - memory, // VkDeviceMemory memory; + *memory, // VkDeviceMemory memory; 0, // VkDeviceSize memoryOffset; 0 // VkSparseMemoryBindFlags flags; }; const VkSparseBufferMemoryBindInfo sparseBufferMemoryBindInfo = { - testBuffer, // VkBuffer buffer; + *testBuffer, // VkBuffer buffer; 1u, // deUint32 bindCount; &sparseMemoryBind // const VkSparseMemoryBind* pBinds; }; @@ -191,13 +203,10 @@ private: if (vk.queueBindSparse(queue, 1, &bindSparseInfo, DE_NULL) != VK_SUCCESS) return tcu::TestStatus::fail("Bind sparse buffer memory failed! (requested memory size: " + de::toString(size) + ")"); } else - if (vk.bindBufferMemory(vkDevice, testBuffer, memory, 0) != VK_SUCCESS) + if (vk.bindBufferMemory(vkDevice, *testBuffer, *memory, 0) != VK_SUCCESS) return tcu::TestStatus::fail("Bind buffer memory failed! (requested memory size: " + de::toString(size) + ")"); } - vk.freeMemory(vkDevice, memory, (const VkAllocationCallbacks*)DE_NULL); - vk.destroyBuffer(vkDevice, testBuffer, (const VkAllocationCallbacks*)DE_NULL); - return tcu::TestStatus::pass("Buffer test"); } diff --git a/external/vulkancts/modules/vulkan/api/vktApiBufferViewCreateTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiBufferViewCreateTests.cpp index 9c14d79f8..4e494962a 100644 --- a/external/vulkancts/modules/vulkan/api/vktApiBufferViewCreateTests.cpp +++ b/external/vulkancts/modules/vulkan/api/vktApiBufferViewCreateTests.cpp @@ -39,6 +39,7 @@ #include "gluVarType.hpp" #include "tcuTestLog.hpp" #include "vkPrograms.hpp" +#include "vkRefUtil.hpp" #include "vktTestCase.hpp" namespace vkt @@ -107,7 +108,7 @@ tcu::TestStatus BufferViewTestInstance::iterate (void) const DeviceInterface& vk = m_context.getDeviceInterface(); const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex(); const VkDeviceSize size = 3 * 5 * 7 * 64; - VkBuffer testBuffer; + Move testBuffer; VkMemoryRequirements memReqs; VkFormatProperties properties; const VkBufferCreateInfo bufferParams = @@ -126,10 +127,16 @@ tcu::TestStatus BufferViewTestInstance::iterate (void) if (!(properties.bufferFeatures & m_testCase.features)) TCU_THROW(NotSupportedError, "Format not supported"); - if (vk.createBuffer(vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL, &testBuffer) != VK_SUCCESS) - return tcu::TestStatus::fail("Buffer creation failed!"); + try + { + testBuffer = createBuffer(vk, vkDevice, &bufferParams, (const VkAllocationCallbacks*)DE_NULL); + } + catch (const vk::Error& error) + { + return tcu::TestStatus::fail("Buffer creation failed! (Error code: " + de::toString(error.getMessage()) + ")"); + } - vk.getBufferMemoryRequirements(vkDevice, testBuffer, &memReqs); + vk.getBufferMemoryRequirements(vkDevice, *testBuffer, &memReqs); if (size > memReqs.size) { @@ -138,7 +145,7 @@ tcu::TestStatus BufferViewTestInstance::iterate (void) return tcu::TestStatus::fail(errorMsg.str()); } - VkDeviceMemory memory; + Move memory; const VkMemoryAllocateInfo memAlloc = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // VkStructureType sType @@ -149,53 +156,64 @@ tcu::TestStatus BufferViewTestInstance::iterate (void) { // Create buffer view. - VkBufferView bufferView; + Move bufferView; const VkBufferViewCreateInfo bufferViewCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType; NULL, // const void* pNext; (VkBufferViewCreateFlags)0, - testBuffer, // VkBuffer buffer; + *testBuffer, // VkBuffer buffer; m_testCase.format, // VkFormat format; m_testCase.offset, // VkDeviceSize offset; m_testCase.range, // VkDeviceSize range; }; - if (vk.allocateMemory(vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL, &memory) != VK_SUCCESS) - return tcu::TestStatus::fail("Alloc memory failed!"); + try + { + memory = allocateMemory(vk, vkDevice, &memAlloc, (const VkAllocationCallbacks*)DE_NULL); + } + catch (const vk::Error& error) + { + return tcu::TestStatus::fail("Alloc memory failed! (Error code: " + de::toString(error.getMessage()) + ")"); + } - if (vk.bindBufferMemory(vkDevice, testBuffer, memory, 0) != VK_SUCCESS) + if (vk.bindBufferMemory(vkDevice, *testBuffer, *memory, 0) != VK_SUCCESS) return tcu::TestStatus::fail("Bind buffer memory failed!"); - if (vk.createBufferView(vkDevice, &bufferViewCreateInfo, (const VkAllocationCallbacks*)DE_NULL, &bufferView) != VK_SUCCESS) - return tcu::TestStatus::fail("Buffer View creation failed!"); - - vk.destroyBufferView(vkDevice, bufferView, (const VkAllocationCallbacks*)DE_NULL); + try + { + bufferView = createBufferView(vk, vkDevice, &bufferViewCreateInfo, (const VkAllocationCallbacks*)DE_NULL); + } + catch (const vk::Error& error) + { + return tcu::TestStatus::fail("Buffer View creation failed! (Error code: " + de::toString(error.getMessage()) + ")"); + } } // Testing complete view size. { - VkBufferView completeBufferView; + Move completeBufferView; VkBufferViewCreateInfo completeBufferViewCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, // VkStructureType sType; NULL, // const void* pNext; (VkBufferViewCreateFlags)0, - testBuffer, // VkBuffer buffer; + *testBuffer, // VkBuffer buffer; m_testCase.format, // VkFormat format; m_testCase.offset, // VkDeviceSize offset; size, // VkDeviceSize range; }; - if (vk.createBufferView(vkDevice, &completeBufferViewCreateInfo, (const VkAllocationCallbacks*)DE_NULL, &completeBufferView) != VK_SUCCESS) - return tcu::TestStatus::fail("Buffer View creation failed!"); - - vk.destroyBufferView(vkDevice, completeBufferView, (const VkAllocationCallbacks*)DE_NULL); + try + { + completeBufferView = createBufferView(vk, vkDevice, &completeBufferViewCreateInfo, (const VkAllocationCallbacks*)DE_NULL); + } + catch (const vk::Error& error) + { + return tcu::TestStatus::fail("Buffer View creation failed! (Error code: " + de::toString(error.getMessage()) + ")"); + } } - vk.freeMemory(vkDevice, memory, (const VkAllocationCallbacks*)DE_NULL); - vk.destroyBuffer(vkDevice, testBuffer, (const VkAllocationCallbacks*)DE_NULL); - return tcu::TestStatus::pass("BufferView test"); }