diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2011-05-03 01:53:57 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2011-05-05 02:03:52 (GMT) |
commit | f18e0e01468899731bc3777649d69fd6d0041012 (patch) | |
tree | fa21b765cb8a203f49435e688d77c544a87281fc /tests | |
parent | 28ccfa472991c0480e67b5f204a567c4023ba6d4 (diff) | |
download | Qt-f18e0e01468899731bc3777649d69fd6d0041012.zip Qt-f18e0e01468899731bc3777649d69fd6d0041012.tar.gz Qt-f18e0e01468899731bc3777649d69fd6d0041012.tar.bz2 |
Remove Q_ASSERT from QMutex autotest
Rather than aborting in debug mode and doing nothing in release mode
when the invariant is violated, count the failures and fail the test
gracefully.
Change-Id: Ie193460c478ddde540b6b15aafdce32f471b4b2b
Task-number: QTBUG-17582
Reviewed-by: Rohan McGovern
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qmutex/tst_qmutex.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/auto/qmutex/tst_qmutex.cpp b/tests/auto/qmutex/tst_qmutex.cpp index ea983cb..dc3ffa4 100644 --- a/tests/auto/qmutex/tst_qmutex.cpp +++ b/tests/auto/qmutex/tst_qmutex.cpp @@ -465,7 +465,12 @@ void tst_QMutex::tryLockRace() TryLockRaceThread::mutex.unlock(); } +// Variable that will be protected by the mutex. Volatile so that the +// the optimiser doesn't mess with it based on the increment-then-decrement +// usage pattern. static volatile int qtbug16115_trylock_counter; +// Counter for how many times the protected variable has an incorrect value. +static int qtbug16115_failure_count = 0; void tst_QMutex::qtbug16115_trylock() { @@ -476,8 +481,10 @@ void tst_QMutex::qtbug16115_trylock() void run() { for (int i = 0; i < 1000000; ++i) { if (mut.tryLock(0)) { - Q_ASSERT((++qtbug16115_trylock_counter) == 1); - Q_ASSERT((--qtbug16115_trylock_counter) == 0); + if ((++qtbug16115_trylock_counter) != 1) + ++qtbug16115_failure_count; + if ((--qtbug16115_trylock_counter) != 0) + ++qtbug16115_failure_count; mut.unlock(); } } @@ -493,13 +500,16 @@ void tst_QMutex::qtbug16115_trylock() for (int i = 0; i < 1000000; ++i) { mut.lock(); - Q_ASSERT((++qtbug16115_trylock_counter) == 1); - Q_ASSERT((--qtbug16115_trylock_counter) == 0); + if ((++qtbug16115_trylock_counter) != 1) + ++qtbug16115_failure_count; + if ((--qtbug16115_trylock_counter) != 0) + ++qtbug16115_failure_count; mut.unlock(); } t1.wait(); t2.wait(); t3.wait(); + QCOMPARE(qtbug16115_failure_count, 0); } QTEST_MAIN(tst_QMutex) |