From 8e0bac89d4b0f01b71c57f79a3b98a6ecb7f20ae Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 22 Aug 2012 17:47:27 +0200 Subject: tst_QMutex: add markers to the tryLock tests Just to make it clear which two sections go together. Change-Id: If3724d1c84172a61bdd7931cc567f4b7140d4f8a Reviewed-by: Jason McDonald Reviewed-by: Bradley T. Hughes --- tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 72670ab33f..d6ece1de4a 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -80,10 +80,12 @@ void tst_QMutex::tryLock() { testsTurn.release(); + // TEST 1: thread can't acquire lock threadsTurn.acquire(); QVERIFY(!normalMutex.tryLock()); testsTurn.release(); + // TEST 2: thread can acquire lock threadsTurn.acquire(); QVERIFY(normalMutex.tryLock()); QVERIFY(lockCount.testAndSetRelaxed(0, 1)); @@ -92,6 +94,7 @@ void tst_QMutex::tryLock() normalMutex.unlock(); testsTurn.release(); + // TEST 3: thread can't acquire lock, timeout = waitTime threadsTurn.acquire(); QTime timer; timer.start(); @@ -99,22 +102,26 @@ void tst_QMutex::tryLock() QVERIFY(timer.elapsed() >= waitTime); testsTurn.release(); + // TEST 4: thread can acquire lock, timeout = waitTime threadsTurn.acquire(); timer.start(); QVERIFY(normalMutex.tryLock(waitTime)); QVERIFY(timer.elapsed() <= waitTime); QVERIFY(lockCount.testAndSetRelaxed(0, 1)); timer.start(); + // it's non-recursive, so the following lock needs to fail QVERIFY(!normalMutex.tryLock(waitTime)); QVERIFY(timer.elapsed() >= waitTime); QVERIFY(lockCount.testAndSetRelaxed(1, 0)); normalMutex.unlock(); testsTurn.release(); + // TEST 5: thread can't acquire lock, timeout = 0 threadsTurn.acquire(); QVERIFY(!normalMutex.tryLock(0)); testsTurn.release(); + // TEST 6: thread can acquire lock, timeout = 0 threadsTurn.acquire(); timer.start(); QVERIFY(normalMutex.tryLock(0)); @@ -132,37 +139,37 @@ void tst_QMutex::tryLock() Thread thread; thread.start(); - // thread can't acquire lock + // TEST 1: thread can't acquire lock testsTurn.acquire(); normalMutex.lock(); QVERIFY(lockCount.testAndSetRelaxed(0, 1)); threadsTurn.release(); - // thread can acquire lock + // TEST 2: thread can acquire lock testsTurn.acquire(); QVERIFY(lockCount.testAndSetRelaxed(1, 0)); normalMutex.unlock(); threadsTurn.release(); - // thread can't acquire lock, timeout = waitTime + // TEST 3: thread can't acquire lock, timeout = waitTime testsTurn.acquire(); normalMutex.lock(); QVERIFY(lockCount.testAndSetRelaxed(0, 1)); threadsTurn.release(); - // thread can acquire lock, timeout = waitTime + // TEST 4: thread can acquire lock, timeout = waitTime testsTurn.acquire(); QVERIFY(lockCount.testAndSetRelaxed(1, 0)); normalMutex.unlock(); threadsTurn.release(); - // thread can't acquire lock, timeout = 0 + // TEST 5: thread can't acquire lock, timeout = 0 testsTurn.acquire(); normalMutex.lock(); QVERIFY(lockCount.testAndSetRelaxed(0, 1)); threadsTurn.release(); - // thread can acquire lock, timeout = 0 + // TEST 6: thread can acquire lock, timeout = 0 testsTurn.acquire(); QVERIFY(lockCount.testAndSetRelaxed(1, 0)); normalMutex.unlock(); -- cgit v1.2.3