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 <jason.mcdonald@nokia.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
Thiago Macieira 2012-08-22 17:47:27 +02:00 committed by Qt by Nokia
parent 2292bf0669
commit 8e0bac89d4

View File

@ -80,10 +80,12 @@ void tst_QMutex::tryLock()
{ {
testsTurn.release(); testsTurn.release();
// TEST 1: thread can't acquire lock
threadsTurn.acquire(); threadsTurn.acquire();
QVERIFY(!normalMutex.tryLock()); QVERIFY(!normalMutex.tryLock());
testsTurn.release(); testsTurn.release();
// TEST 2: thread can acquire lock
threadsTurn.acquire(); threadsTurn.acquire();
QVERIFY(normalMutex.tryLock()); QVERIFY(normalMutex.tryLock());
QVERIFY(lockCount.testAndSetRelaxed(0, 1)); QVERIFY(lockCount.testAndSetRelaxed(0, 1));
@ -92,6 +94,7 @@ void tst_QMutex::tryLock()
normalMutex.unlock(); normalMutex.unlock();
testsTurn.release(); testsTurn.release();
// TEST 3: thread can't acquire lock, timeout = waitTime
threadsTurn.acquire(); threadsTurn.acquire();
QTime timer; QTime timer;
timer.start(); timer.start();
@ -99,22 +102,26 @@ void tst_QMutex::tryLock()
QVERIFY(timer.elapsed() >= waitTime); QVERIFY(timer.elapsed() >= waitTime);
testsTurn.release(); testsTurn.release();
// TEST 4: thread can acquire lock, timeout = waitTime
threadsTurn.acquire(); threadsTurn.acquire();
timer.start(); timer.start();
QVERIFY(normalMutex.tryLock(waitTime)); QVERIFY(normalMutex.tryLock(waitTime));
QVERIFY(timer.elapsed() <= waitTime); QVERIFY(timer.elapsed() <= waitTime);
QVERIFY(lockCount.testAndSetRelaxed(0, 1)); QVERIFY(lockCount.testAndSetRelaxed(0, 1));
timer.start(); timer.start();
// it's non-recursive, so the following lock needs to fail
QVERIFY(!normalMutex.tryLock(waitTime)); QVERIFY(!normalMutex.tryLock(waitTime));
QVERIFY(timer.elapsed() >= waitTime); QVERIFY(timer.elapsed() >= waitTime);
QVERIFY(lockCount.testAndSetRelaxed(1, 0)); QVERIFY(lockCount.testAndSetRelaxed(1, 0));
normalMutex.unlock(); normalMutex.unlock();
testsTurn.release(); testsTurn.release();
// TEST 5: thread can't acquire lock, timeout = 0
threadsTurn.acquire(); threadsTurn.acquire();
QVERIFY(!normalMutex.tryLock(0)); QVERIFY(!normalMutex.tryLock(0));
testsTurn.release(); testsTurn.release();
// TEST 6: thread can acquire lock, timeout = 0
threadsTurn.acquire(); threadsTurn.acquire();
timer.start(); timer.start();
QVERIFY(normalMutex.tryLock(0)); QVERIFY(normalMutex.tryLock(0));
@ -132,37 +139,37 @@ void tst_QMutex::tryLock()
Thread thread; Thread thread;
thread.start(); thread.start();
// thread can't acquire lock // TEST 1: thread can't acquire lock
testsTurn.acquire(); testsTurn.acquire();
normalMutex.lock(); normalMutex.lock();
QVERIFY(lockCount.testAndSetRelaxed(0, 1)); QVERIFY(lockCount.testAndSetRelaxed(0, 1));
threadsTurn.release(); threadsTurn.release();
// thread can acquire lock // TEST 2: thread can acquire lock
testsTurn.acquire(); testsTurn.acquire();
QVERIFY(lockCount.testAndSetRelaxed(1, 0)); QVERIFY(lockCount.testAndSetRelaxed(1, 0));
normalMutex.unlock(); normalMutex.unlock();
threadsTurn.release(); threadsTurn.release();
// thread can't acquire lock, timeout = waitTime // TEST 3: thread can't acquire lock, timeout = waitTime
testsTurn.acquire(); testsTurn.acquire();
normalMutex.lock(); normalMutex.lock();
QVERIFY(lockCount.testAndSetRelaxed(0, 1)); QVERIFY(lockCount.testAndSetRelaxed(0, 1));
threadsTurn.release(); threadsTurn.release();
// thread can acquire lock, timeout = waitTime // TEST 4: thread can acquire lock, timeout = waitTime
testsTurn.acquire(); testsTurn.acquire();
QVERIFY(lockCount.testAndSetRelaxed(1, 0)); QVERIFY(lockCount.testAndSetRelaxed(1, 0));
normalMutex.unlock(); normalMutex.unlock();
threadsTurn.release(); threadsTurn.release();
// thread can't acquire lock, timeout = 0 // TEST 5: thread can't acquire lock, timeout = 0
testsTurn.acquire(); testsTurn.acquire();
normalMutex.lock(); normalMutex.lock();
QVERIFY(lockCount.testAndSetRelaxed(0, 1)); QVERIFY(lockCount.testAndSetRelaxed(0, 1));
threadsTurn.release(); threadsTurn.release();
// thread can acquire lock, timeout = 0 // TEST 6: thread can acquire lock, timeout = 0
testsTurn.acquire(); testsTurn.acquire();
QVERIFY(lockCount.testAndSetRelaxed(1, 0)); QVERIFY(lockCount.testAndSetRelaxed(1, 0));
normalMutex.unlock(); normalMutex.unlock();