Add a testlib selftest for the watchdog
Verify that it does cut in after the specified time has elapsed. Task-number: QTPM-1385 Change-Id: Ib18e8d6af28339f79cca4d62b869287ce07b8cc1 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>bb10
parent
c3e6551d4d
commit
7c7e007794
|
|
@ -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"/>
|
||||
|
|
@ -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
|
||||
|
|
@ -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']
|
||||
|
|
@ -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 *********
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ SUBPROGRAMS = \
|
|||
verbose2 \
|
||||
verifyexceptionthrown \
|
||||
warnings \
|
||||
watchdog \
|
||||
xunit
|
||||
|
||||
qtHaveModule(gui): SUBPROGRAMS += \
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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)
|
||||
Loading…
Reference in New Issue