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
Change-Id: I9709b5eac98d8057a9080f12c07c8a2b76c83850
// 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)
{
}
{
}
+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;
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;
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;
};
// 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,
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;
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,
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;
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];