diff options
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r-- | tests/auto/corelib/io/qdebug/qdebug.pro | 2 | ||||
-rw-r--r-- | tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 40 | ||||
-rw-r--r-- | tests/auto/corelib/io/qprocess/test/test.pro | 1 | ||||
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 2 |
4 files changed, 42 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qdebug/qdebug.pro b/tests/auto/corelib/io/qdebug/qdebug.pro index 820c17fc69..5e902bb105 100644 --- a/tests/auto/corelib/io/qdebug/qdebug.pro +++ b/tests/auto/corelib/io/qdebug/qdebug.pro @@ -1,5 +1,5 @@ CONFIG += testcase parallel_test TARGET = tst_qdebug -QT = core testlib +QT = core testlib concurrent SOURCES = tst_qdebug.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 07e011f449..3f53ab5f0a 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -44,6 +44,9 @@ #include <QtCore/QtDebug> #include <QtTest/QtTest> +#include <QtConcurrentRun> +#include <QFutureSynchronizer> + class tst_QDebug: public QObject { Q_OBJECT @@ -59,6 +62,7 @@ private slots: void qDebugQLatin1String() const; void textStreamModifiers() const; void defaultMessagehandler() const; + void threadSafety() const; }; void tst_QDebug::assignment() const @@ -315,5 +319,41 @@ void tst_QDebug::defaultMessagehandler() const QVERIFY(same); } +QMutex s_mutex; +QStringList s_messages; +QSemaphore s_sema; + +static void threadSafeMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + QMutexLocker lock(&s_mutex); + s_messages.append(msg); + Q_UNUSED(type); + Q_UNUSED(context); +} + +static void doDebug() // called in each thread +{ + s_sema.acquire(); + qDebug() << "doDebug"; +} + +void tst_QDebug::threadSafety() const +{ + MessageHandlerSetter mhs(threadSafeMessageHandler); + const int numThreads = 10; + QThreadPool::globalInstance()->setMaxThreadCount(numThreads); + QFutureSynchronizer<void> sync; + for (int i = 0; i < numThreads; ++i) { + sync.addFuture(QtConcurrent::run(&doDebug)); + } + s_sema.release(numThreads); + sync.waitForFinished(); + QMutexLocker lock(&s_mutex); + QCOMPARE(s_messages.count(), numThreads); + for (int i = 0; i < numThreads; ++i) { + QCOMPARE(s_messages.at(i), QStringLiteral("doDebug")); + } +} + QTEST_MAIN(tst_QDebug); #include "tst_qdebug.moc" diff --git a/tests/auto/corelib/io/qprocess/test/test.pro b/tests/auto/corelib/io/qprocess/test/test.pro index 79ea53cc6b..90afeddaa0 100644 --- a/tests/auto/corelib/io/qprocess/test/test.pro +++ b/tests/auto/corelib/io/qprocess/test/test.pro @@ -2,7 +2,6 @@ CONFIG += testcase CONFIG += parallel_test CONFIG -= app_bundle debug_and_release_target QT = core testlib network -embedded: QT += gui SOURCES = ../tst_qprocess.cpp TARGET = ../tst_qprocess diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 67cf954f98..1d6418cbc0 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1953,7 +1953,7 @@ void tst_QProcess::setStandardOutputFile2() process.start("testProcessEcho2/testProcessEcho2"); process.write(testdata, sizeof testdata); QPROCESS_VERIFY(process,waitForFinished()); - QVERIFY(!process.bytesAvailable()); + QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); QVERIFY(!QFileInfo(QProcess::nullDevice()).isFile()); } |