Fix QThreadstorage test.
- Create subdirectories containing profiles to avoid problems with -fast. - Use QFINDTESTDATA to locate binary. - Make it a console application, no Mac-bundle. - Add error messages to the test, give it a longer time-out and ensure sub-process is killed if it hangs. Change-Id: Ibc177b786c4bc8fdbc068a8c45f4801a41c9f660 Reviewed-by: Sergio Ahumada <sergio.ahumada@nokia.com>
This commit is contained in:
parent
5a0eb4e768
commit
ed8d8451c4
@ -1,8 +0,0 @@
|
|||||||
SOURCES += crashOnExit.cpp
|
|
||||||
QT = core
|
|
||||||
CONFIG-=app_bundle
|
|
||||||
CONFIG+=console
|
|
||||||
|
|
||||||
# This app is testdata for tst_qthreadstorage
|
|
||||||
target.path = $$[QT_INSTALL_TESTS]/tst_qthreadstorage
|
|
||||||
INSTALLS += target
|
|
@ -0,0 +1,9 @@
|
|||||||
|
SOURCES += crashOnExit.cpp
|
||||||
|
DESTDIR = ./
|
||||||
|
QT = core
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
CONFIG += console
|
||||||
|
|
||||||
|
# This app is testdata for tst_qthreadstorage
|
||||||
|
target.path = $$[QT_INSTALL_TESTS]/tst_qthreadstorage/$$TARGET
|
||||||
|
INSTALLS += target
|
@ -1,5 +1,5 @@
|
|||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
tst_qthreadstorage.pro \
|
crashonexit \
|
||||||
crashOnExit.pro
|
test
|
||||||
CONFIG += parallel_test
|
CONFIG += ordered parallel_test
|
||||||
|
6
tests/auto/corelib/thread/qthreadstorage/test/test.pro
Normal file
6
tests/auto/corelib/thread/qthreadstorage/test/test.pro
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
CONFIG += testcase
|
||||||
|
TARGET = ../tst_qthreadstorage
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
CONFIG += console
|
||||||
|
QT = core testlib
|
||||||
|
SOURCES = ../tst_qthreadstorage.cpp
|
@ -46,6 +46,8 @@
|
|||||||
#include <qthread.h>
|
#include <qthread.h>
|
||||||
#include <qwaitcondition.h>
|
#include <qwaitcondition.h>
|
||||||
#include <qthreadstorage.h>
|
#include <qthreadstorage.h>
|
||||||
|
#include <qdir.h>
|
||||||
|
#include <qfileinfo.h>
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -61,6 +63,7 @@ class tst_QThreadStorage : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
|
void initTestCase();
|
||||||
void hasLocalData();
|
void hasLocalData();
|
||||||
void localData();
|
void localData();
|
||||||
void localData_const();
|
void localData_const();
|
||||||
@ -72,6 +75,9 @@ private slots:
|
|||||||
void leakInDestructor();
|
void leakInDestructor();
|
||||||
void resetInDestructor();
|
void resetInDestructor();
|
||||||
void valueBased();
|
void valueBased();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_crashOnExit;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Pointer
|
class Pointer
|
||||||
@ -83,6 +89,20 @@ public:
|
|||||||
};
|
};
|
||||||
int Pointer::count = 0;
|
int Pointer::count = 0;
|
||||||
|
|
||||||
|
void tst_QThreadStorage::initTestCase()
|
||||||
|
{
|
||||||
|
const QString crashOnExitDir = QFINDTESTDATA("crashonexit");
|
||||||
|
QVERIFY2(!crashOnExitDir.isEmpty(),
|
||||||
|
qPrintable(QString::fromLatin1("Could not find 'crashonexit' starting from '%1'")
|
||||||
|
.arg(QDir::toNativeSeparators(QDir::currentPath()))));
|
||||||
|
m_crashOnExit = crashOnExitDir + QStringLiteral("/crashonexit");
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
m_crashOnExit += QStringLiteral(".exe");
|
||||||
|
#endif
|
||||||
|
QVERIFY2(QFileInfo(m_crashOnExit).isExecutable(),
|
||||||
|
qPrintable(QDir::toNativeSeparators(m_crashOnExit) + QStringLiteral(" does not exist or is not executable.")));
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QThreadStorage::hasLocalData()
|
void tst_QThreadStorage::hasLocalData()
|
||||||
{
|
{
|
||||||
QThreadStorage<Pointer *> pointers;
|
QThreadStorage<Pointer *> pointers;
|
||||||
@ -285,18 +305,32 @@ void tst_QThreadStorage::ensureCleanupOrder()
|
|||||||
QVERIFY(First::order < Second::order);
|
QVERIFY(First::order < Second::order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool runCrashOnExit(const QString &binary, QString *errorMessage)
|
||||||
|
{
|
||||||
|
const int timeout = 60000;
|
||||||
|
QProcess process;
|
||||||
|
process.start(binary);
|
||||||
|
if (!process.waitForStarted()) {
|
||||||
|
*errorMessage = QString::fromLatin1("Could not start '%1': %2").arg(binary, process.errorString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!process.waitForFinished(timeout)) {
|
||||||
|
process.kill();
|
||||||
|
*errorMessage = QString::fromLatin1("Timeout (%1ms) waiting for %2.").arg(timeout).arg(binary);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (process.exitStatus() != QProcess::NormalExit) {
|
||||||
|
*errorMessage = binary + QStringLiteral(" crashed.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QThreadStorage::crashOnExit()
|
void tst_QThreadStorage::crashOnExit()
|
||||||
{
|
{
|
||||||
QProcess process;
|
QString errorMessage;
|
||||||
// crashOnExit is always expected to be in the same directory
|
QVERIFY2(runCrashOnExit(m_crashOnExit, &errorMessage),
|
||||||
// as this test binary
|
qPrintable(errorMessage));
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
process.start(QCoreApplication::applicationDirPath() + "/../../../crashOnExit");
|
|
||||||
#else
|
|
||||||
process.start(QCoreApplication::applicationDirPath() + "/crashOnExit");
|
|
||||||
#endif
|
|
||||||
QVERIFY(process.waitForFinished());
|
|
||||||
QVERIFY(process.exitStatus() != QProcess::CrashExit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// S stands for thread Safe.
|
// S stands for thread Safe.
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
CONFIG += testcase
|
|
||||||
TARGET = tst_qthreadstorage
|
|
||||||
QT = core testlib
|
|
||||||
SOURCES = tst_qthreadstorage.cpp
|
|
Loading…
x
Reference in New Issue
Block a user