diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-16 12:47:07 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2017-09-06 09:19:52 +0000 |
commit | bb72fddebcf5ef6bed9d9c77d2317383a2a096ce (patch) | |
tree | 9ba98fe57b81c8640456de73295af02a722c3daf /tests/auto/qml/debugger | |
parent | c915f03303f53b0e1aa2796ae980b9ec63984105 (diff) |
Fix remaining race conditions in QQmlDebugProcess
If the process generated a "Cannot listen" message before we
waitForSessionStart(), we would never quit the nested event loop. Also,
unrelated output was not always forwarded, and the event loop was not
terminated when the process unexpectedly stopped.
Also, the timer was started when the process started, not when we
started waiting and we don't want to report the process as crashed if we
kill it ourselves.
In turn, we remove the remaining blacklists.
Task-number: QTQAINFRA-1334
Change-Id: I711aea373911d380f882b00f6d88627edc9f2415
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/debugger')
10 files changed, 220 insertions, 20 deletions
diff --git a/tests/auto/qml/debugger/debugger.pro b/tests/auto/qml/debugger/debugger.pro index a50411e18b..63721cc575 100644 --- a/tests/auto/qml/debugger/debugger.pro +++ b/tests/auto/qml/debugger/debugger.pro @@ -10,7 +10,8 @@ PUBLICTESTS += \ qqmlenginedebuginspectorintegrationtest \ qqmlenginecontrol \ qqmldebuggingenabler \ - qqmlnativeconnector + qqmlnativeconnector \ + qqmldebugprocess PRIVATETESTS += \ qqmldebugclient \ diff --git a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess.pro b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess.pro new file mode 100644 index 0000000000..331d87b9f1 --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = qqmldebugprocess qqmldebugprocessprocess + +qqmldebugprocess.depends = qqmldebugprocessprocess diff --git a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/qqmldebugprocess.pro b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/qqmldebugprocess.pro new file mode 100644 index 0000000000..9bea2d222c --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/qqmldebugprocess.pro @@ -0,0 +1,14 @@ +CONFIG += testcase +TARGET = tst_qqmldebugprocess +QT = core testlib +CONFIG -= debug_and_release_target +macos:CONFIG -= app_bundle + +SOURCES += \ + ../../shared/qqmldebugprocess.cpp \ + tst_qqmldebugprocess.cpp + +HEADERS += \ + ../../shared/qqmldebugprocess_p.h + +INCLUDEPATH += ../../shared diff --git a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp new file mode 100644 index 0000000000..993a1d5f63 --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocess/tst_qqmldebugprocess.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 <qqmldebugprocess_p.h> +#include <QtTest> + +#include <QtCore/qcoreapplication.h> +#include <QtCore/qscopedpointer.h> + +class tst_QQmlDebugProcess : public QObject +{ + Q_OBJECT + +private slots: + void sessionStart_data(); + void sessionStart(); +}; + +void tst_QQmlDebugProcess::sessionStart_data() +{ + QTest::addColumn<int>("delay"); + QTest::addColumn<QString>("arg"); + QTest::addColumn<bool>("sessionExpected"); + QTest::addColumn<bool>("outputExpected"); + + QTest::addRow("synchronous / waiting") << -1 + << "QML Debugger: Waiting for connection on port 2423..." + << true << false; + QTest::addRow("synchronous / failed") << -1 << "QML Debugger: Unable to listen to port 242." + << false << false; + QTest::addRow("synchronous / unknown") << -1 << "QML Debugger: You don't know this string." + << false << true; + QTest::addRow("synchronous / appout") << -1 << "Output from app itself." + << false << true; + + QTest::addRow("no delay / waiting") << 0 + << "QML Debugger: Waiting for connection on port 2423..." + << true << false; + QTest::addRow("no delay / failed") << 0 << "QML Debugger: Unable to listen to port 242." + << false << false; + QTest::addRow("no delay / unknown") << 0 << "QML Debugger: You don't know this string." + << false << true; + QTest::addRow("no delay / appout") << 0 << "Output from app itself." + << false << true; + + QTest::addRow("delay / waiting") << 1000 + << "QML Debugger: Waiting for connection on port 2423..." + << true << false; + QTest::addRow("delay / failed") << 1000 << "QML Debugger: Unable to listen to port 242." + << false << false; + QTest::addRow("delay / unknown") << 1000 << "QML Debugger: You don't know this string." + << false << true; + QTest::addRow("delay / appout") << 1000 << "Output from app itself." + << false << true; +} + +void tst_QQmlDebugProcess::sessionStart() +{ + QFETCH(int, delay); + QFETCH(QString, arg); + QFETCH(bool, sessionExpected); + QFETCH(bool, outputExpected); + + QScopedPointer<QQmlDebugProcess> process( + new QQmlDebugProcess(QCoreApplication::applicationDirPath() + + QLatin1String("/qqmldebugprocessprocess"), this)); + QVERIFY(process); + + bool outputReceived = false; + connect(process.data(), &QQmlDebugProcess::readyReadStandardOutput, this, [&]() { + QVERIFY(outputExpected); + QVERIFY(!outputReceived); + QCOMPARE(process->output().trimmed(), arg); + outputReceived = true; + QTimer::singleShot(qMax(delay, 0), process.data(), &QQmlDebugProcess::stop); + }); + + if (!outputExpected && !sessionExpected) + QTest::ignoreMessage(QtWarningMsg, "App was unable to bind to port!"); + process->start(QStringList({arg})); + + bool done = false; + auto wait = [&](){ + QCOMPARE(process->waitForSessionStart(), sessionExpected); + QCOMPARE(outputReceived, outputExpected); + process->stop(); + done = true; + }; + + if (delay < 0) + wait(); + else + QTimer::singleShot(delay, process.data(), wait); + + QTRY_VERIFY(done); + QVERIFY(process->state().startsWith("not running")); +} + +QTEST_MAIN(tst_QQmlDebugProcess) + +#include "tst_qqmldebugprocess.moc" diff --git a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocessprocess/qqmldebugprocessprocess.cpp b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocessprocess/qqmldebugprocessprocess.cpp new file mode 100644 index 0000000000..21cce53fc3 --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocessprocess/qqmldebugprocessprocess.cpp @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 <QtCore/qdebug.h> +#include <QtCore/qcoreapplication.h> + +// Process that just outputs a fake "Waiting" message. +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + if (argc > 1) + qDebug() << argv[1]; + return app.exec(); +} diff --git a/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocessprocess/qqmldebugprocessprocess.pro b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocessprocess/qqmldebugprocessprocess.pro new file mode 100644 index 0000000000..55a77d830d --- /dev/null +++ b/tests/auto/qml/debugger/qqmldebugprocess/qqmldebugprocessprocess/qqmldebugprocessprocess.pro @@ -0,0 +1,10 @@ +QT = core +macos:CONFIG -= app_bundle +CONFIG -= debug_and_release_target +SOURCES += qqmldebugprocessprocess.cpp + +DESTDIR = ../qqmldebugprocess + +target.path = $$[QT_INSTALL_TESTS]/tst_qqmldebugprocess +INSTALLS += target + diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/BLACKLIST b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/BLACKLIST deleted file mode 100644 index 5fb1dc193b..0000000000 --- a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -# QTQAINFRA-1334 -windows gcc diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/BLACKLIST b/tests/auto/qml/debugger/qqmlprofilerservice/BLACKLIST deleted file mode 100644 index 5fb1dc193b..0000000000 --- a/tests/auto/qml/debugger/qqmlprofilerservice/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -# QTQAINFRA-1334 -windows gcc diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp index e9ba7c3957..816fec6a2f 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp @@ -35,7 +35,7 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) : QObject(parent) , m_executable(executable) - , m_started(false) + , m_state(SessionUnknown) , m_port(0) , m_maximumBindErrors(0) , m_receivedBindErrors(0) @@ -47,6 +47,11 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) this, &QQmlDebugProcess::processAppOutput); connect(&m_process, &QProcess::errorOccurred, this, &QQmlDebugProcess::processError); + connect(&m_process, static_cast<void(QProcess::*)(int)>(&QProcess::finished), + this, [this]() { + m_timer.stop(); + m_eventLoop.quit(); + }); connect(&m_timer, &QTimer::timeout, this, &QQmlDebugProcess::timeout); } @@ -99,8 +104,6 @@ void QQmlDebugProcess::start(const QStringList &arguments) qWarning() << "QML Debug Client: Could not launch app " << m_executable << ": " << m_process.errorString(); m_eventLoop.quit(); - } else { - m_timer.start(); } m_mutex.unlock(); } @@ -108,6 +111,7 @@ void QQmlDebugProcess::start(const QStringList &arguments) void QQmlDebugProcess::stop() { if (m_process.state() != QProcess::NotRunning) { + disconnect(&m_process, &QProcess::errorOccurred, this, &QQmlDebugProcess::processError); m_process.kill(); m_process.waitForFinished(5000); } @@ -131,12 +135,16 @@ bool QQmlDebugProcess::waitForSessionStart() if (m_process.state() != QProcess::Running) { qWarning() << "Could not start up " << m_executable; return false; - } else if (m_started) { + } else if (m_state == SessionStarted) { return true; + } else if (m_state == SessionFailed) { + return false; } + + m_timer.start(); m_eventLoop.exec(); - return m_started; + return m_state == SessionStarted; } int QQmlDebugProcess::debugPort() const @@ -186,7 +194,7 @@ void QQmlDebugProcess::processAppOutput() if (portRx.indexIn(line) != -1) { m_port = portRx.cap(1).toInt(); m_timer.stop(); - m_started = true; + m_state = SessionStarted; m_eventLoop.quit(); continue; } @@ -195,14 +203,15 @@ void QQmlDebugProcess::processAppOutput() if (m_maximumBindErrors == 0) qWarning() << "App was unable to bind to port!"; m_timer.stop(); + m_state = SessionFailed; m_eventLoop.quit(); } continue; } - } else { - // set to true if there is output not coming from the debugger - outputFromAppItself = true; } + + // set to true if there is output not coming from the debugger or we don't understand it + outputFromAppItself = true; } m_mutex.unlock(); @@ -212,9 +221,6 @@ void QQmlDebugProcess::processAppOutput() void QQmlDebugProcess::processError(QProcess::ProcessError error) { - if (!m_eventLoop.isRunning()) - return; - qDebug() << "An error occurred while waiting for debug process to become available:"; switch (error) { case QProcess::FailedToStart: @@ -236,6 +242,4 @@ void QQmlDebugProcess::processError(QProcess::ProcessError error) qDebug() << "Unknown process error."; break; } - - m_eventLoop.exit(); } diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h b/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h index 8e4602ace1..fd2c89bb41 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess_p.h @@ -76,6 +76,12 @@ private slots: void processError(QProcess::ProcessError error); private: + enum SessionState { + SessionUnknown, + SessionStarted, + SessionFailed + }; + QString m_executable; QProcess m_process; QString m_outputBuffer; @@ -83,7 +89,7 @@ private: QTimer m_timer; QEventLoop m_eventLoop; QMutex m_mutex; - bool m_started; + SessionState m_state; QStringList m_environment; int m_port; int m_maximumBindErrors; |