diff options
11 files changed, 165 insertions, 4 deletions
diff --git a/tests/auto/testlib/selftests/expected_watchdog.lightxml b/tests/auto/testlib/selftests/expected_watchdog.lightxml new file mode 100644 index 0000000000..1070324f2a --- /dev/null +++ b/tests/auto/testlib/selftests/expected_watchdog.lightxml @@ -0,0 +1,19 @@ +<Environment> + <QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion> + <QtBuild/> + <QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion> +</Environment> +<TestFunction name="initTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="delay"> +<Message type="qfatal" file="" line="0"> + <Description><![CDATA[Test function timed out]]></Description> +</Message> +<Incident type="fail" file="Unknown file" line="0"> + <Description><![CDATA[Received a fatal error.]]></Description> +</Incident> + <Duration msecs="0"/> +</TestFunction> +<Duration msecs="0"/> diff --git a/tests/auto/testlib/selftests/expected_watchdog.tap b/tests/auto/testlib/selftests/expected_watchdog.tap new file mode 100644 index 0000000000..3d4890b67e --- /dev/null +++ b/tests/auto/testlib/selftests/expected_watchdog.tap @@ -0,0 +1,15 @@ +TAP version 13 +# tst_Watchdog +ok 1 - initTestCase() +# Test function timed out +not ok 2 - delay() + --- + # Received a fatal error. + at: tst_Watchdog::delay() (Unknown file:0) + file: Unknown file + line: 0 + ... +1..2 +# tests 2 +# pass 1 +# fail 1 diff --git a/tests/auto/testlib/selftests/expected_watchdog.teamcity b/tests/auto/testlib/selftests/expected_watchdog.teamcity new file mode 100644 index 0000000000..0d77bf70d5 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_watchdog.teamcity @@ -0,0 +1,8 @@ +##teamcity[testSuiteStarted name='tst_Watchdog' flowId='tst_Watchdog'] +##teamcity[testStarted name='initTestCase()' flowId='tst_Watchdog'] +##teamcity[testFinished name='initTestCase()' flowId='tst_Watchdog'] +##teamcity[testStarted name='delay()' flowId='tst_Watchdog'] +##teamcity[testFailed name='delay()' message='Failure! |[Loc: Unknown file(0)|]' details='Received a fatal error.' flowId='tst_Watchdog'] +##teamcity[testStdOut name='delay()' out='QFATAL: Test function timed out' flowId='tst_Watchdog'] +##teamcity[testFinished name='delay()' flowId='tst_Watchdog'] +##teamcity[testSuiteFinished name='tst_Watchdog' flowId='tst_Watchdog'] diff --git a/tests/auto/testlib/selftests/expected_watchdog.txt b/tests/auto/testlib/selftests/expected_watchdog.txt new file mode 100644 index 0000000000..4c9cde4ea2 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_watchdog.txt @@ -0,0 +1,8 @@ +********* Start testing of tst_Watchdog ********* +Config: Using QtTest library +PASS : tst_Watchdog::initTestCase() +QFATAL : tst_Watchdog::delay() Test function timed out +FAIL! : tst_Watchdog::delay() Received a fatal error. + Loc: [Unknown file(0)] +Totals: 1 passed, 1 failed, 0 skipped, 0 blacklisted, 0ms +********* Finished testing of tst_Watchdog ********* diff --git a/tests/auto/testlib/selftests/expected_watchdog.xml b/tests/auto/testlib/selftests/expected_watchdog.xml new file mode 100644 index 0000000000..f1642fba79 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_watchdog.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<TestCase name="tst_Watchdog"> +<Environment> + <QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion> + <QtBuild/> + <QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion> +</Environment> +<TestFunction name="initTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="delay"> +<Message type="qfatal" file="" line="0"> + <Description><![CDATA[Test function timed out]]></Description> +</Message> +<Incident type="fail" file="Unknown file" line="0"> + <Description><![CDATA[Received a fatal error.]]></Description> +</Incident> + <Duration msecs="0"/> +</TestFunction> +<Duration msecs="0"/> +</TestCase> diff --git a/tests/auto/testlib/selftests/expected_watchdog.xunitxml b/tests/auto/testlib/selftests/expected_watchdog.xunitxml new file mode 100644 index 0000000000..7e16ab2c34 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_watchdog.xunitxml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<testsuite errors="1" failures="1" tests="2" name="tst_Watchdog"> + <properties> + <property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/> + <property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/> + <property value="" name="QtBuild"/> + </properties> + <testcase result="pass" name="initTestCase"/> + <testcase result="fail" name="delay"> + <!-- message="Test function timed out" type="qfatal" --> + <failure message="Received a fatal error." result="fail"/> + </testcase> + <system-err> +<![CDATA[Test function timed out]]> + </system-err> +</testsuite> diff --git a/tests/auto/testlib/selftests/generate_expected_output.py b/tests/auto/testlib/selftests/generate_expected_output.py index 175b5756a3..92588c614d 100755 --- a/tests/auto/testlib/selftests/generate_expected_output.py +++ b/tests/auto/testlib/selftests/generate_expected_output.py @@ -267,11 +267,14 @@ def baseEnv(platname=None, def testEnv(testname, # Make sure this matches tst_Selftests::doRunSubTest(): extraEnv = { - "crashers": { "QTEST_DISABLE_CORE_DUMP": "1", "QTEST_DISABLE_STACK_DUMP": "1" }, + "crashers": { "QTEST_DISABLE_CORE_DUMP": "1", + "QTEST_DISABLE_STACK_DUMP": "1" }, + "watchdog": { "QTEST_FUNCTION_TIMEOUT": "100" }, }, # Must match tst_Selftests::runSubTest_data(): - crashers = ("assert", "blacklisted", "crashes", "crashedterminate", "exceptionthrow", - "faildatatype", "failfetchtype", "fetchbogus", "silent")): + crashers = ("assert", "blacklisted", "crashes", "crashedterminate", + "exceptionthrow", "faildatatype", "failfetchtype", + "fetchbogus", "silent", "watchdog")): """Determine the environment in which to run a test.""" data = baseEnv() if testname in crashers: diff --git a/tests/auto/testlib/selftests/selftests.pri b/tests/auto/testlib/selftests/selftests.pri index 08d6d633f0..bc5a74a20a 100644 --- a/tests/auto/testlib/selftests/selftests.pri +++ b/tests/auto/testlib/selftests/selftests.pri @@ -50,6 +50,7 @@ SUBPROGRAMS = \ verbose2 \ verifyexceptionthrown \ warnings \ + watchdog \ xunit qtHaveModule(gui): SUBPROGRAMS += \ diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 5c97ad01d1..a5094c8b9e 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -505,6 +505,7 @@ void tst_Selftests::runSubTest_data() << "verifyexceptionthrown" #endif //!QT_NO_EXCEPTIONS << "warnings" + << "watchdog" << "xunit" ; @@ -621,7 +622,7 @@ void tst_Selftests::runSubTest_data() || subtest == QLatin1String("fetchbogus") || subtest == QLatin1String("crashedterminate") || subtest == QLatin1String("faildatatype") || subtest == QLatin1String("failfetchtype") || subtest == QLatin1String("crashes") || subtest == QLatin1String("silent") - || subtest == QLatin1String("blacklisted"); + || subtest == QLatin1String("blacklisted") || subtest == QLatin1String("watchdog"); QTest::newRow(qPrintable(QString("%1 %2").arg(subtest).arg(loggerSet.name))) << subtest << loggers @@ -700,6 +701,8 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge if (crashes) { environment.insert("QTEST_DISABLE_CORE_DUMP", "1"); environment.insert("QTEST_DISABLE_STACK_DUMP", "1"); + if (subdir == QLatin1String("watchdog")) + environment.insert("QTEST_FUNCTION_TIMEOUT", "100"); } proc.setProcessEnvironment(environment); const QString path = subdir + QLatin1Char('/') + subdir; @@ -742,6 +745,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge if (subdir != QLatin1String("exceptionthrow") && subdir != QLatin1String("cmptest") // QImage comparison requires QGuiApplication && subdir != QLatin1String("fetchbogus") + && subdir != QLatin1String("watchdog") && subdir != QLatin1String("xunit") #ifdef Q_CC_MINGW && subdir != QLatin1String("blacklisted") // calls qFatal() diff --git a/tests/auto/testlib/selftests/watchdog/tst_watchdog.cpp b/tests/auto/testlib/selftests/watchdog/tst_watchdog.cpp new file mode 100644 index 0000000000..2f29609f71 --- /dev/null +++ b/tests/auto/testlib/selftests/watchdog/tst_watchdog.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +class tst_Watchdog : public QObject +{ + Q_OBJECT +private slots: + void delay() const; +}; + +void tst_Watchdog::delay() const +{ + bool ok = false; + const int fiveMinutes = 5 * 60 * 1000; + // Use the same env.var as the watch-dog and add a little to it: + const int timeout = qEnvironmentVariableIntValue("QTEST_FUNCTION_TIMEOUT", &ok); + QTest::qSleep(5000 + (ok && timeout > 0 ? timeout : fiveMinutes)); + // The watchdog timer should have interrupted us by now. + QFAIL("ERROR: this function should be interrupted."); +} + +QTEST_APPLESS_MAIN(tst_Watchdog) + +#include "tst_watchdog.moc" diff --git a/tests/auto/testlib/selftests/watchdog/watchdog.pro b/tests/auto/testlib/selftests/watchdog/watchdog.pro new file mode 100644 index 0000000000..ddcc3f6ca2 --- /dev/null +++ b/tests/auto/testlib/selftests/watchdog/watchdog.pro @@ -0,0 +1,14 @@ +SOURCES += tst_watchdog.cpp +QT = core testlib + +darwin: CONFIG -= app_bundle +CONFIG -= debug_and_release_target + +TARGET = watchdog + +# The test deliberately times out; so tell it to do so quickly +checkenv.name = QTEST_FUNCTION_TIMEOUT +checkenv.value = 100 +QT_TOOL_ENV += checkenv + +include($$QT_SOURCE_TREE/src/testlib/selfcover.pri) |