diff options
author | dac <qt-info@nokia.com> | 2010-08-13 12:51:15 +1000 |
---|---|---|
committer | dac <qt-info@nokia.com> | 2010-08-13 12:51:15 +1000 |
commit | dea2f1eb79583641554c3bcca2a242f8393ddab9 (patch) | |
tree | b17fb545ecdb5688e768f92f30966d7e87c53bc0 | |
parent | 9b7866146ecfb43efca089134880a8c45810bd04 (diff) |
Make testing more robust, by trying to close old instances of test
applications that have not been properly shutdown.
-rw-r--r-- | libqsystemtest/desktoptestcontrol.cpp | 17 | ||||
-rw-r--r-- | libqsystemtest/desktoptestcontrol.h | 5 | ||||
-rw-r--r-- | libqsystemtest/qsystemtest.cpp | 21 | ||||
-rw-r--r-- | libqsystemtest/qtestresult.cpp | 8 | ||||
-rw-r--r-- | libqsystemtest/testcontrol.cpp | 13 | ||||
-rw-r--r-- | libqsystemtest/testcontrol.h | 4 | ||||
-rw-r--r-- | libqtslave/qtestslave.cpp | 11 | ||||
-rw-r--r-- | plugins/styles/qtuitest/style.cpp | 17 |
8 files changed, 68 insertions, 28 deletions
diff --git a/libqsystemtest/desktoptestcontrol.cpp b/libqsystemtest/desktoptestcontrol.cpp index 43a55d8..2a284fc 100644 --- a/libqsystemtest/desktoptestcontrol.cpp +++ b/libqsystemtest/desktoptestcontrol.cpp @@ -21,7 +21,6 @@ DesktopTestControl::DesktopTestControl() DesktopTestControl::~DesktopTestControl() { - } bool DesktopTestControl::deviceConfiguration( QString &reply ) @@ -34,7 +33,7 @@ bool DesktopTestControl::startApplication( const QString &application, const QSt bool styleQtUITest, const QStringList &environment, QString &reply ) { proc = new Qt4Test::TestProcess(this); - + connect(proc, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(onFinished())); proc->setEnvironment(environment); // FIXME proc->test = this; QStringList args = arguments; @@ -71,10 +70,12 @@ bool DesktopTestControl::killApplication( const QString &application, QString &r if (!proc) return false; - proc->terminate(); - if (!proc->waitForFinished(5000)) { - proc->kill(); - proc->waitForFinished(5000); + if (proc->state() != QProcess::NotRunning) { + proc->terminate(); + if (!proc->waitForFinished(5000)) { + proc->kill(); + proc->waitForFinished(5000); + } } delete proc; @@ -83,3 +84,7 @@ bool DesktopTestControl::killApplication( const QString &application, QString &r return true; } +void DesktopTestControl::onFinished() +{ + app_name = ""; +}
\ No newline at end of file diff --git a/libqsystemtest/desktoptestcontrol.h b/libqsystemtest/desktoptestcontrol.h index 9b1a301..6b80a09 100644 --- a/libqsystemtest/desktoptestcontrol.h +++ b/libqsystemtest/desktoptestcontrol.h @@ -111,8 +111,11 @@ public: bool styleQtUITest, const QStringList &environment, QString &reply ); bool killApplication( const QString &application, QString &reply ); +private slots: + void onFinished(); + private: - TestProcess* proc; + QPointer<TestProcess> proc; }; } diff --git a/libqsystemtest/qsystemtest.cpp b/libqsystemtest/qsystemtest.cpp index 892aadf..d579eb0 100644 --- a/libqsystemtest/qsystemtest.cpp +++ b/libqsystemtest/qsystemtest.cpp @@ -2241,11 +2241,30 @@ void QSystemTest::startApplication( const QString &application, const QStringLis return; } if (!reply.isEmpty()) testOutputPane()->append(reply); +#else + Q_UNUSED(ok) #endif + } else { + //TODO: Need better error message + fail("No device controller"); + return; } // Give it a little time for the slave to come up. - wait(100); + wait(200); + + if (!device_controller->isApplicationRunning(app, reply)) { + qWarning() << "Test application has not started correctly"; + if (connectToAut(timeout)) { + qWarning() << "An old test application instance is still running; trying to shut it down..."; + QTestMessage quitMsg("terminate"); + QTestMessage response; + quitMsg["expectClose"] = true; + m_test_app->sendMessage( quitMsg, response, 2000 ); + disconnectFromAut(); + bool ok = device_controller->startApplication(app, args, true, m_run_environment, reply); + } + } if (!connectToAut(timeout)) { device_controller->killApplications(); diff --git a/libqsystemtest/qtestresult.cpp b/libqsystemtest/qtestresult.cpp index 33e1b5f..4e1b57b 100644 --- a/libqsystemtest/qtestresult.cpp +++ b/libqsystemtest/qtestresult.cpp @@ -1137,7 +1137,6 @@ bool equalConfigs( const QString &c1, const QString &c2 ) } else if (tmp_c2 == "-no-xft") { cl3_count--; } else { -// qDebug( "cl3 = " + tmp_c1 + ", cl4 = " + tmp_c2); return FALSE; } } @@ -2256,8 +2255,6 @@ QTestResultTestFunc* QTestResultTestCase::findFunction( const QString &funcName void QTestResultTestCase::setCurrentTestFunction( const QString &funcName ) { -// qDebug() << "QTestResultTestCase::setCurrentTestFunction()" << funcName; - if (funcName.isEmpty()) { if ( cur_func == 0 ) return; @@ -2681,15 +2678,12 @@ uint QTestResultTestFunc::passCount() { uint count = 0; QTestResultTestData *d = first_data; -qDebug() << func_name; while (d != 0) { -//dac if (d->result() == QTestBase::PassSelf || d->result() == QTestBase::PassCompile || d->result() == QTestBase::PassTest || d->result() == QTestBase::PassScript) { -qDebug() << " " << d->name() << d->dataTag(); count++; } d = d->next(); @@ -2904,8 +2898,6 @@ QTestResultTestData::QTestResultTestData( const QString &dataName, bool skipAll, QTestResultTestData::~QTestResultTestData() { -// qDebug( QString( "QTestResultTestData::~QTestResultTestData()... %1").arg(data_name).toLatin1() ); - delete next_data; next_data = 0; } diff --git a/libqsystemtest/testcontrol.cpp b/libqsystemtest/testcontrol.cpp index 8333c3d..3cf2069 100644 --- a/libqsystemtest/testcontrol.cpp +++ b/libqsystemtest/testcontrol.cpp @@ -80,6 +80,7 @@ TestController::~TestController() TestControl* TestController::controlFactory() { + //FIXME: Old TestControls should be reused, but that isn't happening, so this leaks if (test_device_type == Maemo) return new MaemoTestControl(ssh_param); else if (test_device_type == Desktop) @@ -138,4 +139,16 @@ void TestController::killApplications() } } +bool TestController::isApplicationRunning( const QString &application, QString &reply ) +{ + TestControl *ctrl = 0; + for (int i=0; i<device_controls.count(); i++) { + ctrl = device_controls.at(i); + if (ctrl && ctrl->application() == application) { + return true; + } + } + return false; +} + } // namespace Qt4Test diff --git a/libqsystemtest/testcontrol.h b/libqsystemtest/testcontrol.h index efe85e1..beca79b 100644 --- a/libqsystemtest/testcontrol.h +++ b/libqsystemtest/testcontrol.h @@ -40,6 +40,7 @@ #include <QtCore/QSharedPointer> #include <QHash> #include <QStringList> +#include <QPointer> namespace Qt4Test { @@ -79,6 +80,7 @@ public: bool styleQtUITest, const QStringList &environment, QString &reply ); bool killApplication( const QString &application, QString &reply ); void killApplications(); + bool isApplicationRunning( const QString &application, QString &reply ); protected: Core::SshConnectionParameters ssh_param; @@ -87,7 +89,7 @@ protected: TestControl* controlFactory(); private: - QList<TestControl*> device_controls; + QList< QPointer<TestControl> > device_controls; }; diff --git a/libqtslave/qtestslave.cpp b/libqtslave/qtestslave.cpp index a4ac20a..9a4a666 100644 --- a/libqtslave/qtestslave.cpp +++ b/libqtslave/qtestslave.cpp @@ -216,6 +216,7 @@ public slots: QTestMessage checkOS (QTestMessage const&); QTestMessage targetIdentifier (QTestMessage const&); QTestMessage setTargetIdentifier(QTestMessage const&); + QTestMessage terminate (QTestMessage const&); void sendBecameIdleMessage(); @@ -1705,20 +1706,26 @@ QTestMessage QTestSlavePrivate::checkOS( QTestMessage const &message ) return RET(reply, "OK"); } -QTestMessage QTestSlavePrivate::targetIdentifier(QTestMessage const&message) +QTestMessage QTestSlavePrivate::targetIdentifier(QTestMessage const &message) { QTestMessage reply; reply["targetIdentifier"] = targetId; return RET(reply, "OK"); } -QTestMessage QTestSlavePrivate::setTargetIdentifier(QTestMessage const&message) +QTestMessage QTestSlavePrivate::setTargetIdentifier(QTestMessage const &message) { QTestMessage reply; targetId = message["targetIdentifier"]; return RET(reply, "OK"); } +QTestMessage QTestSlavePrivate::terminate(QTestMessage const &message) +{ + Q_UNUSED(message); + exit(0); +} + bool QTestSlavePrivate::event(QEvent *e) { if ((int)IdleEvent::Type != (int)e->type()) return false; diff --git a/plugins/styles/qtuitest/style.cpp b/plugins/styles/qtuitest/style.cpp index 1b8d75f..c602969 100644 --- a/plugins/styles/qtuitest/style.cpp +++ b/plugins/styles/qtuitest/style.cpp @@ -108,7 +108,7 @@ void TestSlaveServer::startService() qWarning("QtUiTest: Start service"); for (int index = 0; index < args.count(); index++){ - if (args[index].endsWith("qtuitestrunner")){ + if (args[index].endsWith("qtuitestrunner")) { if (showDebug) qWarning() << "QtUiTest: Not starting TestSlaveServer::startService for qtuitestrunner"; return; @@ -121,24 +121,24 @@ void TestSlaveServer::startService() close(); } - if (!autPortEnv.isEmpty()){ + if (!autPortEnv.isEmpty()) { aut_port = autPortEnv.toUShort(&parseOk); if (!parseOk){ aut_port = DEFAULT_AUT_PORT; qWarning() << "QtUiTest: Unable to parse QTUITEST_PORT" << autPortEnv; - }else{ + } else { setAutPort = true; if (showDebug) qWarning() << "QtUiTest: Set port via QTUITEST_PORT to" << aut_port; } } - for (int index = 0; index < args.count(); index++){ + for (int index = 0; index < args.count(); index++) { if ((args[index] == QLatin1String("-autport")) && (index + 1 < args.count())){ aut_port = args[index + 1].toUShort(&parseOk); - if (!parseOk){ + if (!parseOk) { aut_port = DEFAULT_AUT_PORT; qWarning() << "QtUiTest: Unable to parse -autport" << args[index]; - }else{ + } else { setAutPort = true; if (showDebug) qWarning() << "QtUiTest: Set port via -autport to" << aut_port; @@ -149,9 +149,8 @@ void TestSlaveServer::startService() if (!listen(QHostAddress::Any, aut_port)) { qWarning() << "QtUiTest: couldn't listen for connections on " << aut_port << " :" << errorString() << " started :" << started; - started = false; - close(); - }else { + exit(-1); + } else { started = true; if (showDebug) qWarning() << "QtUiTest: listening for connections on" << aut_port; |