aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-01-09 11:14:39 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-01-09 17:02:05 +0000
commit58ae456f4be17ffcb749143d47388207fb2f7ead (patch)
treeab5d93052aceecf216959f9e126e0c448c26f0b9
parentbecbcd4455a0062de91673337e8275862aedb64b (diff)
QmlProfiler: Verify attached RunControl stops when connection closes
Change-Id: I2b7bd63c4e84fcb0e78318f810ed54e58468d05e Task-number: QTCREATORBUG-19496 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/plugins/qmlprofiler/qmlprofiler.qbs1
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertool.cpp13
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertool.h8
-rw-r--r--src/plugins/qmlprofiler/tests/fakedebugserver.cpp51
-rw-r--r--src/plugins/qmlprofiler/tests/fakedebugserver.h36
-rw-r--r--src/plugins/qmlprofiler/tests/qmlprofilerclientmanager_test.cpp20
-rw-r--r--src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp18
-rw-r--r--src/plugins/qmlprofiler/tests/tests.pri2
8 files changed, 120 insertions, 29 deletions
diff --git a/src/plugins/qmlprofiler/qmlprofiler.qbs b/src/plugins/qmlprofiler/qmlprofiler.qbs
index 5e7f52193a..5a2f4b6ebb 100644
--- a/src/plugins/qmlprofiler/qmlprofiler.qbs
+++ b/src/plugins/qmlprofiler/qmlprofiler.qbs
@@ -77,6 +77,7 @@ QtcPlugin {
prefix: "tests/"
files: [
"debugmessagesmodel_test.cpp", "debugmessagesmodel_test.h",
+ "fakedebugserver.cpp", "fakedebugserver.h",
"flamegraphmodel_test.cpp", "flamegraphmodel_test.h",
"flamegraphview_test.cpp", "flamegraphview_test.h",
"inputeventsmodel_test.cpp", "inputeventsmodel_test.h",
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.cpp b/src/plugins/qmlprofiler/qmlprofilertool.cpp
index 99c2cf1286..cb2bcb59a8 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertool.cpp
@@ -526,10 +526,10 @@ bool QmlProfilerTool::prepareTool()
return true;
}
-void QmlProfilerTool::attachToWaitingApplication()
+ProjectExplorer::RunControl *QmlProfilerTool::attachToWaitingApplication()
{
if (!prepareTool())
- return;
+ return nullptr;
Id kitId;
int port;
@@ -547,12 +547,12 @@ void QmlProfilerTool::attachToWaitingApplication()
dialog.setPort(port);
if (dialog.exec() != QDialog::Accepted)
- return;
+ return nullptr;
kit = dialog.kit();
port = dialog.port();
- QTC_ASSERT(port >= 0, return);
- QTC_ASSERT(port <= std::numeric_limits<quint16>::max(), return);
+ QTC_ASSERT(port >= 0, return nullptr);
+ QTC_ASSERT(port <= std::numeric_limits<quint16>::max(), return nullptr);
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/kitId"), kit->id().toSetting());
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/port"), port);
@@ -561,7 +561,7 @@ void QmlProfilerTool::attachToWaitingApplication()
QUrl serverUrl;
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
- QTC_ASSERT(device, return);
+ QTC_ASSERT(device, return nullptr);
QUrl toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
serverUrl.setScheme(Utils::urlTcpScheme());
serverUrl.setHost(toolControl.host());
@@ -577,6 +577,7 @@ void QmlProfilerTool::attachToWaitingApplication()
connect(d->m_profilerConnections, &QmlProfilerClientManager::connectionClosed,
runControl, &RunControl::initiateStop);
ProjectExplorerPlugin::startRunControl(runControl);
+ return runControl;
}
void QmlProfilerTool::logState(const QString &msg)
diff --git a/src/plugins/qmlprofiler/qmlprofilertool.h b/src/plugins/qmlprofiler/qmlprofilertool.h
index 334e51aeed..0c21087400 100644
--- a/src/plugins/qmlprofiler/qmlprofilertool.h
+++ b/src/plugins/qmlprofiler/qmlprofilertool.h
@@ -32,6 +32,12 @@
#include <QAction>
#include <QObject>
+namespace ProjectExplorer {
+
+class RunControl;
+
+}
+
namespace QmlProfiler {
class QmlProfilerRunner;
@@ -53,7 +59,7 @@ public:
void finalizeRunControl(QmlProfilerRunner *runWorker);
bool prepareTool();
- void attachToWaitingApplication();
+ ProjectExplorer::RunControl *attachToWaitingApplication();
static QList <QAction *> profilerContextMenuActions();
diff --git a/src/plugins/qmlprofiler/tests/fakedebugserver.cpp b/src/plugins/qmlprofiler/tests/fakedebugserver.cpp
new file mode 100644
index 0000000000..88f5825fec
--- /dev/null
+++ b/src/plugins/qmlprofiler/tests/fakedebugserver.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** 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.
+**
+****************************************************************************/
+
+#include "fakedebugserver.h"
+#include <qmldebug/qpacketprotocol.h>
+
+namespace QmlProfiler {
+namespace Internal {
+
+void fakeDebugServer(QIODevice *socket)
+{
+ QmlDebug::QPacketProtocol *protocol = new QmlDebug::QPacketProtocol(socket, socket);
+ QObject::connect(protocol, &QmlDebug::QPacketProtocol::readyRead, [protocol]() {
+ QmlDebug::QPacket packet(QDataStream::Qt_4_7);
+ const int messageId = 0;
+ const int protocolVersion = 1;
+ const QStringList pluginNames({"CanvasFrameRate", "EngineControl", "DebugMessages"});
+ const QList<float> pluginVersions({1.0f, 1.0f, 1.0f});
+
+ packet << QString::fromLatin1("QDeclarativeDebugClient") << messageId << protocolVersion
+ << pluginNames << pluginVersions << QDataStream::Qt_DefaultCompiledVersion;
+ protocol->send(packet.data());
+ protocol->disconnect();
+ protocol->deleteLater();
+ });
+}
+
+} // namespace Internal
+} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tests/fakedebugserver.h b/src/plugins/qmlprofiler/tests/fakedebugserver.h
new file mode 100644
index 0000000000..6a74c5482e
--- /dev/null
+++ b/src/plugins/qmlprofiler/tests/fakedebugserver.h
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** 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.
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QIODevice>
+
+namespace QmlProfiler {
+namespace Internal {
+
+void fakeDebugServer(QIODevice *socket);
+
+} // namespace Internal
+} // namespace QmlProfiler
diff --git a/src/plugins/qmlprofiler/tests/qmlprofilerclientmanager_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilerclientmanager_test.cpp
index 5b37f7f96f..cd9b821ff7 100644
--- a/src/plugins/qmlprofiler/tests/qmlprofilerclientmanager_test.cpp
+++ b/src/plugins/qmlprofiler/tests/qmlprofilerclientmanager_test.cpp
@@ -24,8 +24,8 @@
****************************************************************************/
#include "qmlprofilerclientmanager_test.h"
+#include "fakedebugserver.h"
#include <qmlprofiler/qmlprofilerruncontrol.h>
-#include <qmldebug/qpacketprotocol.h>
#include <projectexplorer/applicationlauncher.h>
#include <utils/url.h>
@@ -222,24 +222,6 @@ void QmlProfilerClientManagerTest::testResponsiveTcp_data()
responsiveTestData();
}
-void fakeDebugServer(QIODevice *socket)
-{
- QmlDebug::QPacketProtocol *protocol = new QmlDebug::QPacketProtocol(socket, socket);
- QObject::connect(protocol, &QmlDebug::QPacketProtocol::readyRead, [protocol]() {
- QmlDebug::QPacket packet(QDataStream::Qt_4_7);
- const int messageId = 0;
- const int protocolVersion = 1;
- const QStringList pluginNames({"CanvasFrameRate", "EngineControl", "DebugMessages"});
- const QList<float> pluginVersions({1.0f, 1.0f, 1.0f});
-
- packet << QString::fromLatin1("QDeclarativeDebugClient") << messageId << protocolVersion
- << pluginNames << pluginVersions << QDataStream::Qt_DefaultCompiledVersion;
- protocol->send(packet.data());
- protocol->disconnect();
- protocol->deleteLater();
- });
-}
-
void QmlProfilerClientManagerTest::testResponsiveTcp()
{
QFETCH(quint32, flushInterval);
diff --git a/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp
index 62670e7a0c..2d5fd1cdaa 100644
--- a/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp
+++ b/src/plugins/qmlprofiler/tests/qmlprofilertool_test.cpp
@@ -24,7 +24,9 @@
****************************************************************************/
#include "qmlprofilertool_test.h"
+#include "fakedebugserver.h"
+#include <projectexplorer/runconfiguration.h>
#include <qmlprofiler/qmlprofilerclientmanager.h>
#include <qmlprofiler/qmlprofilerattachdialog.h>
#include <utils/url.h>
@@ -43,7 +45,12 @@ void QmlProfilerToolTest::testAttachToWaitingApplication()
QVERIFY(serverUrl.port() >= 0);
QVERIFY(serverUrl.port() <= std::numeric_limits<quint16>::max());
server.listen(QHostAddress(serverUrl.host()), static_cast<quint16>(serverUrl.port()));
- QSignalSpy connectionSpy(&server, SIGNAL(newConnection()));
+
+ QScopedPointer<QTcpSocket> connection;
+ connect(&server, &QTcpServer::newConnection, this, [&]() {
+ connection.reset(server.nextPendingConnection());
+ fakeDebugServer(connection.data());
+ });
QTimer timer;
timer.setInterval(100);
@@ -56,9 +63,14 @@ void QmlProfilerToolTest::testAttachToWaitingApplication()
});
timer.start();
- profilerTool->attachToWaitingApplication();
+ ProjectExplorer::RunControl *runControl = profilerTool->attachToWaitingApplication();
+ QVERIFY(runControl);
+
+ QTRY_VERIFY(connection);
+ QTRY_VERIFY(runControl->isRunning());
- QTRY_VERIFY(connectionSpy.count() > 0);
+ connection.reset();
+ QTRY_VERIFY(runControl->isStopped());
}
} // namespace Internal
diff --git a/src/plugins/qmlprofiler/tests/tests.pri b/src/plugins/qmlprofiler/tests/tests.pri
index 998010f326..eee511e93f 100644
--- a/src/plugins/qmlprofiler/tests/tests.pri
+++ b/src/plugins/qmlprofiler/tests/tests.pri
@@ -1,5 +1,6 @@
SOURCES += \
$$PWD/debugmessagesmodel_test.cpp \
+ $$PWD/fakedebugserver.cpp \
$$PWD/flamegraphmodel_test.cpp \
$$PWD/flamegraphview_test.cpp \
$$PWD/inputeventsmodel_test.cpp \
@@ -22,6 +23,7 @@ SOURCES += \
HEADERS += \
$$PWD/debugmessagesmodel_test.h \
+ $$PWD/fakedebugserver.h \
$$PWD/flamegraphmodel_test.h \
$$PWD/flamegraphview_test.h \
$$PWD/inputeventsmodel_test.h \