summaryrefslogtreecommitdiffstats
path: root/tests/auto/qwaitcondition/tst_qwaitcondition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qwaitcondition/tst_qwaitcondition.cpp')
-rw-r--r--tests/auto/qwaitcondition/tst_qwaitcondition.cpp133
1 files changed, 72 insertions, 61 deletions
diff --git a/tests/auto/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/qwaitcondition/tst_qwaitcondition.cpp
index 1e0136f..ce3ac1e 100644
--- a/tests/auto/qwaitcondition/tst_qwaitcondition.cpp
+++ b/tests/auto/qwaitcondition/tst_qwaitcondition.cpp
@@ -47,6 +47,12 @@
#include <qthread.h>
#include <qwaitcondition.h>
+#if defined(Q_OS_SYMBIAN)
+// Symbian Open C has a bug that causes very short waits to fail sometimes
+#define COND_WAIT_TIME 50
+#else
+#define COND_WAIT_TIME 1
+#endif
//TESTED_CLASS=
@@ -283,8 +289,8 @@ void tst_QWaitCondition::wait_QReadWriteLock()
int x;
for (int i = 0; i < iterations; ++i) {
{
- QReadWriteLock readWriteLock;
- QWaitCondition waitCondition;
+ QReadWriteLock readWriteLock;
+ QWaitCondition waitCondition;
readWriteLock.lockForRead();
@@ -297,8 +303,8 @@ void tst_QWaitCondition::wait_QReadWriteLock()
readWriteLock.unlock();
}
- {
- QReadWriteLock readWriteLock;
+ {
+ QReadWriteLock readWriteLock;
QWaitCondition waitCondition;
readWriteLock.lockForWrite();
@@ -320,7 +326,12 @@ void tst_QWaitCondition::wait_QReadWriteLock()
thread[x].readWriteLock.lockForRead();
thread[x].start();
// wait for thread to start
+#if defined(Q_OS_SYMBIAN) && defined(Q_CC_WINSCW)
+ // Symbian emulator startup simultaneously with this thread causes additional delay
+ QVERIFY(thread[x].cond.wait(&thread[x].readWriteLock, 10000));
+#else
QVERIFY(thread[x].cond.wait(&thread[x].readWriteLock, 1000));
+#endif
thread[x].readWriteLock.unlock();
}
@@ -448,7 +459,7 @@ void tst_QWaitCondition::wakeOne()
QMutex mutex;
QWaitCondition cond;
- // QMutex
+ // QMutex
wake_Thread thread[ThreadCount];
bool thread_exited[ThreadCount];
@@ -460,9 +471,9 @@ void tst_QWaitCondition::wakeOne()
thread[x].start();
// wait for thread to start
QVERIFY(thread[x].started.wait(&mutex, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
}
mutex.unlock();
@@ -472,18 +483,18 @@ void tst_QWaitCondition::wakeOne()
for (x = 0; x < ThreadCount; ++x) {
mutex.lock();
cond.wakeOne();
- QVERIFY(!cond.wait(&mutex, 1));
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
+ QVERIFY(!thread[x].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 ? 1 : 1000)) {
- thread_exited[y] = TRUE;
- ++exited;
- }
+ if (thread_exited[y])
+ continue;
+ if (thread[y].wait(exited > 0 ? 1 : 1000)) {
+ thread_exited[y] = TRUE;
+ ++exited;
+ }
}
QCOMPARE(exited, 1);
@@ -492,11 +503,11 @@ void tst_QWaitCondition::wakeOne()
QCOMPARE(wake_Thread::count, 0);
- // QReadWriteLock
- QReadWriteLock readWriteLock;
- wake_Thread_2 rwthread[ThreadCount];
+ // QReadWriteLock
+ QReadWriteLock readWriteLock;
+ wake_Thread_2 rwthread[ThreadCount];
- readWriteLock.lockForWrite();
+ readWriteLock.lockForWrite();
for (x = 0; x < ThreadCount; ++x) {
rwthread[x].readWriteLock = &readWriteLock;
rwthread[x].cond = &cond;
@@ -504,9 +515,9 @@ void tst_QWaitCondition::wakeOne()
rwthread[x].start();
// wait for thread to start
QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
}
readWriteLock.unlock();
@@ -516,18 +527,18 @@ void tst_QWaitCondition::wakeOne()
for (x = 0; x < ThreadCount; ++x) {
readWriteLock.lockForWrite();
cond.wakeOne();
- QVERIFY(!cond.wait(&readWriteLock, 1));
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
readWriteLock.unlock();
int exited = 0;
for (int y = 0; y < ThreadCount; ++y) {
- if (thread_exited[y])
- continue;
- if (rwthread[y].wait(exited > 0 ? 1 : 1000)) {
- thread_exited[y] = TRUE;
- ++exited;
- }
+ if (thread_exited[y])
+ continue;
+ if (rwthread[y].wait(exited > 0 ? 1 : 1000)) {
+ thread_exited[y] = TRUE;
+ ++exited;
+ }
}
QCOMPARE(exited, 1);
@@ -554,9 +565,9 @@ void tst_QWaitCondition::wakeOne()
thread[x].start();
// wait for thread to start
QVERIFY(thread[x].started.wait(&mutex, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
}
mutex.unlock();
@@ -567,19 +578,19 @@ void tst_QWaitCondition::wakeOne()
mutex.lock();
cond.wakeOne();
cond.wakeOne();
- QVERIFY(!cond.wait(&mutex, 1));
- QVERIFY(!thread[x].dummy.wait(&mutex, 1));
- QVERIFY(!thread[x + 1].dummy.wait(&mutex, 1));
+ QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
+ QVERIFY(!thread[x].dummy.wait(&mutex, 1));
+ 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 ? 1 : 1000)) {
- thread_exited[y] = TRUE;
- ++exited;
- }
+ if (thread_exited[y])
+ continue;
+ if (thread[y].wait(exited > 0 ? 1 : 1000)) {
+ thread_exited[y] = TRUE;
+ ++exited;
+ }
}
QCOMPARE(exited, 2);
@@ -600,9 +611,9 @@ void tst_QWaitCondition::wakeOne()
rwthread[x].start();
// wait for thread to start
QVERIFY(rwthread[x].started.wait(&readWriteLock, 1000));
- // make sure wakeups are not queued... if nothing is
- // waiting at the time of the wakeup, nothing happens
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ // make sure wakeups are not queued... if nothing is
+ // waiting at the time of the wakeup, nothing happens
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
}
readWriteLock.unlock();
@@ -613,19 +624,19 @@ void tst_QWaitCondition::wakeOne()
readWriteLock.lockForWrite();
cond.wakeOne();
cond.wakeOne();
- QVERIFY(!cond.wait(&readWriteLock, 1));
- QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
- QVERIFY(!rwthread[x + 1].dummy.wait(&readWriteLock, 1));
+ QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
+ QVERIFY(!rwthread[x].dummy.wait(&readWriteLock, 1));
+ QVERIFY(!rwthread[x + 1].dummy.wait(&readWriteLock, 1));
readWriteLock.unlock();
int exited = 0;
for (int y = 0; y < ThreadCount; ++y) {
- if (thread_exited[y])
- continue;
- if (rwthread[y].wait(exited > 0 ? 1 : 1000)) {
- thread_exited[y] = TRUE;
- ++exited;
- }
+ if (thread_exited[y])
+ continue;
+ if (rwthread[y].wait(exited > 0 ? 1 : 1000)) {
+ thread_exited[y] = TRUE;
+ ++exited;
+ }
}
QCOMPARE(exited, 2);
@@ -643,7 +654,7 @@ void tst_QWaitCondition::wakeAll()
QMutex mutex;
QWaitCondition cond;
- // QMutex
+ // QMutex
wake_Thread thread[ThreadCount];
mutex.lock();
@@ -661,7 +672,7 @@ void tst_QWaitCondition::wakeAll()
// wake up all threads at once
mutex.lock();
cond.wakeAll();
- QVERIFY(!cond.wait(&mutex, 1));
+ QVERIFY(!cond.wait(&mutex, COND_WAIT_TIME));
mutex.unlock();
int exited = 0;
@@ -673,8 +684,8 @@ void tst_QWaitCondition::wakeAll()
QCOMPARE(exited, ThreadCount);
QCOMPARE(wake_Thread::count, 0);
- // QReadWriteLock
- QReadWriteLock readWriteLock;
+ // QReadWriteLock
+ QReadWriteLock readWriteLock;
wake_Thread_2 rwthread[ThreadCount];
readWriteLock.lockForWrite();
@@ -692,10 +703,10 @@ void tst_QWaitCondition::wakeAll()
// wake up all threads at once
readWriteLock.lockForWrite();
cond.wakeAll();
- QVERIFY(!cond.wait(&readWriteLock, 1));
+ QVERIFY(!cond.wait(&readWriteLock, COND_WAIT_TIME));
readWriteLock.unlock();
- exited = 0;
+ exited = 0;
for (x = 0; x < ThreadCount; ++x) {
if (rwthread[x].wait(1000))
++exited;