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>
Thu, 25 Aug 2016 19:19:18 +0000 (12:19 -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
Change-Id: I9709b5eac98d8057a9080f12c07c8a2b76c83850

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 22246657e1f986fda7e64d6c8240e05a3e9d3049..36027b9466a1db8b029a64c7e3bcc0c93ba51d71 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 ecba532ec4535fe2b823314faf1abeeb7f9c407a..63cabd83c2ae0aa880719017b01d9fdd0f8c00e9 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 5336d4460531b7d0c73b11b4b99a5b4989790af0..36eaee223c568ad53a5951ddbae2230dbf22d6af 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 a450128a09fe3bf99fa6574083e6b882a791f58c..701ec4b3a77b6f7ddc863d13ecebfa8b27a841d0 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 f4fea746f7c1c2134748cf929130f897c31e2845..4eb92f5cc528eefe2e19f224631dce52faff8ffe 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];