From ed8d8451c4174d9f200445c8476a9216be51af70 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 27 Feb 2012 11:09:27 +0100 Subject: 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 --- .../corelib/thread/qthreadstorage/crashOnExit.cpp | 65 ---------------------- .../corelib/thread/qthreadstorage/crashOnExit.pro | 8 --- .../qthreadstorage/crashonexit/crashOnExit.cpp | 65 ++++++++++++++++++++++ .../qthreadstorage/crashonexit/crashonexit.pro | 9 +++ .../thread/qthreadstorage/qthreadstorage.pro | 6 +- .../corelib/thread/qthreadstorage/test/test.pro | 6 ++ .../thread/qthreadstorage/tst_qthreadstorage.cpp | 54 ++++++++++++++---- .../thread/qthreadstorage/tst_qthreadstorage.pro | 4 -- 8 files changed, 127 insertions(+), 90 deletions(-) delete mode 100644 tests/auto/corelib/thread/qthreadstorage/crashOnExit.cpp delete mode 100644 tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro create mode 100644 tests/auto/corelib/thread/qthreadstorage/crashonexit/crashOnExit.cpp create mode 100644 tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro create mode 100644 tests/auto/corelib/thread/qthreadstorage/test/test.pro delete mode 100644 tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro (limited to 'tests/auto/corelib/thread/qthreadstorage') diff --git a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.cpp b/tests/auto/corelib/thread/qthreadstorage/crashOnExit.cpp deleted file mode 100644 index 388c233d84..0000000000 --- a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -class Class -{ -public: - ~Class() - { - // trigger creation of a new QThreadStorage, after the previous QThreadStorage from main() was destructed - static QThreadStorage threadstorage; - threadstorage.setLocalData(new int); - threadstorage.setLocalData(new int); - } -}; - -int main() -{ - // instantiate the class that will use QThreadStorage from its destructor, it's destructor will be run last - static Class instance; - // instantiate QThreadStorage, it's destructor (and the global destructors for QThreadStorages internals) will run first - static QThreadStorage threadstorage; - threadstorage.setLocalData(new int); - threadstorage.setLocalData(new int); -} diff --git a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro b/tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro deleted file mode 100644 index 68d0f1202b..0000000000 --- a/tests/auto/corelib/thread/qthreadstorage/crashOnExit.pro +++ /dev/null @@ -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 diff --git a/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashOnExit.cpp b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashOnExit.cpp new file mode 100644 index 0000000000..388c233d84 --- /dev/null +++ b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashOnExit.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +class Class +{ +public: + ~Class() + { + // trigger creation of a new QThreadStorage, after the previous QThreadStorage from main() was destructed + static QThreadStorage threadstorage; + threadstorage.setLocalData(new int); + threadstorage.setLocalData(new int); + } +}; + +int main() +{ + // instantiate the class that will use QThreadStorage from its destructor, it's destructor will be run last + static Class instance; + // instantiate QThreadStorage, it's destructor (and the global destructors for QThreadStorages internals) will run first + static QThreadStorage threadstorage; + threadstorage.setLocalData(new int); + threadstorage.setLocalData(new int); +} diff --git a/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro new file mode 100644 index 0000000000..94a0a01e94 --- /dev/null +++ b/tests/auto/corelib/thread/qthreadstorage/crashonexit/crashonexit.pro @@ -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 diff --git a/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro b/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro index 0dc8d086df..2fa973d2f7 100644 --- a/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro +++ b/tests/auto/corelib/thread/qthreadstorage/qthreadstorage.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs SUBDIRS = \ - tst_qthreadstorage.pro \ - crashOnExit.pro -CONFIG += parallel_test + crashonexit \ + test +CONFIG += ordered parallel_test diff --git a/tests/auto/corelib/thread/qthreadstorage/test/test.pro b/tests/auto/corelib/thread/qthreadstorage/test/test.pro new file mode 100644 index 0000000000..a7d8eb0106 --- /dev/null +++ b/tests/auto/corelib/thread/qthreadstorage/test/test.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = ../tst_qthreadstorage +CONFIG -= app_bundle +CONFIG += console +QT = core testlib +SOURCES = ../tst_qthreadstorage.cpp diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp index fff361ea2a..0529e67e0f 100644 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include #ifdef Q_OS_UNIX #include @@ -61,6 +63,7 @@ class tst_QThreadStorage : public QObject { Q_OBJECT private slots: + void initTestCase(); void hasLocalData(); void localData(); void localData_const(); @@ -72,6 +75,9 @@ private slots: void leakInDestructor(); void resetInDestructor(); void valueBased(); + +private: + QString m_crashOnExit; }; class Pointer @@ -83,6 +89,20 @@ public: }; 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() { QThreadStorage pointers; @@ -285,18 +305,32 @@ void tst_QThreadStorage::ensureCleanupOrder() QVERIFY(First::order < Second::order); } -void tst_QThreadStorage::crashOnExit() +static inline bool runCrashOnExit(const QString &binary, QString *errorMessage) { + const int timeout = 60000; QProcess process; - // crashOnExit is always expected to be in the same directory - // as this test binary -#ifdef Q_OS_MAC - process.start(QCoreApplication::applicationDirPath() + "/../../../crashOnExit"); -#else - process.start(QCoreApplication::applicationDirPath() + "/crashOnExit"); -#endif - QVERIFY(process.waitForFinished()); - QVERIFY(process.exitStatus() != QProcess::CrashExit); + 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() +{ + QString errorMessage; + QVERIFY2(runCrashOnExit(m_crashOnExit, &errorMessage), + qPrintable(errorMessage)); } // S stands for thread Safe. diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro deleted file mode 100644 index 15ced107d3..0000000000 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qthreadstorage -QT = core testlib -SOURCES = tst_qthreadstorage.cpp -- cgit v1.2.3