From 7a402fb6e60f0de30bec65418588299fe593ec5e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Nov 2015 15:34:30 +0100 Subject: [PATCH] WIP: Introduce clever wait predicate for tst_QWaitCondition::wakeOne(). Use with QTRY_COMPARE to get of wait(). TODO: Does *not* work, crashes with recursive mutex lock. Task-number: QTBUG-49653 Change-Id: I3daf12493a0457ee97408876e212fda1531008fd --- .../thread/qwaitcondition/tst_qwaitcondition.cpp | 46 ++++++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp index df52aa4..146d1f4 100644 --- a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp @@ -451,11 +451,37 @@ public: } }; +static const int firstWaitInterval = 1000; +static const int waitInterval = 30; + +class WaitPred { + Q_DISABLE_COPY(WaitPred) +public: + WaitPred(bool *thread_exited, + QThread *threads, + int count) : m_exited(0), m_threads(threads), m_thread_exited(thread_exited), m_count(count) {} + + int exited() + { + for (int y = 0; y < m_count; ++y) { + qDebug() << y << m_thread_exited[y]; + if (!m_thread_exited[y] && !m_threads[y].isRunning()) { + m_thread_exited[y] = true; + ++m_exited; + } + } + return m_exited; + } + +private: + int m_exited; + const QThread *m_threads; + bool *m_thread_exited; + int m_count; +}; + void tst_QWaitCondition::wakeOne() { - static const int firstWaitInterval = 1000; - static const int waitInterval = 30; - int x; QAtomicInt count; // wake up threads, one at a time @@ -602,17 +628,11 @@ void tst_QWaitCondition::wakeOne() QVERIFY(!thread[x + 1].dummy.wait(&mutex, 1)); mutex.unlock(); - int exited = 0; - for (int y = 0; y < ThreadCount; ++y) { - if (thread_exited[y]) - continue; - if (thread[y].wait(exited > 0 ? waitInterval : firstWaitInterval)) { - thread_exited[y] = true; - ++exited; - } - } + WaitPred p(thread_exited, thread, ThreadCount); + qDebug() << "x=" << x; + + QTRY_COMPARE(p.exited(), 2); - QCOMPARE(exited, 2); QCOMPARE(count.load(), ThreadCount - (x + 2)); } -- 2.5.0.windows.1