From: Kai Koehne Date: Fri, 20 Apr 2012 09:53:45 +0000 (+0200) Subject: Debugger: Improve autotest output on failure X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=47927c1f5309ad2465858bfb07b316a1d9e0685d;p=konrad%2Fqtdeclarative.git Debugger: Improve autotest output on failure Change-Id: Ia463b198b5d6dac8e480d141412cb4475e54d204 Reviewed-by: Aurindam Jana --- diff --git a/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp b/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp index 2961ced..a258028 100644 --- a/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp +++ b/tests/auto/qml/debugger/qv8profilerservice/tst_qv8profilerservice.cpp @@ -142,7 +142,7 @@ private: QQmlDebugConnection *m_connection; QV8ProfilerClient *m_client; - void connect(bool block, const QString &testFile); + bool connect(bool block, const QString &testFile, QString *error); private slots: void cleanup(); @@ -201,7 +201,8 @@ void QV8ProfilerClient::messageReceived(const QByteArray &message) QVERIFY(stream.atEnd()); } -void tst_QV8ProfilerService::connect(bool block, const QString &testFile) +bool tst_QV8ProfilerService::connect(bool block, const QString &testFile, + QString *error) { const QString executable = QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene"; QStringList arguments; @@ -213,19 +214,22 @@ void tst_QV8ProfilerService::connect(bool block, const QString &testFile) arguments << QQmlDataTest::instance()->testFile(testFile); + m_connection = new QQmlDebugConnection(); + m_client = new QV8ProfilerClient(m_connection); + m_process = new QQmlDebugProcess(executable); m_process->start(QStringList() << arguments); if (!m_process->waitForSessionStart()) { - QString failMsg = QString("Could not launch app '%1'.").arg(executable); - QFAIL(qPrintable(failMsg)); + *error = QLatin1String("Could not launch app ") + executable; + return false; } - m_connection = new QQmlDebugConnection(); - m_client = new QV8ProfilerClient(m_connection); - m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT); - if (!m_connection->waitForConnected()) - QFAIL("Could not connect to debugger port."); + if (!m_connection->waitForConnected()) { + *error = QLatin1String("Could not connect to debugger port."); + return false; + } + return true; } void tst_QV8ProfilerService::cleanup() @@ -233,13 +237,17 @@ void tst_QV8ProfilerService::cleanup() if (QTest::currentTestFailed()) qDebug() << "Application Output:" << m_process->output(); + delete m_client; delete m_process; delete m_connection; } void tst_QV8ProfilerService::blockingConnectWithTraceEnabled() { - connect(true, "test.qml"); + QString error; + if (!connect(true, "test.qml", &error)) + QFAIL(qPrintable(error)); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->startProfiling(""); @@ -250,7 +258,10 @@ void tst_QV8ProfilerService::blockingConnectWithTraceEnabled() void tst_QV8ProfilerService::blockingConnectWithTraceDisabled() { - connect(true, "test.qml"); + QString error; + if (!connect(true, "test.qml", &error)) + QFAIL(qPrintable(error)); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->stopProfiling(""); @@ -267,7 +278,10 @@ void tst_QV8ProfilerService::blockingConnectWithTraceDisabled() void tst_QV8ProfilerService::nonBlockingConnect() { - connect(false, "test.qml"); + QString error; + if (!connect(false, "test.qml", &error)) + QFAIL(qPrintable(error)); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->startProfiling(""); @@ -278,7 +292,10 @@ void tst_QV8ProfilerService::nonBlockingConnect() void tst_QV8ProfilerService::snapshot() { - connect(false, "test.qml"); + QString error; + if (!connect(false, "test.qml", &error)) + QFAIL(qPrintable(error)); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->takeSnapshot(); @@ -288,7 +305,10 @@ void tst_QV8ProfilerService::snapshot() void tst_QV8ProfilerService::profileOnExit() { - connect(true, "exit.qml"); + QString error; + if (!connect(true, "exit.qml", &error)) + QFAIL(qPrintable(error)); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->startProfiling(""); @@ -299,7 +319,10 @@ void tst_QV8ProfilerService::profileOnExit() void tst_QV8ProfilerService::console() { - connect(true, "console.qml"); + QString error; + if (!connect(true, "console.qml", &error)) + QFAIL(qPrintable(error)); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->stopProfiling(""); diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index 925f537..eea777f 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -65,7 +65,7 @@ QByteArray QQmlDebugTestClient::waitForResponse() lastMsg.clear(); QQmlDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray))); if (lastMsg.isEmpty()) { - qWarning() << "tst_QQmlDebugTestClient: no response from server!"; + qWarning() << "no response from server!"; return QByteArray(); } return lastMsg; @@ -91,7 +91,7 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable) m_timer.setSingleShot(true); m_timer.setInterval(5000); connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput())); - connect(&m_timer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit())); + connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); } QQmlDebugProcess::~QQmlDebugProcess() @@ -117,6 +117,13 @@ void QQmlDebugProcess::stop() } } +void QQmlDebugProcess::timeout() +{ + qWarning() << "Timeout while waiting for QML debugging messages " + "in application output"; + m_eventLoop.quit(); +} + bool QQmlDebugProcess::waitForSessionStart() { if (m_process.state() != QProcess::Running) { @@ -153,14 +160,17 @@ void QQmlDebugProcess::processAppOutput() const QString line = m_outputBuffer.left(nlIndex); m_outputBuffer = m_outputBuffer.right(m_outputBuffer.size() - nlIndex - 1); - if (line.startsWith("QML debugging is enabled")) // ignore - continue; if (line.startsWith("QML Debugger:")) { if (line.contains("Waiting for connection ")) { m_started = true; m_eventLoop.quit(); continue; } + if (line.contains("Unable to listen")) { + qWarning() << "App was unable to bind to port!"; + m_eventLoop.quit(); + continue; + } } } m_mutex.unlock(); diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h index 4350056..0b3b8ec 100644 --- a/tests/auto/qml/debugger/shared/debugutil_p.h +++ b/tests/auto/qml/debugger/shared/debugutil_p.h @@ -96,6 +96,7 @@ public: void stop(); private slots: + void timeout(); void processAppOutput(); private: