QmlProfiler: Verify attached RunControl stops when connection closes

Change-Id: I2b7bd63c4e84fcb0e78318f810ed54e58468d05e
Task-number: QTCREATORBUG-19496
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2018-01-09 11:14:39 +01:00
parent becbcd4455
commit 58ae456f4b
8 changed files with 120 additions and 29 deletions

View File

@@ -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",

View File

@@ -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)

View File

@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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(connectionSpy.count() > 0);
QTRY_VERIFY(connection);
QTRY_VERIFY(runControl->isRunning());
connection.reset();
QTRY_VERIFY(runControl->isStopped());
}
} // namespace Internal

View File

@@ -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 \