summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-02-16 21:46:20 +0100
committerLiang Qi <liang.qi@qt.io>2017-02-16 21:51:11 +0100
commitc577f6edafef7c40a5f78092ec4fcd78bb820b2c (patch)
tree9ca3819e5cca9b7e61f305a874b682e5a2085e83 /tests/auto/corelib
parent99ce1d3d97c0423c3ee63ccf58deed964db0770e (diff)
parentde225ccdf95efb57866d62bc80872c1a2ab99703 (diff)
Merge remote-tracking branch 'origin/5.8' into 5.9
Conflicts: src/corelib/plugin/qlibrary_unix.cpp src/plugins/platforms/xcb/qxcbconnection.cpp tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp Change-Id: I632c400d909f8c204f55743aadc7886af2f15dfb
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp8
-rw-r--r--tests/auto/corelib/kernel/qtimer/BLACKLIST3
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp7
-rw-r--r--tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp6
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp69
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp38
6 files changed, 95 insertions, 36 deletions
diff --git a/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp
index 9db001c37d..4ee3ca361f 100644
--- a/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp
+++ b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp
@@ -31,7 +31,7 @@
#include <QtCore/QElapsedTimer>
#include <QtTest/QtTest>
-static const int minResolution = 50; // the minimum resolution for the tests
+static const int minResolution = 100; // the minimum resolution for the tests
QDebug operator<<(QDebug s, const QElapsedTimer &t)
{
@@ -107,7 +107,7 @@ void tst_QElapsedTimer::elapsed()
QElapsedTimer t1;
t1.start();
- QTest::qSleep(4*minResolution);
+ QTest::qSleep(2*minResolution);
QElapsedTimer t2;
t2.start();
@@ -128,8 +128,8 @@ void tst_QElapsedTimer::elapsed()
QVERIFY(!t2.hasExpired(-1));
qint64 elapsed = t1.restart();
- QVERIFY(elapsed > 3*minResolution);
- QVERIFY(elapsed < 5*minResolution);
+ QVERIFY(elapsed > minResolution);
+ QVERIFY(elapsed < 3*minResolution);
qint64 diff = t2.msecsTo(t1);
QVERIFY(diff < minResolution);
}
diff --git a/tests/auto/corelib/kernel/qtimer/BLACKLIST b/tests/auto/corelib/kernel/qtimer/BLACKLIST
new file mode 100644
index 0000000000..e5136624d8
--- /dev/null
+++ b/tests/auto/corelib/kernel/qtimer/BLACKLIST
@@ -0,0 +1,3 @@
+[remainingTime]
+windows
+osx
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 2cf9ea4913..8058d3c897 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -858,6 +858,11 @@ void tst_QMimeDatabase::fromThreads()
}
#ifndef QT_NO_PROCESS
+
+enum {
+ UpdateMimeDatabaseTimeout = 120 * 1000 // 2min
+};
+
static bool runUpdateMimeDatabase(const QString &path) // TODO make it a QMimeDatabase method?
{
const QString umdCommand = QString::fromLatin1("update-mime-database");
@@ -878,7 +883,7 @@ static bool runUpdateMimeDatabase(const QString &path) // TODO make it a QMimeDa
qPrintable(umd), qPrintable(proc.errorString()));
return false;
}
- const bool success = proc.waitForFinished();
+ const bool success = proc.waitForFinished(UpdateMimeDatabaseTimeout);
qDebug().noquote() << "runUpdateMimeDatabase: done,"
<< success << timer.elapsed() << "ms";
return true;
diff --git a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
index f1eb32a282..2970b2e118 100644
--- a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
+++ b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp
@@ -367,16 +367,18 @@ public:
void run();
};
+static const int Timeout = 60 * 1000; // 1min
+
void Producer::run()
{
for (int i = 0; i < DataSize; ++i) {
- freeSpace.acquire();
+ QVERIFY(freeSpace.tryAcquire(1, Timeout));
buffer[i % BufferSize] = alphabet[i % AlphabetSize];
usedSpace.release();
}
for (int i = 0; i < DataSize; ++i) {
if ((i % ProducerChunkSize) == 0)
- freeSpace.acquire(ProducerChunkSize);
+ QVERIFY(freeSpace.tryAcquire(ProducerChunkSize, Timeout));
buffer[i % BufferSize] = alphabet[i % AlphabetSize];
if ((i % ProducerChunkSize) == (ProducerChunkSize - 1))
usedSpace.release(ProducerChunkSize);
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index 3bc3f8a759..5b7242fddb 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -958,51 +958,88 @@ void tst_QThreadPool::clear()
void tst_QThreadPool::cancel()
{
QSemaphore sem(0);
+ QSemaphore startedThreads(0);
+
+ class SemaphoreReleaser
+ {
+ QSemaphore &sem;
+ int n;
+ Q_DISABLE_COPY(SemaphoreReleaser)
+ public:
+ explicit SemaphoreReleaser(QSemaphore &sem, int n)
+ : sem(sem), n(n) {}
+
+ ~SemaphoreReleaser()
+ {
+ sem.release(n);
+ }
+ };
+
class BlockingRunnable : public QRunnable
{
public:
QSemaphore & sem;
- int & dtorCounter;
- int & runCounter;
+ QSemaphore &startedThreads;
+ QAtomicInt &dtorCounter;
+ QAtomicInt &runCounter;
int dummy;
- BlockingRunnable(QSemaphore & s, int & c, int & r) : sem(s), dtorCounter(c), runCounter(r){}
- ~BlockingRunnable(){dtorCounter++;}
+
+ explicit BlockingRunnable(QSemaphore &s, QSemaphore &started, QAtomicInt &c, QAtomicInt &r)
+ : sem(s), startedThreads(started), dtorCounter(c), runCounter(r){}
+
+ ~BlockingRunnable()
+ {
+ dtorCounter.fetchAndAddRelaxed(1);
+ }
+
void run()
{
- runCounter++;
+ startedThreads.release();
+ runCounter.fetchAndAddRelaxed(1);
sem.acquire();
count.ref();
}
};
- typedef BlockingRunnable* BlockingRunnablePtr;
+
+ enum {
+ MaxThreadCount = 3,
+ OverProvisioning = 2,
+ runs = MaxThreadCount * OverProvisioning
+ };
QThreadPool threadPool;
- threadPool.setMaxThreadCount(3);
- int runs = 2 * threadPool.maxThreadCount();
- BlockingRunnablePtr* runnables = new BlockingRunnablePtr[runs];
+ threadPool.setMaxThreadCount(MaxThreadCount);
+ BlockingRunnable *runnables[runs];
+
+ // ensure that the QThreadPool doesn't deadlock if any of the checks fail
+ // and cause an early return:
+ const SemaphoreReleaser semReleaser(sem, runs);
+
count.store(0);
- int dtorCounter = 0;
- int runCounter = 0;
+ QAtomicInt dtorCounter = 0;
+ QAtomicInt runCounter = 0;
for (int i = 0; i < runs; i++) {
- runnables[i] = new BlockingRunnable(sem, dtorCounter, runCounter);
+ runnables[i] = new BlockingRunnable(sem, startedThreads, dtorCounter, runCounter);
runnables[i]->setAutoDelete(i != 0 && i != (runs-1)); //one which will run and one which will not
threadPool.cancel(runnables[i]); //verify NOOP for jobs not in the queue
threadPool.start(runnables[i]);
}
+ // wait for all worker threads to have started up:
+ QVERIFY(startedThreads.tryAcquire(MaxThreadCount, 60*1000 /* 1min */));
+
for (int i = 0; i < runs; i++) {
threadPool.cancel(runnables[i]);
}
runnables[0]->dummy = 0; //valgrind will catch this if cancel() is crazy enough to delete currently running jobs
runnables[runs-1]->dummy = 0;
- QCOMPARE(dtorCounter, runs-threadPool.maxThreadCount()-1);
+ QCOMPARE(dtorCounter.load(), runs - threadPool.maxThreadCount() - 1);
sem.release(threadPool.maxThreadCount());
threadPool.waitForDone();
- QCOMPARE(runCounter, threadPool.maxThreadCount());
+ QCOMPARE(runCounter.load(), threadPool.maxThreadCount());
QCOMPARE(count.load(), threadPool.maxThreadCount());
- QCOMPARE(dtorCounter, runs-2);
+ QCOMPARE(dtorCounter.load(), runs - 2);
delete runnables[0]; //if the pool deletes them then we'll get double-free crash
delete runnables[runs-1];
- delete[] runnables;
}
void tst_QThreadPool::destroyingWaitsForTasksToFinish()
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 5f9f5fbb6f..b81f3d356d 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -155,6 +155,29 @@ private:
QDateTime invalidDateTime() const { return QDateTime(invalidDate(), invalidTime()); }
QDate invalidDate() const { return QDate(); }
QTime invalidTime() const { return QTime(-1, -1, -1); }
+
+ class TimeZoneRollback
+ {
+ const QByteArray prior;
+ public:
+ // Save the previous timezone so we can restore it afterwards, otherwise
+ // later tests may break:
+ explicit TimeZoneRollback(const QByteArray &zone) : prior(qgetenv("TZ"))
+ { reset(zone); }
+ void reset(const QByteArray &zone)
+ {
+ qputenv("TZ", zone.constData());
+ tzset();
+ }
+ ~TimeZoneRollback()
+ {
+ if (prior.isNull())
+ qunsetenv("TZ");
+ else
+ qputenv("TZ", prior.constData());
+ tzset();
+ }
+ };
};
Q_DECLARE_METATYPE(Qt::TimeSpec)
@@ -1953,12 +1976,8 @@ void tst_QDateTime::operator_insert_extract()
QFETCH(QString, deserialiseAs);
QFETCH(QDataStream::Version, dataStreamVersion);
- // Save the previous timezone so we can restore it afterwards, otherwise later tests will break
- QByteArray previousTimeZone = qgetenv("TZ");
-
// Start off in a certain timezone.
- qputenv("TZ", serialiseAs.toLocal8Bit().constData());
- tzset();
+ TimeZoneRollback useZone(serialiseAs.toLocal8Bit());
QDateTime dateTimeAsUTC(dateTime.toUTC());
QByteArray byteArray;
@@ -1983,8 +2002,7 @@ void tst_QDateTime::operator_insert_extract()
// Ensure that a change in timezone between serialisation and deserialisation
// still results in identical UTC-converted datetimes.
- qputenv("TZ", deserialiseAs.toLocal8Bit().constData());
- tzset();
+ useZone.reset(deserialiseAs.toLocal8Bit());
QDateTime expectedLocalTime(dateTimeAsUTC.toLocalTime());
{
// Deserialise whole QDateTime at once.
@@ -2035,12 +2053,6 @@ void tst_QDateTime::operator_insert_extract()
QCOMPARE(localDeserialized, dateTime);
}
}
-
- if (previousTimeZone.isNull())
- qunsetenv("TZ");
- else
- qputenv("TZ", previousTimeZone.constData());
- tzset();
}
void tst_QDateTime::toString_strformat()