CP: Do not test VkDevice, VkInstance creation OOM paths in WSI tests
VkInstance and VkDevice creation OOM simulation is done already in
dEQP-VK.api.object_management.alloc_callback fail and repeating testing
in WSI tests just wastes time.
Since we want to trigger OOM even if implementation calls into instance-
or device-level callbacks, this is done by setting a mode in
DeterministicFailAllocator that stops alloc counting and failure
simulation.
Bug: 30811856
(cherry picked from commit 2dd2c2dc560092c80b636551237758b62fae78d7)
Change-Id: I93389a2c6b85f2dd8407824afb25d68770d4e6bd
diff --git a/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.cpp b/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.cpp
index 723706a..9569282 100644
--- a/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.cpp
+++ b/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.cpp
@@ -277,9 +277,10 @@
// DeterministicFailAllocator
-DeterministicFailAllocator::DeterministicFailAllocator (const VkAllocationCallbacks* allocator, deUint32 numPassingAllocs)
+DeterministicFailAllocator::DeterministicFailAllocator (const VkAllocationCallbacks* allocator, deUint32 numPassingAllocs, Mode initialMode)
: ChainedAllocator (allocator)
, m_numPassingAllocs(numPassingAllocs)
+ , m_mode (initialMode)
, m_allocationNdx (0)
{
}
@@ -288,9 +289,15 @@
{
}
+void DeterministicFailAllocator::setMode (Mode mode)
+{
+ m_mode = mode;
+}
+
void* DeterministicFailAllocator::allocate (size_t size, size_t alignment, VkSystemAllocationScope allocationScope)
{
- if (deAtomicIncrementUint32(&m_allocationNdx) <= m_numPassingAllocs)
+ if ((m_mode == MODE_DO_NOT_COUNT) ||
+ (deAtomicIncrementUint32(&m_allocationNdx) <= m_numPassingAllocs))
return ChainedAllocator::allocate(size, alignment, allocationScope);
else
return DE_NULL;
@@ -298,7 +305,8 @@
void* DeterministicFailAllocator::reallocate (void* original, size_t size, size_t alignment, VkSystemAllocationScope allocationScope)
{
- if (deAtomicIncrementUint32(&m_allocationNdx) <= m_numPassingAllocs)
+ if ((m_mode == MODE_DO_NOT_COUNT) ||
+ (deAtomicIncrementUint32(&m_allocationNdx) <= m_numPassingAllocs))
return ChainedAllocator::reallocate(original, size, alignment, allocationScope);
else
return DE_NULL;
diff --git a/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.hpp b/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.hpp
index ecba532..63cabd8 100644
--- a/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.hpp
+++ b/external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.hpp
@@ -158,14 +158,26 @@
class DeterministicFailAllocator : public ChainedAllocator
{
public:
- DeterministicFailAllocator (const VkAllocationCallbacks* allocator, deUint32 numPassingAllocs);
+ enum Mode
+ {
+ MODE_DO_NOT_COUNT = 0, //!< Do not count allocations, all allocs will succeed
+ MODE_COUNT_AND_FAIL, //!< Count allocations, fail when reaching alloc N
+
+ MODE_LAST
+ };
+
+ DeterministicFailAllocator (const VkAllocationCallbacks* allocator, deUint32 numPassingAllocs, Mode initialMode);
~DeterministicFailAllocator (void);
+ void setMode (Mode mode);
+
void* allocate (size_t size, size_t alignment, VkSystemAllocationScope allocationScope);
void* reallocate (void* original, size_t size, size_t alignment, VkSystemAllocationScope allocationScope);
private:
const deUint32 m_numPassingAllocs;
+
+ Mode m_mode;
volatile deUint32 m_allocationNdx;
};
diff --git a/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp b/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
index 5336d44..36eaee2 100644
--- a/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
+++ b/external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
@@ -2326,7 +2326,9 @@
// Iterate over test until object allocation succeeds
for (; numPassingAllocs < maxTries; ++numPassingAllocs)
{
- DeterministicFailAllocator objAllocator(getSystemAllocator(), numPassingAllocs);
+ DeterministicFailAllocator objAllocator(getSystemAllocator(),
+ numPassingAllocs,
+ DeterministicFailAllocator::MODE_COUNT_AND_FAIL);
AllocationCallbackRecorder recorder (objAllocator.getCallbacks(), 128);
const Environment objEnv (resEnv.env.vkp,
resEnv.env.vkd,
diff --git a/external/vulkancts/modules/vulkan/wsi/vktWsiSurfaceTests.cpp b/external/vulkancts/modules/vulkan/wsi/vktWsiSurfaceTests.cpp
index 66db6e6..b74bda0 100644
--- a/external/vulkancts/modules/vulkan/wsi/vktWsiSurfaceTests.cpp
+++ b/external/vulkancts/modules/vulkan/wsi/vktWsiSurfaceTests.cpp
@@ -230,7 +230,9 @@
for (deUint32 numPassingAllocs = 0; numPassingAllocs <= 1024u; ++numPassingAllocs)
{
AllocationCallbackRecorder allocationRecorder (getSystemAllocator());
- DeterministicFailAllocator failingAllocator (allocationRecorder.getCallbacks(), numPassingAllocs);
+ DeterministicFailAllocator failingAllocator (allocationRecorder.getCallbacks(),
+ numPassingAllocs,
+ DeterministicFailAllocator::MODE_DO_NOT_COUNT);
bool gotOOM = false;
log << TestLog::Message << "Testing with " << numPassingAllocs << " first allocations succeeding" << TestLog::EndMessage;
@@ -238,6 +240,11 @@
try
{
const InstanceHelper instHelper (context, wsiType, failingAllocator.getCallbacks());
+
+ // OOM is not simulated for VkInstance as we don't want to spend time
+ // testing OOM paths inside instance creation.
+ failingAllocator.setMode(DeterministicFailAllocator::MODE_COUNT_AND_FAIL);
+
const NativeObjects native (context, instHelper.supportedExtensions, wsiType);
const Unique<VkSurfaceKHR> surface (createSurface(instHelper.vki,
*instHelper.instance,
diff --git a/external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp b/external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp
index 4de0915..d18c88a 100644
--- a/external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp
+++ b/external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp
@@ -607,7 +607,9 @@
if (m_numPassingAllocs <= 16*1024u)
{
AllocationCallbackRecorder allocationRecorder (getSystemAllocator());
- DeterministicFailAllocator failingAllocator (allocationRecorder.getCallbacks(), m_numPassingAllocs);
+ DeterministicFailAllocator failingAllocator (allocationRecorder.getCallbacks(),
+ m_numPassingAllocs,
+ DeterministicFailAllocator::MODE_DO_NOT_COUNT);
bool gotOOM = false;
log << TestLog::Message << "Testing with " << m_numPassingAllocs << " first allocations succeeding" << TestLog::EndMessage;
@@ -625,6 +627,10 @@
const DeviceHelper devHelper (m_context, instHelper.vki, *instHelper.instance, *surface, failingAllocator.getCallbacks());
const vector<VkSwapchainCreateInfoKHR> cases (generateSwapchainParameterCases(m_params.wsiType, m_params.dimension, instHelper.vki, devHelper.physicalDevice, *surface));
+ // We don't care testing OOM paths in VkInstance, VkSurface, or VkDevice
+ // creation as they are tested elsewhere.
+ failingAllocator.setMode(DeterministicFailAllocator::MODE_COUNT_AND_FAIL);
+
for (size_t caseNdx = 0; caseNdx < cases.size(); ++caseNdx)
{
VkSwapchainCreateInfoKHR curParams = cases[caseNdx];