diff --git a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp index 33133e876f..1ca900fa27 100644 --- a/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp +++ b/tests/auto/concurrent/qtconcurrentiteratekernel/tst_qtconcurrentiteratekernel.cpp @@ -151,7 +151,9 @@ void tst_QtConcurrentIterateKernel::cancel() f.cancel(); f.waitForFinished(); QVERIFY(f.isCanceled()); - QVERIFY(iterations.load() <= QThread::idealThreadCount()); // the threads might run one iteration each before they are canceled. + // the threads might run one iteration each before they are canceled. + QVERIFY2(iterations.load() <= QThread::idealThreadCount(), + (QByteArray::number(iterations.load()) + ' ' + QByteArray::number(QThread::idealThreadCount()))); } } @@ -251,26 +253,48 @@ void tst_QtConcurrentIterateKernel::throttling() QCOMPARE(threads.count(), 1); } - -int peakBlockSize = 0; class BlockSizeRecorder : public IterateKernel { public: - BlockSizeRecorder(TestIterator begin, TestIterator end) : IterateKernel(begin, end) { } + BlockSizeRecorder(TestIterator begin, TestIterator end) + : IterateKernel(begin, end) + , peakBlockSize(0) + , peakBegin(0) + {} + inline bool runIterations(TestIterator, int begin, int end, void *) { - peakBlockSize = qMax(peakBlockSize, end - begin); + const int blockSize = end - begin; + if (blockSize > peakBlockSize) { + peakBlockSize = blockSize; + peakBegin = begin; + } return false; } + int peakBlockSize; + int peakBegin; }; +static QByteArray msgBlockSize(const BlockSizeRecorder &recorder, int expectedMinimumBlockSize) +{ + return QByteArrayLiteral("peakBlockSize=") + QByteArray::number(recorder.peakBlockSize) + + QByteArrayLiteral(" is less than expectedMinimumBlockSize=") + + QByteArray::number(expectedMinimumBlockSize) + + QByteArrayLiteral(", reached at: ") + QByteArray::number(recorder.peakBegin) + + QByteArrayLiteral(" (ideal thread count: ") + QByteArray::number(QThread::idealThreadCount()) + + ')'; +} + void tst_QtConcurrentIterateKernel::blockSize() { const int expectedMinimumBlockSize = 1024 / QThread::idealThreadCount(); - BlockSizeRecorder(0, 10000).startBlocking(); - if (peakBlockSize < expectedMinimumBlockSize) - qDebug() << "block size" << peakBlockSize; - QVERIFY(peakBlockSize >= expectedMinimumBlockSize); + BlockSizeRecorder recorder(0, 10000); + recorder.startBlocking(); +#ifdef Q_OS_WIN + if (recorder.peakBlockSize < expectedMinimumBlockSize) + QEXPECT_FAIL("", msgBlockSize(recorder, expectedMinimumBlockSize).constData(), Abort); +#endif // Q_OS_WIN + QVERIFY2(recorder.peakBlockSize >= expectedMinimumBlockSize, msgBlockSize(recorder, expectedMinimumBlockSize)); } class MultipleResultsFor : public IterateKernel