diff options
Diffstat (limited to 'tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp')
-rw-r--r-- | tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 66853a88d8..094c6ed0a5 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -92,6 +92,7 @@ private slots: void tryTake(); void waitForDoneTimeout(); void destroyingWaitsForTasksToFinish(); + void stackSize(); void stressTest(); void takeAllAndIncreaseMaxThreadCount(); @@ -962,21 +963,6 @@ void tst_QThreadPool::cancel() QSemaphore sem(0); QSemaphore startedThreads(0); - class SemaphoreReleaser - { - QSemaphore &sem; - int n; - Q_DISABLE_COPY(SemaphoreReleaser) - public: - explicit SemaphoreReleaser(QSemaphore &sem, int n) - : sem(sem), n(n) {} - - ~SemaphoreReleaser() - { - sem.release(n); - } - }; - class BlockingRunnable : public QRunnable { public: @@ -1015,7 +1001,7 @@ void tst_QThreadPool::cancel() // ensure that the QThreadPool doesn't deadlock if any of the checks fail // and cause an early return: - const SemaphoreReleaser semReleaser(sem, runs); + const QSemaphoreReleaser semReleaser(sem, runs); count.store(0); QAtomicInt dtorCounter = 0; @@ -1049,21 +1035,6 @@ void tst_QThreadPool::tryTake() QSemaphore sem(0); QSemaphore startedThreads(0); - class SemaphoreReleaser - { - QSemaphore &sem; - int n; - Q_DISABLE_COPY(SemaphoreReleaser) - public: - explicit SemaphoreReleaser(QSemaphore &sem, int n) - : sem(sem), n(n) {} - - ~SemaphoreReleaser() - { - sem.release(n); - } - }; - class BlockingRunnable : public QRunnable { public: @@ -1102,7 +1073,7 @@ void tst_QThreadPool::tryTake() // ensure that the QThreadPool doesn't deadlock if any of the checks fail // and cause an early return: - const SemaphoreReleaser semReleaser(sem, Runs); + const QSemaphoreReleaser semReleaser(sem, Runs); count.store(0); QAtomicInt dtorCounter = 0; @@ -1167,6 +1138,39 @@ void tst_QThreadPool::destroyingWaitsForTasksToFinish() } } +// Verify that QThreadPool::stackSize is used when creating +// new threads. Note that this tests the Qt property only +// since QThread::stackSize() does not reflect the actual +// stack size used by the native thread. +void tst_QThreadPool::stackSize() +{ + uint targetStackSize = 512 * 1024; + uint threadStackSize = 1; // impossible value + + class StackSizeChecker : public QRunnable + { + public: + uint *stackSize; + + StackSizeChecker(uint *stackSize) + :stackSize(stackSize) + { + + } + + void run() + { + *stackSize = QThread::currentThread()->stackSize(); + } + }; + + QThreadPool threadPool; + threadPool.setStackSize(targetStackSize); + threadPool.start(new StackSizeChecker(&threadStackSize)); + QVERIFY(threadPool.waitForDone(30000)); // 30s timeout + QCOMPARE(threadStackSize, targetStackSize); +} + void tst_QThreadPool::stressTest() { class Task : public QRunnable |