diff options
author | Jason McDonald <jason.mcdonald@nokia.com> | 2011-11-24 17:34:51 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-25 07:56:16 +0100 |
commit | e08410ab8db3d7cabf4ef2fc4de40bb6da6d6fef (patch) | |
tree | 9d6e154364039ab6cbc7a789ef33b7e0ce038e51 /tests/auto/corelib/thread/qmutex | |
parent | 489a39aacc102e46a5b3fffd5839ed694bb7214f (diff) |
Cleanup corelib autotests
Bug trackers come and go, so using bug identifiers in function and test
case names will ensure that those names eventually become meaningless.
It is better to choose a meaningful name and provide explanatory
comments where appropriate.
Change-Id: I67c27782ef21b5d4eaab4854079a043c8ef6957b
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests/auto/corelib/thread/qmutex')
-rw-r--r-- | tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 82b0c98522..d70dea5e57 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -59,7 +59,7 @@ private slots: void lock_unlock_locked_tryLock(); void stressTest(); void tryLockRace(); - void qtbug16115_trylock(); + void tryLockDeadlock(); void moreStress(); }; @@ -510,14 +510,17 @@ void tst_QMutex::tryLockRace() TryLockRaceThread::mutex.unlock(); } +// The following is a regression test for QTBUG-16115, where QMutex could +// deadlock after calling tryLock repeatedly. + // 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; +static volatile int tryLockDeadlockCounter; // Counter for how many times the protected variable has an incorrect value. -static int qtbug16115_failure_count = 0; +static int tryLockDeadlockFailureCount = 0; -void tst_QMutex::qtbug16115_trylock() +void tst_QMutex::tryLockDeadlock() { //Used to deadlock on unix struct TrylockThread : QThread { @@ -526,10 +529,10 @@ void tst_QMutex::qtbug16115_trylock() void run() { for (int i = 0; i < 100000; ++i) { if (mut.tryLock(0)) { - if ((++qtbug16115_trylock_counter) != 1) - ++qtbug16115_failure_count; - if ((--qtbug16115_trylock_counter) != 0) - ++qtbug16115_failure_count; + if ((++tryLockDeadlockCounter) != 1) + ++tryLockDeadlockFailureCount; + if ((--tryLockDeadlockCounter) != 0) + ++tryLockDeadlockFailureCount; mut.unlock(); } } @@ -545,16 +548,16 @@ void tst_QMutex::qtbug16115_trylock() for (int i = 0; i < 100000; ++i) { mut.lock(); - if ((++qtbug16115_trylock_counter) != 1) - ++qtbug16115_failure_count; - if ((--qtbug16115_trylock_counter) != 0) - ++qtbug16115_failure_count; + if ((++tryLockDeadlockCounter) != 1) + ++tryLockDeadlockFailureCount; + if ((--tryLockDeadlockCounter) != 0) + ++tryLockDeadlockFailureCount; mut.unlock(); } t1.wait(); t2.wait(); t3.wait(); - QCOMPARE(qtbug16115_failure_count, 0); + QCOMPARE(tryLockDeadlockFailureCount, 0); } |