CP: Do not test VkDevice, VkInstance creation OOM paths in WSI tests
authorPyry Haulos <phaulos@google.com>
Thu, 18 Aug 2016 14:22:00 +0000 (15:22 +0100)
committerPyry Haulos <phaulos@google.com>
Mon, 29 Aug 2016 22:35:23 +0000 (15:35 -0700)
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

external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.cpp
external/vulkancts/framework/vulkan/vkAllocationCallbackUtil.hpp
external/vulkancts/modules/vulkan/api/vktApiObjectManagementTests.cpp
external/vulkancts/modules/vulkan/wsi/vktWsiSurfaceTests.cpp
external/vulkancts/modules/vulkan/wsi/vktWsiSwapchainTests.cpp

index 723706a..9569282 100644 (file)
@@ -277,9 +277,10 @@ void AllocationCallbackRecorder::notifyInternalFree (size_t size, VkInternalAllo
 
 // 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 @@ DeterministicFailAllocator::~DeterministicFailAllocator (void)
 {
 }
 
+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::allocate (size_t size, size_t alignment, VkSys
 
 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;
index ecba532..63cabd8 100644 (file)
@@ -158,14 +158,26 @@ private:
 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;
 };
 
index 5336d44..36eaee2 100644 (file)
@@ -2326,7 +2326,9 @@ tcu::TestStatus allocCallbackFailTest (Context& context, typename Object::Parame
                // 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,
index 66db6e6..b74bda0 100644 (file)
@@ -230,7 +230,9 @@ tcu::TestStatus createSurfaceSimulateOOMTest (Context& context, Type wsiType)
        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 @@ tcu::TestStatus createSurfaceSimulateOOMTest (Context& context, Type wsiType)
                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,
index 4de0915..d18c88a 100644 (file)
@@ -607,7 +607,9 @@ tcu::TestStatus CreateSwapchainSimulateOOMTest::iterate (void)
        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 @@ tcu::TestStatus CreateSwapchainSimulateOOMTest::iterate (void)
                        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];