diff options
Diffstat (limited to 'tests/auto/concurrent')
6 files changed, 60 insertions, 74 deletions
diff --git a/tests/auto/concurrent/qtconcurrentfilter/qtconcurrentfilter.pro b/tests/auto/concurrent/qtconcurrentfilter/qtconcurrentfilter.pro index f3684faa61..15345d40db 100644 --- a/tests/auto/concurrent/qtconcurrentfilter/qtconcurrentfilter.pro +++ b/tests/auto/concurrent/qtconcurrentfilter/qtconcurrentfilter.pro @@ -3,3 +3,4 @@ TARGET = tst_qtconcurrentfilter QT = core testlib concurrent SOURCES = tst_qtconcurrentfilter.cpp DEFINES += QT_STRICT_ITERATORS +DEFINES -= QT_NO_LINKED_LIST diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp index 2e698e6615..3c77b1ba0b 100644 --- a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp +++ b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp @@ -88,7 +88,7 @@ QAtomicInt iterations; class PrintFor : public IterateKernel<TestIterator, void> { public: - PrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); } + PrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); } bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { iterations.fetchAndAddRelaxed(end - begin); @@ -107,7 +107,7 @@ public: class SleepPrintFor : public IterateKernel<TestIterator, void> { public: - SleepPrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); } + SleepPrintFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); } inline bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { QTest::qSleep(200); @@ -127,7 +127,7 @@ public: void tst_QtConcurrentIterateKernel::instantiate() { startThreadEngine(new PrintFor(0, 40)).startBlocking(); - QCOMPARE(iterations.load(), 40); + QCOMPARE(iterations.loadRelaxed(), 40); } void tst_QtConcurrentIterateKernel::cancel() @@ -138,8 +138,8 @@ void tst_QtConcurrentIterateKernel::cancel() f.waitForFinished(); QVERIFY(f.isCanceled()); // the threads might run one iteration each before they are canceled. - QVERIFY2(iterations.load() <= QThread::idealThreadCount(), - (QByteArray::number(iterations.load()) + ' ' + QByteArray::number(QThread::idealThreadCount()))); + QVERIFY2(iterations.loadRelaxed() <= QThread::idealThreadCount(), + (QByteArray::number(iterations.loadRelaxed()) + ' ' + QByteArray::number(QThread::idealThreadCount()))); } } @@ -147,7 +147,7 @@ QAtomicInt counter; class CountFor : public IterateKernel<TestIterator, void> { public: - CountFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); } + CountFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); } inline bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { counter.fetchAndAddRelaxed(end - begin); @@ -164,10 +164,10 @@ void tst_QtConcurrentIterateKernel::stresstest() const int iterations = 1000; const int times = 50; for (int i = 0; i < times; ++i) { - counter.store(0); + counter.storeRelaxed(0); CountFor f(0, iterations); f.startBlocking(); - QCOMPARE(counter.load(), iterations); + QCOMPARE(counter.loadRelaxed(), iterations); } } @@ -186,7 +186,7 @@ public: // this class throttles between iterations 100 and 200, // and then records how many threads that run between // iterations 140 and 160. - ThrottleFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.store(0); throttling = false; } + ThrottleFor(TestIterator begin, TestIterator end) : IterateKernel<TestIterator, void>(begin, end) { iterations.storeRelaxed(0); throttling = false; } inline bool runIterations(TestIterator/*beginIterator*/, int begin, int end, void *) { if (200 >= begin && 200 < end) { @@ -217,7 +217,7 @@ public: bool shouldThrottleThread() { - const int load = iterations.load(); + const int load = iterations.loadRelaxed(); return (load > 100 && load < 200); } bool throttling; @@ -226,14 +226,14 @@ public: void tst_QtConcurrentIterateKernel::throttling() { const int totalIterations = 400; - iterations.store(0); + iterations.storeRelaxed(0); threads.clear(); ThrottleFor f(0, totalIterations); f.startBlocking(); - QCOMPARE(iterations.load(), totalIterations); + QCOMPARE(iterations.loadRelaxed(), totalIterations); QCOMPARE(threads.count(), 1); diff --git a/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro b/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro index fd8fd0a74a..717d103e44 100644 --- a/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro +++ b/tests/auto/concurrent/qtconcurrentmap/qtconcurrentmap.pro @@ -3,6 +3,7 @@ TARGET = tst_qtconcurrentmap QT = core testlib concurrent SOURCES = tst_qtconcurrentmap.cpp DEFINES += QT_STRICT_ITERATORS +DEFINES -= QT_NO_LINKED_LIST # Force C++17 if available contains(QT_CONFIG, c++1z): CONFIG += c++1z diff --git a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp index b864b065e6..383de0b2ce 100644 --- a/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp +++ b/tests/auto/concurrent/qtconcurrentmap/tst_qtconcurrentmap.cpp @@ -127,14 +127,11 @@ void tst_QtConcurrentMap::map() QtConcurrent::map(numberList.begin(), numberList.end(), &Number::multiplyBy2).waitForFinished(); QCOMPARE(numberList, QList<Number>() << 4 << 8 << 12); -#ifdef Q_COMPILER_LAMBDA // lambda QtConcurrent::map(list, [](int &x){x *= 2;}).waitForFinished(); QCOMPARE(list, QList<int>() << 128 << 256 << 384); QtConcurrent::map(list.begin(), list.end(), [](int &x){x *= 2;}).waitForFinished(); QCOMPARE(list, QList<int>() << 256 << 512 << 768); -#endif - } // functors don't take arguments by reference, making these no-ops @@ -160,13 +157,11 @@ void tst_QtConcurrentMap::map() QtConcurrent::map(list.begin(), list.end(), multiplyBy2Immutable).waitForFinished(); QCOMPARE(list, QList<int>() << 1 << 2 << 3); -#ifdef Q_COMPILER_LAMBDA // lambda QtConcurrent::map(list, [](int x){x *= 2;}).waitForFinished(); QCOMPARE(list, QList<int>() << 1 << 2 << 3); QtConcurrent::map(list.begin(), list.end(), [](int x){x *= 2;}).waitForFinished(); QCOMPARE(list, QList<int>() << 1 << 2 << 3); -#endif } // Linked lists and forward iterators @@ -2026,12 +2021,12 @@ int fn(int &i) return i; } -int fnConstNoExcept(const int &i) Q_DECL_NOTHROW +int fnConstNoExcept(const int &i) noexcept { return i; } -int fnNoExcept(int &i) Q_DECL_NOTHROW +int fnNoExcept(int &i) noexcept { return i; } @@ -2046,12 +2041,12 @@ QString changeType(int &) return QString(); } -QString changeTypeConstNoExcept(const int &) Q_DECL_NOTHROW +QString changeTypeConstNoExcept(const int &) noexcept { return QString(); } -QString changeTypeNoExcept(int &) Q_DECL_NOTHROW +QString changeTypeNoExcept(int &) noexcept { return QString(); } @@ -2066,12 +2061,12 @@ int changeTypeQStringList(QStringList &) return 0; } -int changeTypeQStringListConstNoExcept(const QStringList &) Q_DECL_NOTHROW +int changeTypeQStringListConstNoExcept(const QStringList &) noexcept { return 0; } -int changeTypeQStringListNoExcept(QStringList &) Q_DECL_NOTHROW +int changeTypeQStringListNoExcept(QStringList &) noexcept { return 0; } @@ -2101,22 +2096,22 @@ public: return QString(); } - MemFnTester fnNoExcept() Q_DECL_NOTHROW + MemFnTester fnNoExcept() noexcept { return MemFnTester(); } - MemFnTester fnConstNoExcept() const Q_DECL_NOTHROW + MemFnTester fnConstNoExcept() const noexcept { return MemFnTester(); } - QString changeTypeNoExcept() Q_DECL_NOTHROW + QString changeTypeNoExcept() noexcept { return QString(); } - QString changeTypeConstNoExcept() const Q_DECL_NOTHROW + QString changeTypeConstNoExcept() const noexcept { return QString(); } @@ -2186,8 +2181,8 @@ public: void updatePeak() { forever { - const int localPeak = peakInstanceCount.load(); - const int localCurrent = currentInstanceCount.load(); + const int localPeak = peakInstanceCount.loadRelaxed(); + const int localCurrent = currentInstanceCount.loadRelaxed(); if (localCurrent <= localPeak) break; if (peakInstanceCount.testAndSetOrdered(localPeak, localCurrent)) @@ -2225,35 +2220,35 @@ void tst_QtConcurrentMap::throttling() const int allowedTemporaries = QThread::idealThreadCount() * 40; { - currentInstanceCount.store(0); - peakInstanceCount.store(0); + currentInstanceCount.storeRelaxed(0); + peakInstanceCount.storeRelaxed(0); QList<InstanceCounter> instances; for (int i = 0; i < itemcount; ++i) instances.append(InstanceCounter()); - QCOMPARE(currentInstanceCount.load(), itemcount); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); int results = QtConcurrent::blockingMappedReduced(instances, slowMap, fastReduce); QCOMPARE(results, itemcount); - QCOMPARE(currentInstanceCount.load(), itemcount); - QVERIFY(peakInstanceCount.load() < itemcount + allowedTemporaries); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); + QVERIFY(peakInstanceCount.loadRelaxed() < itemcount + allowedTemporaries); } { - QCOMPARE(currentInstanceCount.load(), 0); - peakInstanceCount.store(0); + QCOMPARE(currentInstanceCount.loadRelaxed(), 0); + peakInstanceCount.storeRelaxed(0); QList<InstanceCounter> instances; for (int i = 0; i < itemcount; ++i) instances.append(InstanceCounter()); - QCOMPARE(currentInstanceCount.load(), itemcount); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); int results = QtConcurrent::blockingMappedReduced(instances, fastMap, slowReduce); QCOMPARE(results, itemcount); - QCOMPARE(currentInstanceCount.load(), itemcount); - QVERIFY(peakInstanceCount.load() < itemcount + allowedTemporaries); + QCOMPARE(currentInstanceCount.loadRelaxed(), itemcount); + QVERIFY(peakInstanceCount.loadRelaxed() < itemcount + allowedTemporaries); } } @@ -2385,8 +2380,8 @@ InstanceCounter ic_fn(const InstanceCounter & ic) // assigned over with operator == void tst_QtConcurrentMap::qFutureAssignmentLeak() { - currentInstanceCount.store(0); - peakInstanceCount.store(0); + currentInstanceCount.storeRelaxed(0); + peakInstanceCount.storeRelaxed(0); QFuture<InstanceCounter> future; { QList<InstanceCounter> list; @@ -2405,9 +2400,9 @@ void tst_QtConcurrentMap::qFutureAssignmentLeak() // Use QTRY_COMPARE because QtConcurrent::ThreadEngine::asynchronousFinish() // deletes its internals after signaling finished, so it might still be holding // on to copies of InstanceCounter for a short while. - QTRY_COMPARE(currentInstanceCount.load(), 1000); + QTRY_COMPARE(currentInstanceCount.loadRelaxed(), 1000); future = QFuture<InstanceCounter>(); - QTRY_COMPARE(currentInstanceCount.load(), 0); + QTRY_COMPARE(currentInstanceCount.loadRelaxed(), 0); } inline void increment(int &num) diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index 1596a9fafd..a4eb2936b5 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -48,12 +48,8 @@ private slots: #ifndef QT_NO_EXCEPTIONS void exceptions(); #endif -#ifdef Q_COMPILER_DECLTYPE void functor(); -#endif -#ifdef Q_COMPILER_LAMBDA void lambda(); -#endif }; void light() @@ -126,23 +122,23 @@ public: class ANoExcept { public: - int member0() Q_DECL_NOTHROW { return 10; } - int member1(int in) Q_DECL_NOTHROW { return in; } + int member0() noexcept { return 10; } + int member1(int in) noexcept { return in; } typedef int result_type; - int operator()() Q_DECL_NOTHROW { return 10; } - int operator()(int in) Q_DECL_NOTHROW { return in; } + int operator()() noexcept { return 10; } + int operator()(int in) noexcept { return in; } }; class AConstNoExcept { public: - int member0() const Q_DECL_NOTHROW { return 10; } - int member1(int in) const Q_DECL_NOTHROW { return in; } + int member0() const noexcept { return 10; } + int member1(int in) const noexcept { return in; } typedef int result_type; - int operator()() const Q_DECL_NOTHROW { return 10; } - int operator()(int in) const Q_DECL_NOTHROW { return in; } + int operator()() const noexcept { return 10; } + int operator()(int in) const noexcept { return in; } }; void tst_QtConcurrentRun::returnValue() @@ -510,17 +506,17 @@ void tst_QtConcurrentRun::recursive() int levels = 15; for (int i = 0; i < QThread::idealThreadCount(); ++i) { - count.store(0); + count.storeRelaxed(0); QThreadPool::globalInstance()->setMaxThreadCount(i); recursiveRun(levels); - QCOMPARE(count.load(), (int)std::pow(2.0, levels) - 1); + QCOMPARE(count.loadRelaxed(), (int)std::pow(2.0, levels) - 1); } for (int i = 0; i < QThread::idealThreadCount(); ++i) { - count.store(0); + count.storeRelaxed(0); QThreadPool::globalInstance()->setMaxThreadCount(i); recursiveResult(levels); - QCOMPARE(count.load(), (int)std::pow(2.0, levels) - 1); + QCOMPARE(count.loadRelaxed(), (int)std::pow(2.0, levels) - 1); } } @@ -574,7 +570,7 @@ public: static QAtomicInt cancel; void run() override { int iter = 60; - while (--iter && !cancel.load()) + while (--iter && !cancel.loadRelaxed()) QThread::currentThread()->msleep(25); } }; @@ -642,13 +638,12 @@ void tst_QtConcurrentRun::exceptions() caught = true; } - SlowTask::cancel.store(true); + SlowTask::cancel.storeRelaxed(true); QVERIFY2(caught, "did not get exception"); } #endif -#ifdef Q_COMPILER_DECLTYPE // Compiler supports decltype struct Functor { int operator()() { return 42; } @@ -706,9 +701,7 @@ void tst_QtConcurrentRun::functor() QtConcurrent::run(&pool, f, 1,2,3,4,5).waitForFinished(); } } -#endif -#ifdef Q_COMPILER_LAMBDA // Compiler supports lambda void tst_QtConcurrentRun::lambda() { @@ -717,14 +710,12 @@ void tst_QtConcurrentRun::lambda() QCOMPARE(QtConcurrent::run([](int a, double b){ return a + b; }, 12, 15).result(), double(12+15)); QCOMPARE(QtConcurrent::run([](int a , int, int, int, int b){ return a + b; }, 1, 2, 3, 4, 5).result(), 1 + 5); -#ifdef Q_COMPILER_INITIALIZER_LISTS { QString str { "Hello World Foo" }; QFuture<QStringList> f1 = QtConcurrent::run([&](){ return str.split(' '); }); auto r = f1.result(); QCOMPARE(r, QStringList({"Hello", "World", "Foo"})); } -#endif // and now with explicit pool: QThreadPool pool; @@ -733,16 +724,13 @@ void tst_QtConcurrentRun::lambda() QCOMPARE(QtConcurrent::run(&pool, [](int a, double b){ return a + b; }, 12, 15).result(), double(12+15)); QCOMPARE(QtConcurrent::run(&pool, [](int a , int, int, int, int b){ return a + b; }, 1, 2, 3, 4, 5).result(), 1 + 5); -#ifdef Q_COMPILER_INITIALIZER_LISTS { QString str { "Hello World Foo" }; QFuture<QStringList> f1 = QtConcurrent::run(&pool, [&](){ return str.split(' '); }); auto r = f1.result(); QCOMPARE(r, QStringList({"Hello", "World", "Foo"})); } -#endif } -#endif QTEST_MAIN(tst_QtConcurrentRun) #include "tst_qtconcurrentrun.moc" diff --git a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp index a68f7d5a4e..d4c669cddc 100644 --- a/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp +++ b/tests/auto/concurrent/qtconcurrentthreadengine/tst_qtconcurrentthreadengine.cpp @@ -28,6 +28,7 @@ #include <qtconcurrentthreadengine.h> #include <qexception.h> #include <QThread> +#include <QElapsedTimer> #include <QtTest/QtTest> using namespace QtConcurrent; @@ -186,7 +187,7 @@ class ThrottleAlwaysUser : public ThreadEngine<void> public: ThrottleAlwaysUser() { - count.store(initialCount = 100); + count.storeRelaxed(initialCount = 100); finishing = false; } @@ -198,7 +199,7 @@ public: ThreadFunctionResult threadFunction() { forever { - const int local = count.load(); + const int local = count.loadRelaxed(); if (local == 0) { finishing = true; return ThreadFinished; @@ -223,13 +224,13 @@ void tst_QtConcurrentThreadEngine::throttle() for (int i = 0; i < repeats; ++i) { QFuture<void> f = (new ThrottleAlwaysUser())->startAsynchronously(); f.waitForFinished(); - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } for (int i = 0; i < repeats; ++i) { ThrottleAlwaysUser t; t.startBlocking(); - QCOMPARE(count.load(), 0); + QCOMPARE(count.loadRelaxed(), 0); } } @@ -382,7 +383,7 @@ void tst_QtConcurrentThreadEngine::cancelQueuedSlowUser() { const int times = 100; - QTime t; + QElapsedTimer t; t.start(); { |