diff options
Diffstat (limited to 'tests/auto/corelib/thread')
29 files changed, 227 insertions, 134 deletions
diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index e8c58a9fa5..72ae68f81a 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -479,34 +479,34 @@ void tst_QAtomicInt::testAndSet_data() QTest::addColumn<int>("value"); QTest::addColumn<int>("expected"); QTest::addColumn<int>("newval"); - QTest::addColumn<int>("result"); + QTest::addColumn<bool>("result"); // these should succeed - QTest::newRow("success0") << 0 << 0 << 0 << 1; - QTest::newRow("success1") << 0 << 0 << 1 << 1; - QTest::newRow("success2") << 0 << 0 << -1 << 1; - QTest::newRow("success3") << 1 << 1 << 0 << 1; - QTest::newRow("success4") << 1 << 1 << 1 << 1; - QTest::newRow("success5") << 1 << 1 << -1 << 1; - QTest::newRow("success6") << -1 << -1 << 0 << 1; - QTest::newRow("success7") << -1 << -1 << 1 << 1; - QTest::newRow("success8") << -1 << -1 << -1 << 1; - QTest::newRow("success9") << INT_MIN+1 << INT_MIN+1 << INT_MIN+1 << 1; - QTest::newRow("successA") << INT_MIN+1 << INT_MIN+1 << 1 << 1; - QTest::newRow("successB") << INT_MIN+1 << INT_MIN+1 << -1 << 1; - QTest::newRow("successC") << INT_MAX << INT_MAX << INT_MAX << 1; - QTest::newRow("successD") << INT_MAX << INT_MAX << 1 << 1; - QTest::newRow("successE") << INT_MAX << INT_MAX << -1 << 1; + QTest::newRow("success0") << 0 << 0 << 0 << true; + QTest::newRow("success1") << 0 << 0 << 1 << true; + QTest::newRow("success2") << 0 << 0 << -1 << true; + QTest::newRow("success3") << 1 << 1 << 0 << true; + QTest::newRow("success4") << 1 << 1 << 1 << true; + QTest::newRow("success5") << 1 << 1 << -1 << true; + QTest::newRow("success6") << -1 << -1 << 0 << true; + QTest::newRow("success7") << -1 << -1 << 1 << true; + QTest::newRow("success8") << -1 << -1 << -1 << true; + QTest::newRow("success9") << INT_MIN+1 << INT_MIN+1 << INT_MIN+1 << true; + QTest::newRow("successA") << INT_MIN+1 << INT_MIN+1 << 1 << true; + QTest::newRow("successB") << INT_MIN+1 << INT_MIN+1 << -1 << true; + QTest::newRow("successC") << INT_MAX << INT_MAX << INT_MAX << true; + QTest::newRow("successD") << INT_MAX << INT_MAX << 1 << true; + QTest::newRow("successE") << INT_MAX << INT_MAX << -1 << true; // these should fail - QTest::newRow("failure0") << 0 << 1 << ~0 << 0; - QTest::newRow("failure1") << 0 << -1 << ~0 << 0; - QTest::newRow("failure2") << 1 << 0 << ~0 << 0; - QTest::newRow("failure3") << -1 << 0 << ~0 << 0; - QTest::newRow("failure4") << 1 << -1 << ~0 << 0; - QTest::newRow("failure5") << -1 << 1 << ~0 << 0; - QTest::newRow("failure6") << INT_MIN+1 << INT_MAX << ~0 << 0; - QTest::newRow("failure7") << INT_MAX << INT_MIN+1 << ~0 << 0; + QTest::newRow("failure0") << 0 << 1 << ~0 << false; + QTest::newRow("failure1") << 0 << -1 << ~0 << false; + QTest::newRow("failure2") << 1 << 0 << ~0 << false; + QTest::newRow("failure3") << -1 << 0 << ~0 << false; + QTest::newRow("failure4") << 1 << -1 << ~0 << false; + QTest::newRow("failure5") << -1 << 1 << ~0 << false; + QTest::newRow("failure6") << INT_MIN+1 << INT_MAX << ~0 << false; + QTest::newRow("failure7") << INT_MAX << INT_MIN+1 << ~0 << false; } void tst_QAtomicInt::testAndSet() @@ -517,26 +517,26 @@ void tst_QAtomicInt::testAndSet() { QAtomicInt atomic = value; - QTEST(atomic.testAndSetRelaxed(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetRelaxed(expected, newval), "result"); } { QAtomicInt atomic = value; - QTEST(atomic.testAndSetAcquire(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetAcquire(expected, newval), "result"); } { QAtomicInt atomic = value; - QTEST(atomic.testAndSetRelease(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetRelease(expected, newval), "result"); } { QAtomicInt atomic = value; - QTEST(atomic.testAndSetOrdered(expected, newval) ? 1 : 0, "result"); + QTEST(atomic.testAndSetOrdered(expected, newval), "result"); } #ifdef Q_ATOMIC_INT32_IS_SUPPORTED - QFETCH(int, result); + QFETCH(bool, result); // the new implementation has the version that loads the current value { diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/char/char.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/char/char.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/char/char.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/char/char.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/char16_t/char16_t.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/char16_t/char16_t.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/char16_t/char16_t.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/char16_t/char16_t.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/char32_t/char32_t.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/char32_t/char32_t.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/char32_t/char32_t.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/char32_t/char32_t.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/int/int.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/int/int.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/int/int.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/int/int.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/long/long.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/long/long.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/long/long.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/long/long.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/qlonglong/qlonglong.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/qlonglong/qlonglong.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/qlonglong/qlonglong.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/qlonglong/qlonglong.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/qptrdiff/qptrdiff.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/qptrdiff/qptrdiff.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/qptrdiff/qptrdiff.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/qptrdiff/qptrdiff.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/quintptr/quintptr.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/quintptr/quintptr.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/quintptr/quintptr.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/quintptr/quintptr.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/qulonglong/qulonglong.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/qulonglong/qulonglong.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/qulonglong/qulonglong.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/qulonglong/qulonglong.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/schar/schar.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/schar/schar.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/schar/schar.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/schar/schar.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/short/short.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/short/short.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/short/short.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/short/short.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/uchar/uchar.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/uchar/uchar.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/uchar/uchar.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/uchar/uchar.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/uint/uint.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/uint/uint.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/uint/uint.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/uint/uint.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/ulong/ulong.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/ulong/ulong.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/ulong/ulong.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/ulong/ulong.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/ushort/ushort.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/ushort/ushort.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/ushort/ushort.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/ushort/ushort.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/cxx11/wchar_t/wchar_t.pro b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/wchar_t/wchar_t.pro index 64401f0229..64401f0229 100644 --- a/tests/auto/corelib/thread/qatomicinteger/cxx11/wchar_t/wchar_t.pro +++ b/tests/auto/corelib/thread/qatomicinteger/no-cxx11/wchar_t/wchar_t.pro diff --git a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri b/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri index d9ebe64d5b..e80e71f238 100644 --- a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri +++ b/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pri @@ -3,9 +3,9 @@ TYPE = $$basename(_PRO_FILE_PWD_) dn = $$dirname(_PRO_FILE_PWD_) FORCE = $$basename(dn) -equals(FORCE, cxx11) { - suffix = Cxx11_$$TYPE - DEFINES += QT_ATOMIC_FORCE_CXX11 +equals(FORCE, no-cxx11) { + suffix = NoCxx11_$$TYPE + DEFINES += QT_ATOMIC_FORCE_NO_CXX11 } else: equals(FORCE, gcc) { suffix = Gcc_$$TYPE DEFINES += QT_ATOMIC_FORCE_GCC diff --git a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro b/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro index 58e5b157bd..9d929e649e 100644 --- a/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro +++ b/tests/auto/corelib/thread/qatomicinteger/qatomicinteger.pro @@ -19,22 +19,22 @@ SUBDIRS=\ contains(QT_CONFIG, c++11)|msvc: SUBDIRS +=\ - cxx11/char \ - cxx11/char16_t \ - cxx11/char32_t \ - cxx11/int \ - cxx11/long \ - cxx11/qlonglong \ - cxx11/qptrdiff \ - cxx11/quintptr \ - cxx11/qulonglong \ - cxx11/schar \ - cxx11/short \ - cxx11/uchar \ - cxx11/uint \ - cxx11/ulong \ - cxx11/ushort \ - cxx11/wchar_t \ + no-cxx11/char \ + no-cxx11/char16_t \ + no-cxx11/char32_t \ + no-cxx11/int \ + no-cxx11/long \ + no-cxx11/qlonglong \ + no-cxx11/qptrdiff \ + no-cxx11/quintptr \ + no-cxx11/qulonglong \ + no-cxx11/schar \ + no-cxx11/short \ + no-cxx11/uchar \ + no-cxx11/uint \ + no-cxx11/ulong \ + no-cxx11/ushort \ + no-cxx11/wchar_t \ # The GCC-style atomics only support 32-bit and pointer-sized but add diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index 99978a9923..ad690a094b 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -648,7 +648,7 @@ void tst_QFuture::cancel() result.reportStarted(); f = result.future(); - QVERIFY(f.isCanceled() == false); + QVERIFY(!f.isCanceled()); result.reportCanceled(); QVERIFY(f.isCanceled()); result.reportFinished(); @@ -663,14 +663,14 @@ void tst_QFuture::cancel() QFutureInterface<void> result; QFuture<void> f; - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); result.reportStarted(); f = result.future(); - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); - QVERIFY(result.isCanceled() == false); + QVERIFY(!result.isCanceled()); f.cancel(); QVERIFY(result.isCanceled()); @@ -683,12 +683,12 @@ void tst_QFuture::cancel() QFutureInterface<void> result; QFuture<void> f; - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); result.reportStarted(); f = result.future(); - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); result.reportFinished(); @@ -805,12 +805,12 @@ void tst_QFuture::indexedResults() { QFutureInterface<QChar> Interface; QFuture<QChar> f; - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); Interface.reportStarted(); f = Interface.future(); - QVERIFY(f.isStarted() == true); + QVERIFY(f.isStarted()); QChar result; @@ -1126,14 +1126,14 @@ void tst_QFuture::iterators() QVERIFY(it.hasNext()); QCOMPARE(it.peekNext(), resultCount - 1); QCOMPARE(it.next(), resultCount - 1); - QVERIFY(it.hasNext() == false); + QVERIFY(!it.hasNext()); } { QFutureIterator<int> it(f); QVERIFY(it.hasNext()); it.toBack(); - QVERIFY(it.hasNext() == false); + QVERIFY(!it.hasNext()); it.toFront(); QVERIFY(it.hasNext()); } @@ -1192,15 +1192,15 @@ void tst_QFuture::pause() Interface.reportStarted(); QFuture<void> f = Interface.future(); - QVERIFY(Interface.isPaused() == false); + QVERIFY(!Interface.isPaused()); f.pause(); - QVERIFY(Interface.isPaused() == true); + QVERIFY(Interface.isPaused()); f.resume(); - QVERIFY(Interface.isPaused() == false); + QVERIFY(!Interface.isPaused()); f.togglePaused(); - QVERIFY(Interface.isPaused() == true); + QVERIFY(Interface.isPaused()); f.togglePaused(); - QVERIFY(Interface.isPaused() == false); + QVERIFY(!Interface.isPaused()); Interface.reportFinished(); } @@ -1228,13 +1228,13 @@ void tst_QFuture::throttling() i.reportStarted(); QFuture<void> f = i.future(); - QVERIFY(i.isThrottled() == false); + QVERIFY(!i.isThrottled()); i.setThrottled(true); QVERIFY(i.isThrottled()); i.setThrottled(false); - QVERIFY(i.isThrottled() == false); + QVERIFY(!i.isThrottled()); i.setThrottled(true); QVERIFY(i.isThrottled()); diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index 8831345ad7..c4fad93e4b 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -68,6 +68,7 @@ private slots: void incrementalFilterResults(); void qfutureSynchronizer(); void warnRace(); + void matchFlags(); }; void sleeper() @@ -312,10 +313,16 @@ void tst_QFutureWatcher::futureSignals() // (QSignalSpy does not trigger it.) connect(&f, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int))); a.reportStarted(); - f.setFuture(a.future()); QSignalSpy progressSpy(&f, &QFutureWatcher<void>::progressValueChanged); + QSignalSpy finishedSpy(&f, &QFutureWatcher<void>::finished); + QSignalSpy resultReadySpy(&f, &QFutureWatcher<void>::resultReadyAt); + QVERIFY(progressSpy.isValid()); + QVERIFY(finishedSpy.isValid()); + QVERIFY(resultReadySpy.isValid()); + f.setFuture(a.future()); + const int progress = 1; a.setProgressValue(progress); QTest::qWait(10); @@ -323,12 +330,6 @@ void tst_QFutureWatcher::futureSignals() QCOMPARE(progressSpy.takeFirst().at(0).toInt(), 0); QCOMPARE(progressSpy.takeFirst().at(0).toInt(), 1); - QSignalSpy finishedSpy(&f, &QFutureWatcher<void>::finished); - QSignalSpy resultReadySpy(&f, &QFutureWatcher<void>::resultReadyAt); - - QVERIFY(finishedSpy.isValid()); - QVERIFY(resultReadySpy.isValid()); - const int result = 10; a.reportResult(&result); QTest::qWait(10); @@ -426,16 +427,15 @@ void tst_QFutureWatcher::disconnectRunningFuture() QFuture<int> f = a.future(); QFutureWatcher<int> *watcher = new QFutureWatcher<int>(); - watcher->setFuture(f); - - SignalSlotObject object; - connect(watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int))); - QSignalSpy finishedSpy(watcher, &QFutureWatcher<int>::finished); QSignalSpy resultReadySpy(watcher, &QFutureWatcher<int>::resultReadyAt); QVERIFY(finishedSpy.isValid()); QVERIFY(resultReadySpy.isValid()); + watcher->setFuture(f); + + SignalSlotObject object; + connect(watcher, SIGNAL(resultReadyAt(int)), &object, SLOT(resultReadyAt(int))); const int result = 10; a.reportResult(&result); @@ -677,11 +677,6 @@ void tst_QFutureWatcher::pauseEvents() QFutureInterface<int> iface; iface.reportStarted(); - QFuture<int> a = iface.future(); - - int value = 0; - iface.reportFinished(&value); - QFutureWatcher<int> watcher; SignalSlotObject object; @@ -689,14 +684,17 @@ void tst_QFutureWatcher::pauseEvents() QSignalSpy resultReadySpy(&watcher, &QFutureWatcher<int>::resultReadyAt); QVERIFY(resultReadySpy.isValid()); - watcher.setFuture(a); + watcher.setFuture(iface.future()); watcher.pause(); + int value = 0; + iface.reportFinished(&value); + QTest::qWait(10); QCOMPARE(resultReadySpy.count(), 0); watcher.resume(); - QTest::qWait(10); + QTRY_VERIFY2(!resultReadySpy.isEmpty(), "Result didn't arrive"); QCOMPARE(resultReadySpy.count(), 1); } { @@ -705,9 +703,6 @@ void tst_QFutureWatcher::pauseEvents() QFuture<int> a = iface.future(); - int value = 0; - iface.reportFinished(&value); - QFutureWatcher<int> watcher; SignalSlotObject object; @@ -718,6 +713,9 @@ void tst_QFutureWatcher::pauseEvents() watcher.setFuture(a); a.pause(); + int value = 0; + iface.reportFinished(&value); + QFuture<int> b; watcher.setFuture(b); // If we watch b instead, resuming a a.resume(); // should give us no results. @@ -743,7 +741,7 @@ void tst_QFutureWatcher::finishedState() iface.reportFinished(); QVERIFY(future.isFinished()); - QVERIFY(watcher.isFinished() == false); + QVERIFY(!watcher.isFinished()); QTest::qWait(10); QVERIFY(watcher.isFinished()); @@ -761,18 +759,18 @@ void tst_QFutureWatcher::throttling() QFutureWatcher<int> watcher; watcher.setFuture(future); - QVERIFY(iface.isThrottled() == false); + QVERIFY(!iface.isThrottled()); for (int i = 0; i < 1000; ++i) { int result = 0; iface.reportResult(result); } - QVERIFY(iface.isThrottled() == true); + QVERIFY(iface.isThrottled()); QTest::qWait(100); // process events. - QVERIFY(iface.isThrottled() == false); + QVERIFY(!iface.isThrottled()); iface.reportFinished(); } @@ -930,5 +928,17 @@ void tst_QFutureWatcher::warnRace() future.waitForFinished(); } +void tst_QFutureWatcher::matchFlags() +{ + /* Regression test: expect a default watcher to be in the same state as a + * default future. */ + QFutureWatcher<int> watcher; + QFuture<int> future; + QCOMPARE(watcher.isStarted(), future.isStarted()); + QCOMPARE(watcher.isCanceled(), future.isCanceled()); + QCOMPARE(watcher.isFinished(), future.isFinished()); +} + + QTEST_MAIN(tst_QFutureWatcher) #include "tst_qfuturewatcher.moc" diff --git a/tests/auto/corelib/thread/qsemaphore/BLACKLIST b/tests/auto/corelib/thread/qsemaphore/BLACKLIST new file mode 100644 index 0000000000..9f6f6e3ba6 --- /dev/null +++ b/tests/auto/corelib/thread/qsemaphore/BLACKLIST @@ -0,0 +1,3 @@ +# Times out randomly on linux, windows, osx +[tryAcquireWithTimeout] +* diff --git a/tests/auto/corelib/thread/qthread/BLACKLIST b/tests/auto/corelib/thread/qthread/BLACKLIST new file mode 100644 index 0000000000..d75249454f --- /dev/null +++ b/tests/auto/corelib/thread/qthread/BLACKLIST @@ -0,0 +1,2 @@ +[wait3_slowDestructor] +windows diff --git a/tests/auto/corelib/thread/qthreadpool/BLACKLIST b/tests/auto/corelib/thread/qthreadpool/BLACKLIST new file mode 100644 index 0000000000..1c392ce96c --- /dev/null +++ b/tests/auto/corelib/thread/qthreadpool/BLACKLIST @@ -0,0 +1,2 @@ +[expiryTimeoutRace] +osx diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index c9fdb4b718..c465a07487 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -821,7 +821,7 @@ void tst_QThreadPool::tryStartCount() ++count; QCOMPARE(count, QThread::idealThreadCount()); - QTest::qWait(100); + QTRY_COMPARE(threadPool.activeThreadCount(), 0); } } diff --git a/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro b/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro index 2fa973d2f7..e81038a4be 100644 --- a/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro +++ b/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro @@ -1,5 +1,7 @@ TEMPLATE = subdirs SUBDIRS = \ - crashonexit \ test + +!winrt: SUBDIRS += crashonexit + CONFIG += ordered parallel_test diff --git a/tests/auto/corelib/thread/qthreadstorage/test/test.pro b/tests/auto/corelib/thread/qthreadstorage/test/test.pro index 8b7caf1e24..d97d474e51 100644 --- a/tests/auto/corelib/thread/qthreadstorage/test/test.pro +++ b/tests/auto/corelib/thread/qthreadstorage/test/test.pro @@ -5,6 +5,6 @@ CONFIG += console QT = core testlib SOURCES = ../tst_qthreadstorage.cpp -TEST_HELPER_INSTALLS = ../crashonexit/crashonexit +!winrt: TEST_HELPER_INSTALLS = ../crashonexit/crashonexit DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp index 5e9b7370b9..ed7b446172 100644 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp @@ -240,7 +240,7 @@ void tst_QThreadStorage::adoptedThreads() QTestEventLoop::instance().enterLoop(2); QVERIFY(!QTestEventLoop::instance().timeout()); - QCOMPARE(Pointer::count, c); + QTRY_COMPARE(Pointer::count, c); } QBasicAtomicInt cleanupOrder = Q_BASIC_ATOMIC_INITIALIZER(0); diff --git a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp index dea305e3e1..df52aa4949 100644 --- a/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ b/tests/auto/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp @@ -33,6 +33,7 @@ #include <QtTest/QtTest> +#include <qatomic.h> #include <qcoreapplication.h> #include <qmutex.h> #include <qthread.h> @@ -54,7 +55,25 @@ private slots: static const int iterations = 4; static const int ThreadCount = 4; -class wait_QMutex_Thread_1 : public QThread +// Terminate thread in destructor for threads instantiated on the stack +class TerminatingThread : public QThread +{ +public: + explicit TerminatingThread() + { + setTerminationEnabled(true); + } + + ~TerminatingThread() + { + if (isRunning()) { + qWarning() << "forcibly terminating " << objectName(); + terminate(); + } + } +}; + +class wait_QMutex_Thread_1 : public TerminatingThread { public: QMutex mutex; @@ -72,7 +91,7 @@ public: } }; -class wait_QMutex_Thread_2 : public QThread +class wait_QMutex_Thread_2 : public TerminatingThread { public: QWaitCondition started; @@ -93,7 +112,7 @@ public: } }; -class wait_QReadWriteLock_Thread_1 : public QThread +class wait_QReadWriteLock_Thread_1 : public TerminatingThread { public: QReadWriteLock readWriteLock; @@ -111,7 +130,7 @@ public: } }; -class wait_QReadWriteLock_Thread_2 : public QThread +class wait_QReadWriteLock_Thread_2 : public TerminatingThread { public: QWaitCondition started; @@ -155,7 +174,11 @@ void tst_QWaitCondition::wait_QMutex() // test multiple threads waiting on separate wait conditions wait_QMutex_Thread_1 thread[ThreadCount]; + const QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_mutex_") + + QString::number(i) + QLatin1Char('_'); + for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); thread[x].mutex.lock(); thread[x].start(); // wait for thread to start @@ -185,8 +208,12 @@ void tst_QWaitCondition::wait_QMutex() QWaitCondition cond1, cond2; wait_QMutex_Thread_2 thread[ThreadCount]; + const QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_mutex_") + + QString::number(i) + QLatin1Char('_'); + mutex.lock(); for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); thread[x].mutex = &mutex; thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2; thread[x].start(); @@ -289,7 +316,10 @@ void tst_QWaitCondition::wait_QReadWriteLock() // test multiple threads waiting on separate wait conditions wait_QReadWriteLock_Thread_1 thread[ThreadCount]; + const QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_lockforread_"); + for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); thread[x].readWriteLock.lockForRead(); thread[x].start(); // wait for thread to start @@ -319,8 +349,11 @@ void tst_QWaitCondition::wait_QReadWriteLock() QWaitCondition cond1, cond2; wait_QReadWriteLock_Thread_2 thread[ThreadCount]; + const QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_lockforwrite_"); + readWriteLock.lockForWrite(); for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); thread[x].readWriteLock = &readWriteLock; thread[x].cond = (x < ThreadCount / 2) ? &cond1 : &cond2; thread[x].start(); @@ -346,11 +379,17 @@ void tst_QWaitCondition::wait_QReadWriteLock() } } -class wake_Thread : public QThread +class WakeThreadBase : public TerminatingThread { public: - static int count; + QAtomicInt *count; + WakeThreadBase() : count(Q_NULLPTR) {} +}; + +class wake_Thread : public WakeThreadBase +{ +public: QWaitCondition started; QWaitCondition dummy; @@ -366,24 +405,23 @@ public: void run() { + Q_ASSERT(count); + Q_ASSERT(mutex); + Q_ASSERT(cond); mutex->lock(); - ++count; + ++*count; dummy.wakeOne(); // this wakeup should be lost started.wakeOne(); dummy.wakeAll(); // this one too cond->wait(mutex); - --count; + --*count; mutex->unlock(); } }; -int wake_Thread::count = 0; - -class wake_Thread_2 : public QThread +class wake_Thread_2 : public WakeThreadBase { public: - static int count; - QWaitCondition started; QWaitCondition dummy; @@ -399,22 +437,27 @@ public: void run() { + Q_ASSERT(count); + Q_ASSERT(readWriteLock); + Q_ASSERT(cond); readWriteLock->lockForWrite(); - ++count; + ++*count; dummy.wakeOne(); // this wakeup should be lost started.wakeOne(); dummy.wakeAll(); // this one too cond->wait(readWriteLock); - --count; + --*count; readWriteLock->unlock(); } }; -int wake_Thread_2::count = 0; - void tst_QWaitCondition::wakeOne() { + static const int firstWaitInterval = 1000; + static const int waitInterval = 30; + int x; + QAtomicInt count; // wake up threads, one at a time for (int i = 0; i < iterations; ++i) { QMutex mutex; @@ -424,8 +467,13 @@ void tst_QWaitCondition::wakeOne() wake_Thread thread[ThreadCount]; bool thread_exited[ThreadCount]; + QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_mutex_") + + QString::number(i) + QLatin1Char('_'); + mutex.lock(); for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); + thread[x].count = &count; thread[x].mutex = &mutex; thread[x].cond = &cond; thread_exited[x] = false; @@ -438,7 +486,7 @@ void tst_QWaitCondition::wakeOne() } mutex.unlock(); - QCOMPARE(wake_Thread::count, ThreadCount); + QCOMPARE(count.load(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; ++x) { @@ -452,24 +500,29 @@ void tst_QWaitCondition::wakeOne() for (int y = 0; y < ThreadCount; ++y) { if (thread_exited[y]) continue; - if (thread[y].wait(exited > 0 ? 10 : 1000)) { + if (thread[y].wait(exited > 0 ? waitInterval : firstWaitInterval)) { thread_exited[y] = true; ++exited; } } QCOMPARE(exited, 1); - QCOMPARE(wake_Thread::count, ThreadCount - (x + 1)); + QCOMPARE(count.load(), ThreadCount - (x + 1)); } - QCOMPARE(wake_Thread::count, 0); + QCOMPARE(count.load(), 0); // QReadWriteLock QReadWriteLock readWriteLock; wake_Thread_2 rwthread[ThreadCount]; + prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_readwritelock_") + + QString::number(i) + QLatin1Char('_'); + readWriteLock.lockForWrite(); for (x = 0; x < ThreadCount; ++x) { + rwthread[x].setObjectName(prefix + QString::number(x)); + rwthread[x].count = &count; rwthread[x].readWriteLock = &readWriteLock; rwthread[x].cond = &cond; thread_exited[x] = false; @@ -482,7 +535,7 @@ void tst_QWaitCondition::wakeOne() } readWriteLock.unlock(); - QCOMPARE(wake_Thread_2::count, ThreadCount); + QCOMPARE(count.load(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; ++x) { @@ -496,17 +549,17 @@ void tst_QWaitCondition::wakeOne() for (int y = 0; y < ThreadCount; ++y) { if (thread_exited[y]) continue; - if (rwthread[y].wait(exited > 0 ? 10 : 1000)) { + if (rwthread[y].wait(exited > 0 ? waitInterval : firstWaitInterval)) { thread_exited[y] = true; ++exited; } } QCOMPARE(exited, 1); - QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 1)); + QCOMPARE(count.load(), ThreadCount - (x + 1)); } - QCOMPARE(wake_Thread_2::count, 0); + QCOMPARE(count.load(), 0); } // wake up threads, two at a time @@ -518,8 +571,13 @@ void tst_QWaitCondition::wakeOne() wake_Thread thread[ThreadCount]; bool thread_exited[ThreadCount]; + QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_mutex2_") + + QString::number(i) + QLatin1Char('_'); + mutex.lock(); for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); + thread[x].count = &count; thread[x].mutex = &mutex; thread[x].cond = &cond; thread_exited[x] = false; @@ -532,7 +590,7 @@ void tst_QWaitCondition::wakeOne() } mutex.unlock(); - QCOMPARE(wake_Thread::count, ThreadCount); + QCOMPARE(count.load(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; x += 2) { @@ -548,24 +606,29 @@ void tst_QWaitCondition::wakeOne() for (int y = 0; y < ThreadCount; ++y) { if (thread_exited[y]) continue; - if (thread[y].wait(exited > 0 ? 10 : 1000)) { + if (thread[y].wait(exited > 0 ? waitInterval : firstWaitInterval)) { thread_exited[y] = true; ++exited; } } QCOMPARE(exited, 2); - QCOMPARE(wake_Thread::count, ThreadCount - (x + 2)); + QCOMPARE(count.load(), ThreadCount - (x + 2)); } - QCOMPARE(wake_Thread::count, 0); + QCOMPARE(count.load(), 0); // QReadWriteLock QReadWriteLock readWriteLock; wake_Thread_2 rwthread[ThreadCount]; + prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_readwritelock_") + + QString::number(i) + QLatin1Char('_'); + readWriteLock.lockForWrite(); for (x = 0; x < ThreadCount; ++x) { + rwthread[x].setObjectName(prefix + QString::number(x)); + rwthread[x].count = &count; rwthread[x].readWriteLock = &readWriteLock; rwthread[x].cond = &cond; thread_exited[x] = false; @@ -578,7 +641,7 @@ void tst_QWaitCondition::wakeOne() } readWriteLock.unlock(); - QCOMPARE(wake_Thread_2::count, ThreadCount); + QCOMPARE(count.load(), ThreadCount); // wake up threads one at a time for (x = 0; x < ThreadCount; x += 2) { @@ -594,23 +657,24 @@ void tst_QWaitCondition::wakeOne() for (int y = 0; y < ThreadCount; ++y) { if (thread_exited[y]) continue; - if (rwthread[y].wait(exited > 0 ? 10 : 1000)) { + if (rwthread[y].wait(exited > 0 ? waitInterval : firstWaitInterval)) { thread_exited[y] = true; ++exited; } } QCOMPARE(exited, 2); - QCOMPARE(wake_Thread_2::count, ThreadCount - (x + 2)); + QCOMPARE(count.load(), ThreadCount - (x + 2)); } - QCOMPARE(wake_Thread_2::count, 0); + QCOMPARE(count.load(), 0); } } void tst_QWaitCondition::wakeAll() { int x; + QAtomicInt count; for (int i = 0; i < iterations; ++i) { QMutex mutex; QWaitCondition cond; @@ -618,8 +682,13 @@ void tst_QWaitCondition::wakeAll() // QMutex wake_Thread thread[ThreadCount]; + QString prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_mutex_") + + QString::number(i) + QLatin1Char('_'); + mutex.lock(); for (x = 0; x < ThreadCount; ++x) { + thread[x].setObjectName(prefix + QString::number(x)); + thread[x].count = &count; thread[x].mutex = &mutex; thread[x].cond = &cond; thread[x].start(); @@ -628,7 +697,7 @@ void tst_QWaitCondition::wakeAll() } mutex.unlock(); - QCOMPARE(wake_Thread::count, ThreadCount); + QCOMPARE(count.load(), ThreadCount); // wake up all threads at once mutex.lock(); @@ -643,14 +712,19 @@ void tst_QWaitCondition::wakeAll() } QCOMPARE(exited, ThreadCount); - QCOMPARE(wake_Thread::count, 0); + QCOMPARE(count.load(), 0); // QReadWriteLock QReadWriteLock readWriteLock; wake_Thread_2 rwthread[ThreadCount]; + prefix = QLatin1String(QTest::currentTestFunction()) + QLatin1String("_readwritelock_") + + QString::number(i) + QLatin1Char('_'); + readWriteLock.lockForWrite(); for (x = 0; x < ThreadCount; ++x) { + rwthread[x].setObjectName(prefix + QString::number(x)); + rwthread[x].count = &count; rwthread[x].readWriteLock = &readWriteLock; rwthread[x].cond = &cond; rwthread[x].start(); @@ -659,7 +733,7 @@ void tst_QWaitCondition::wakeAll() } readWriteLock.unlock(); - QCOMPARE(wake_Thread_2::count, ThreadCount); + QCOMPARE(count.load(), ThreadCount); // wake up all threads at once readWriteLock.lockForWrite(); @@ -674,11 +748,11 @@ void tst_QWaitCondition::wakeAll() } QCOMPARE(exited, ThreadCount); - QCOMPARE(wake_Thread_2::count, 0); + QCOMPARE(count.load(), 0); } } -class wait_RaceConditionThread : public QThread +class wait_RaceConditionThread : public TerminatingThread { public: wait_RaceConditionThread(QMutex *mutex, QWaitCondition *startup, QWaitCondition *waitCondition, @@ -707,7 +781,7 @@ public: } }; -class wait_RaceConditionThread_2 : public QThread +class wait_RaceConditionThread_2 : public TerminatingThread { public: wait_RaceConditionThread_2(QReadWriteLock *readWriteLock, |