forked from qt-creator/qt-creator
Debugger, QmlProfiler et al: Replace AnalyzerStartParameter
... and QmlProfilerRunner::Configuaration by PE::UrlConnection, and call it 'serverUrl' on the user side. That's the only variant we ever had and avoids "translations" between three structures that are essential the same. Change-Id: I33386b2b8d2a7985ff934f6f8f840de0831bf9c1 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -65,23 +65,10 @@ void QmlProfilerClientManager::setRetryParams(int interval, int maxAttempts)
|
||||
m_maximumRetries = maxAttempts;
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::setTcpConnection(QString host, Utils::Port port)
|
||||
void QmlProfilerClientManager::setServerUrl(const QUrl &server)
|
||||
{
|
||||
if (!m_localSocket.isEmpty() || m_tcpHost != host || m_tcpPort != port) {
|
||||
m_tcpHost = host;
|
||||
m_tcpPort = port;
|
||||
m_localSocket.clear();
|
||||
disconnectClient();
|
||||
stopConnectionTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void QmlProfilerClientManager::setLocalSocket(QString file)
|
||||
{
|
||||
if (m_localSocket != file || !m_tcpHost.isEmpty() || m_tcpPort.isValid()) {
|
||||
m_localSocket = file;
|
||||
m_tcpHost.clear();
|
||||
m_tcpPort = Utils::Port();
|
||||
if (m_server != server) {
|
||||
m_server = server;
|
||||
disconnectClient();
|
||||
stopConnectionTimer();
|
||||
}
|
||||
@@ -89,9 +76,7 @@ void QmlProfilerClientManager::setLocalSocket(QString file)
|
||||
|
||||
void QmlProfilerClientManager::clearConnection()
|
||||
{
|
||||
m_localSocket.clear();
|
||||
m_tcpHost.clear();
|
||||
m_tcpPort = Utils::Port();
|
||||
m_server.clear();
|
||||
disconnectClient();
|
||||
stopConnectionTimer();
|
||||
}
|
||||
@@ -115,7 +100,7 @@ void QmlProfilerClientManager::connectToTcpServer()
|
||||
if (m_connection.isNull()) {
|
||||
// If the previous connection failed, recreate it.
|
||||
createConnection();
|
||||
m_connection->connectToHost(m_tcpHost, m_tcpPort.number());
|
||||
m_connection->connectToHost(m_server.host(), m_server.port());
|
||||
} else if (m_numRetries < 3
|
||||
&& m_connection->socketState() != QAbstractSocket::ConnectedState) {
|
||||
// If we don't get connected in the first retry interval, drop the socket and try
|
||||
@@ -124,7 +109,7 @@ void QmlProfilerClientManager::connectToTcpServer()
|
||||
// On other operating systems (windows) every connection takes forever to get
|
||||
// established. So, after tearing down and rebuilding the socket twice, just
|
||||
// keep trying with the same one.
|
||||
m_connection->connectToHost(m_tcpHost, m_tcpPort.number());
|
||||
m_connection->connectToHost(m_server.host(), m_server.port());
|
||||
} // Else leave it alone and wait for hello.
|
||||
} else {
|
||||
// On final timeout, clear the connection.
|
||||
@@ -142,7 +127,7 @@ void QmlProfilerClientManager::connectToTcpServer()
|
||||
QTC_ASSERT(m_qmlclientplugin.isNull(), disconnectClient());
|
||||
createConnection();
|
||||
QTC_ASSERT(m_connection, emit connectionFailed(); return);
|
||||
m_connection->connectToHost(m_tcpHost, m_tcpPort.number());
|
||||
m_connection->connectToHost(m_server.host(), m_server.port());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +154,7 @@ void QmlProfilerClientManager::startLocalServer()
|
||||
QTC_ASSERT(m_qmlclientplugin.isNull(), disconnectClient());
|
||||
createConnection();
|
||||
QTC_ASSERT(m_connection, emit connectionFailed(); return);
|
||||
m_connection->startLocalServer(m_localSocket);
|
||||
m_connection->startLocalServer(m_server.path());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,9 +166,9 @@ void QmlProfilerClientManager::stopRecording()
|
||||
|
||||
void QmlProfilerClientManager::retryConnect()
|
||||
{
|
||||
if (!m_localSocket.isEmpty()) {
|
||||
if (m_server.scheme() == "socket") {
|
||||
startLocalServer();
|
||||
} else if (!m_tcpHost.isEmpty() && m_tcpPort.isValid()) {
|
||||
} else if (!m_server.host().isEmpty() && m_server.port() > -1) {
|
||||
disconnectClient();
|
||||
connectToTcpServer();
|
||||
} else {
|
||||
|
||||
@@ -28,12 +28,10 @@
|
||||
#include "qmlprofilertraceclient.h"
|
||||
|
||||
#include <qmldebug/qmldebugclient.h>
|
||||
#include <utils/port.h>
|
||||
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <QUrl>
|
||||
|
||||
namespace QmlProfiler {
|
||||
class QmlProfilerModelManager;
|
||||
@@ -49,8 +47,7 @@ public:
|
||||
~QmlProfilerClientManager();
|
||||
|
||||
void setProfilerStateManager(QmlProfilerStateManager *profilerState);
|
||||
void setTcpConnection(QString host, Utils::Port port);
|
||||
void setLocalSocket(QString file);
|
||||
void setServerUrl(const QUrl &server);
|
||||
void clearConnection();
|
||||
|
||||
void clearBufferedData();
|
||||
@@ -79,9 +76,7 @@ private:
|
||||
|
||||
QTimer m_connectionTimer;
|
||||
|
||||
QString m_localSocket;
|
||||
QString m_tcpHost;
|
||||
Utils::Port m_tcpPort;
|
||||
QUrl m_server;
|
||||
quint32 m_flushInterval = 0;
|
||||
|
||||
int m_retryInterval = 200;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "qmlprofilerplugin.h"
|
||||
|
||||
#include <debugger/analyzer/analyzermanager.h>
|
||||
#include <debugger/analyzer/analyzerstartparameters.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/helpmanager.h>
|
||||
@@ -37,7 +36,6 @@
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
#include <projectexplorer/environmentaspect.h>
|
||||
#include <projectexplorer/kitinformation.h>
|
||||
#include <projectexplorer/localapplicationruncontrol.h>
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectexplorericons.h>
|
||||
@@ -51,15 +49,11 @@
|
||||
#include <qmldebug/qmldebugcommandlinearguments.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/temporaryfile.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QMessageBox>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QTcpServer>
|
||||
#include <QTemporaryFile>
|
||||
#include <QTimer>
|
||||
|
||||
using namespace Debugger;
|
||||
@@ -79,7 +73,7 @@ public:
|
||||
QmlProfilerStateManager *m_profilerState = 0;
|
||||
QTimer m_noDebugOutputTimer;
|
||||
bool m_isLocal = false;
|
||||
QmlProfilerRunner::Configuration m_configuration;
|
||||
QUrl m_serverUrl;
|
||||
ProjectExplorer::ApplicationLauncher m_launcher;
|
||||
QmlDebug::QmlOutputParser m_outputParser;
|
||||
};
|
||||
@@ -116,29 +110,24 @@ void QmlProfilerRunner::start()
|
||||
Internal::QmlProfilerTool::instance()->finalizeRunControl(this);
|
||||
QTC_ASSERT(d->m_profilerState, return);
|
||||
|
||||
QTC_ASSERT(connection().is<AnalyzerConnection>(), return);
|
||||
auto conn = connection().as<AnalyzerConnection>();
|
||||
QTC_ASSERT(connection().is<UrlConnection>(), return);
|
||||
QUrl serverUrl = connection().as<UrlConnection>();
|
||||
|
||||
if (conn.analyzerPort.isValid()) {
|
||||
if (serverUrl.port() != -1) {
|
||||
auto clientManager = Internal::QmlProfilerTool::clientManager();
|
||||
clientManager->setTcpConnection(conn.analyzerHost, conn.analyzerPort);
|
||||
clientManager->setServerUrl(serverUrl);
|
||||
clientManager->connectToTcpServer();
|
||||
}
|
||||
else if (conn.analyzerSocket.isEmpty())
|
||||
else if (serverUrl.path().isEmpty())
|
||||
d->m_noDebugOutputTimer.start();
|
||||
|
||||
d->m_profilerState->setCurrentState(QmlProfilerStateManager::AppRunning);
|
||||
|
||||
if (d->m_isLocal) {
|
||||
QTC_ASSERT(!d->m_configuration.socket.isEmpty() || d->m_configuration.port.isValid(), return);
|
||||
QTC_ASSERT(!d->m_serverUrl.path().isEmpty() || d->m_serverUrl.port() != -1, return);
|
||||
|
||||
StandardRunnable debuggee = runnable().as<StandardRunnable>();
|
||||
QString arguments = d->m_configuration.socket.isEmpty() ?
|
||||
QmlDebug::qmlDebugTcpArguments(QmlDebug::QmlProfilerServices,
|
||||
d->m_configuration.port) :
|
||||
QmlDebug::qmlDebugLocalArguments(QmlDebug::QmlProfilerServices,
|
||||
d->m_configuration.socket);
|
||||
|
||||
QString arguments = QmlDebug::qmlDebugArguments(QmlDebug::QmlProfilerServices, d->m_serverUrl);
|
||||
|
||||
if (!debuggee.commandLineArguments.isEmpty())
|
||||
arguments += ' ' + debuggee.commandLineArguments;
|
||||
@@ -254,13 +243,15 @@ void QmlProfilerRunner::notifyRemoteSetupDone(Utils::Port port)
|
||||
{
|
||||
d->m_noDebugOutputTimer.stop();
|
||||
|
||||
if (!port.isValid()) {
|
||||
QTC_ASSERT(connection().is<AnalyzerConnection>(), return);
|
||||
port = connection().as<AnalyzerConnection>().analyzerPort;
|
||||
}
|
||||
QTC_ASSERT(connection().is<UrlConnection>(), return);
|
||||
QUrl serverUrl = connection().as<UrlConnection>();
|
||||
if (!port.isValid())
|
||||
port = Utils::Port(serverUrl.port());
|
||||
|
||||
if (port.isValid()) {
|
||||
serverUrl.setPort(port.number());
|
||||
auto clientManager = Internal::QmlProfilerTool::clientManager();
|
||||
clientManager->setTcpConnection(connection().as<AnalyzerConnection>().analyzerHost, port);
|
||||
clientManager->setServerUrl(serverUrl);
|
||||
clientManager->connectToTcpServer();
|
||||
}
|
||||
}
|
||||
@@ -291,33 +282,10 @@ void QmlProfilerRunner::profilerStateChanged()
|
||||
}
|
||||
}
|
||||
|
||||
QString QmlProfilerRunner::findFreeSocket()
|
||||
{
|
||||
Utils::TemporaryFile file("qmlprofiler-freesocket");
|
||||
if (file.open()) {
|
||||
return file.fileName();
|
||||
} else {
|
||||
qWarning() << "Could not open a temporary file to find a debug socket.";
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
Utils::Port QmlProfilerRunner::findFreePort(QString &host)
|
||||
{
|
||||
QTcpServer server;
|
||||
if (!server.listen(QHostAddress::LocalHost)
|
||||
&& !server.listen(QHostAddress::LocalHostIPv6)) {
|
||||
qWarning() << "Cannot open port on host for QML profiling.";
|
||||
return Utils::Port();
|
||||
}
|
||||
host = server.serverAddress().toString();
|
||||
return Utils::Port(server.serverPort());
|
||||
}
|
||||
|
||||
void QmlProfilerRunner::setLocalConfiguration(const Configuration &configuration)
|
||||
void QmlProfilerRunner::setServerUrl(const QUrl &serverUrl)
|
||||
{
|
||||
d->m_isLocal = true;
|
||||
d->m_configuration = configuration;
|
||||
d->m_serverUrl = serverUrl;
|
||||
connect(&d->m_launcher, &ApplicationLauncher::appendMessage,
|
||||
this, &QmlProfilerRunner::appendMessage);
|
||||
connect(this, &QmlProfilerRunner::localRunnerStopped,
|
||||
|
||||
@@ -45,11 +45,7 @@ public:
|
||||
QmlProfilerRunner(ProjectExplorer::RunControl *runControl);
|
||||
~QmlProfilerRunner() override;
|
||||
|
||||
struct Configuration {
|
||||
Utils::Port port;
|
||||
QString socket;
|
||||
};
|
||||
void setLocalConfiguration(const Configuration &conf);
|
||||
void setServerUrl(const QUrl &serverUrl);
|
||||
|
||||
void registerProfilerStateManager( QmlProfilerStateManager *profilerState );
|
||||
|
||||
@@ -58,9 +54,6 @@ public:
|
||||
void cancelProcess();
|
||||
void notifyRemoteFinished();
|
||||
|
||||
static Utils::Port findFreePort(QString &host);
|
||||
static QString findFreeSocket();
|
||||
|
||||
signals:
|
||||
void localRunnerStarted();
|
||||
void localRunnerStopped();
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "qmlprofilerrunconfigurationaspect.h"
|
||||
|
||||
#include <debugger/analyzer/analyzermanager.h>
|
||||
#include <debugger/analyzer/analyzerstartparameters.h>
|
||||
#include <debugger/debuggerrunconfigurationaspect.h>
|
||||
|
||||
#include <projectexplorer/environmentaspect.h>
|
||||
@@ -74,27 +73,23 @@ RunControl *QmlProfilerRunControlFactory::create(RunConfiguration *runConfigurat
|
||||
QTC_ASSERT(runConfiguration->runnable().is<StandardRunnable>(), return 0);
|
||||
|
||||
Kit *kit = runConfiguration->target()->kit();
|
||||
AnalyzerConnection connection;
|
||||
QUrl serverUrl;
|
||||
const QtSupport::BaseQtVersion *version = QtSupport::QtKitInformation::qtVersion(kit);
|
||||
if (version) {
|
||||
if (version->qtVersion() >= QtSupport::QtVersionNumber(5, 6, 0))
|
||||
connection.analyzerSocket = QmlProfilerRunner::findFreeSocket();
|
||||
serverUrl = UrlConnection::localSocket();
|
||||
else
|
||||
connection.analyzerPort = QmlProfilerRunner::findFreePort(connection.analyzerHost);
|
||||
serverUrl = UrlConnection::localHostAndFreePort();
|
||||
} else {
|
||||
qWarning() << "Running QML profiler on Kit without Qt version??";
|
||||
connection.analyzerPort = QmlProfilerRunner::findFreePort(connection.analyzerHost);
|
||||
qWarning("Running QML profiler on Kit without Qt version?");
|
||||
serverUrl = UrlConnection::localHostAndFreePort();
|
||||
}
|
||||
|
||||
auto runControl = new RunControl(runConfiguration, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->setConnection(connection);
|
||||
|
||||
QmlProfilerRunner::Configuration conf;
|
||||
conf.socket = connection.analyzerSocket;
|
||||
conf.port = connection.analyzerPort;
|
||||
runControl->setConnection(UrlConnection(serverUrl));
|
||||
|
||||
auto runner = new QmlProfilerRunner(runControl);
|
||||
runner->setLocalConfiguration(conf);
|
||||
runner->setServerUrl(serverUrl);
|
||||
return runControl;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
|
||||
#include <debugger/debuggericons.h>
|
||||
#include <debugger/analyzer/analyzermanager.h>
|
||||
#include <debugger/analyzer/analyzerstartparameters.h>
|
||||
|
||||
#include <utils/fancymainwindow.h>
|
||||
#include <utils/fileinprojectfinder.h>
|
||||
@@ -352,15 +351,14 @@ void QmlProfilerTool::finalizeRunControl(QmlProfilerRunner *runWorker)
|
||||
runWorker->registerProfilerStateManager(d->m_profilerState);
|
||||
QmlProfilerClientManager *clientManager = d->m_profilerConnections;
|
||||
|
||||
QTC_ASSERT(runWorker->connection().is<AnalyzerConnection>(), return);
|
||||
QTC_ASSERT(runWorker->connection().is<UrlConnection>(), return);
|
||||
// FIXME: Check that there's something sensible in sp.connParams
|
||||
auto connection = runWorker->connection().as<AnalyzerConnection>();
|
||||
if (!connection.analyzerSocket.isEmpty()) {
|
||||
clientManager->setLocalSocket(connection.analyzerSocket);
|
||||
auto serverUrl = runWorker->connection().as<UrlConnection>();
|
||||
clientManager->setServerUrl(serverUrl);
|
||||
if (!serverUrl.path().isEmpty()) {
|
||||
// That's the local socket case.
|
||||
// We open the server and the application connects to it, so let's do that right away.
|
||||
clientManager->startLocalServer();
|
||||
} else {
|
||||
clientManager->setTcpConnection(connection.analyzerHost, connection.analyzerPort);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -579,23 +577,21 @@ void QmlProfilerTool::startRemoteTool()
|
||||
settings->setValue(QLatin1String("AnalyzerQmlAttachDialog/port"), port);
|
||||
}
|
||||
|
||||
AnalyzerConnection connection;
|
||||
QUrl serverUrl;
|
||||
|
||||
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
|
||||
if (device) {
|
||||
Connection toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
|
||||
QTC_ASSERT(toolControl.is<HostName>(), return);
|
||||
connection.analyzerHost = toolControl.as<HostName>().host();
|
||||
connection.connParams = device->sshParameters();
|
||||
}
|
||||
connection.analyzerPort = Utils::Port(port);
|
||||
QTC_ASSERT(device, return);
|
||||
Connection toolControl = device->toolControlChannel(IDevice::QmlControlChannel);
|
||||
QTC_ASSERT(toolControl.is<HostName>(), return);
|
||||
serverUrl.setHost(toolControl.as<HostName>().host());
|
||||
serverUrl.setPort(port);
|
||||
|
||||
Debugger::selectPerspective(Constants::QmlProfilerPerspectiveId);
|
||||
|
||||
RunConfiguration *rc = Debugger::startupRunConfiguration();
|
||||
auto runControl = new RunControl(rc, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->createWorker(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
runControl->setConnection(connection);
|
||||
runControl->setConnection(UrlConnection(serverUrl));
|
||||
|
||||
ProjectExplorerPlugin::startRunControl(runControl);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "../qmlprofilerruncontrol.h"
|
||||
|
||||
#include <debugger/analyzer/analyzermanager.h>
|
||||
#include <debugger/analyzer/analyzerstartparameters.h>
|
||||
|
||||
#include <projectexplorer/runnables.h>
|
||||
|
||||
@@ -63,13 +62,13 @@ void LocalQmlProfilerRunnerTest::testRunner()
|
||||
debuggee.environment = Utils::Environment::systemEnvironment();
|
||||
|
||||
// should not be used anywhere but cannot be empty
|
||||
configuration.socket = connection.analyzerSocket = QString("invalid");
|
||||
serverUrl.setPath("invalid");
|
||||
|
||||
rc = new ProjectExplorer::RunControl(nullptr, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
rc->setRunnable(debuggee);
|
||||
rc->setConnection(connection);
|
||||
rc->setConnection(UrlConnection(serverUrl));
|
||||
auto runner = new QmlProfilerRunner(rc);
|
||||
runner->setLocalConfiguration(configuration);
|
||||
runner->setServerUrl(serverUrl);
|
||||
connectRunner(runner);
|
||||
|
||||
rc->initiateStart();
|
||||
@@ -81,7 +80,7 @@ void LocalQmlProfilerRunnerTest::testRunner1()
|
||||
QTRY_COMPARE_WITH_TIMEOUT(runCount, 1, 10000);
|
||||
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
|
||||
|
||||
configuration.socket = connection.analyzerSocket = QmlProfilerRunner::findFreeSocket();
|
||||
serverUrl = UrlConnection::localSocket();
|
||||
|
||||
debuggee.executable = QCoreApplication::applicationFilePath();
|
||||
// comma is used to specify a test function. In this case, an invalid one.
|
||||
@@ -90,9 +89,9 @@ void LocalQmlProfilerRunnerTest::testRunner1()
|
||||
delete rc;
|
||||
rc = new ProjectExplorer::RunControl(nullptr, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
rc->setRunnable(debuggee);
|
||||
rc->setConnection(connection);
|
||||
rc->setConnection(serverUrl);
|
||||
auto runner = new QmlProfilerRunner(rc);
|
||||
runner->setLocalConfiguration(configuration);
|
||||
runner->setServerUrl(serverUrl);
|
||||
connectRunner(runner);
|
||||
rc->initiateStart();
|
||||
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner2);
|
||||
@@ -106,15 +105,12 @@ void LocalQmlProfilerRunnerTest::testRunner2()
|
||||
delete rc;
|
||||
|
||||
debuggee.commandLineArguments.clear();
|
||||
configuration.socket.clear();
|
||||
connection.analyzerSocket.clear();
|
||||
configuration.port = connection.analyzerPort =
|
||||
QmlProfilerRunner::findFreePort(connection.analyzerHost);
|
||||
serverUrl = UrlConnection::localHostAndFreePort();
|
||||
rc = new ProjectExplorer::RunControl(nullptr, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||
rc->setRunnable(debuggee);
|
||||
rc->setConnection(connection);
|
||||
rc->setConnection(serverUrl);
|
||||
auto runner = new QmlProfilerRunner(rc);
|
||||
runner->setLocalConfiguration(configuration);
|
||||
runner->setServerUrl(serverUrl);
|
||||
connectRunner(runner);
|
||||
rc->initiateStart();
|
||||
|
||||
@@ -136,17 +132,17 @@ void LocalQmlProfilerRunnerTest::testRunner4()
|
||||
|
||||
void LocalQmlProfilerRunnerTest::testFindFreePort()
|
||||
{
|
||||
QString host;
|
||||
Utils::Port port = QmlProfilerRunner::findFreePort(host);
|
||||
QVERIFY(port.isValid());
|
||||
QVERIFY(!host.isEmpty());
|
||||
QUrl serverUrl = UrlConnection::localHostAndFreePort();
|
||||
QVERIFY(serverUrl.port() != -1);
|
||||
QVERIFY(!serverUrl.host().isEmpty());
|
||||
QTcpServer server;
|
||||
QVERIFY(server.listen(QHostAddress(host), port.number()));
|
||||
QVERIFY(server.listen(QHostAddress(serverUrl.host()), serverUrl.port()));
|
||||
}
|
||||
|
||||
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
|
||||
{
|
||||
QString socket = QmlProfilerRunner::findFreeSocket();
|
||||
QUrl serverUrl = UrlConnection::localSocket();
|
||||
QString socket = serverUrl.path();
|
||||
QVERIFY(!socket.isEmpty());
|
||||
QVERIFY(!QFile::exists(socket));
|
||||
QFile file(socket);
|
||||
|
||||
@@ -27,7 +27,8 @@
|
||||
|
||||
#include <qmlprofiler/qmlprofilermodelmanager.h>
|
||||
#include <qmlprofiler/qmlprofilerruncontrol.h>
|
||||
#include <debugger/analyzer/analyzerstartparameters.h>
|
||||
|
||||
#include <QUrl>
|
||||
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
@@ -54,8 +55,7 @@ private:
|
||||
int runCount = 0;
|
||||
ProjectExplorer::RunControl *rc = nullptr;
|
||||
ProjectExplorer::StandardRunnable debuggee;
|
||||
Debugger::AnalyzerConnection connection;
|
||||
QmlProfilerRunner::Configuration configuration;
|
||||
ProjectExplorer::UrlConnection serverUrl;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace QmlProfiler {
|
||||
namespace Internal {
|
||||
|
||||
@@ -68,34 +70,41 @@ void QmlProfilerClientManagerTest::testConnectionFailure_data()
|
||||
QTest::addColumn<QmlProfilerStateManager *>("stateManager");
|
||||
QVarLengthArray<QmlProfilerStateManager *> stateManagers({nullptr, &stateManager});
|
||||
|
||||
QString hostName;
|
||||
Utils::Port port = QmlProfilerRunner::findFreePort(hostName);
|
||||
QUrl localUrl = UrlConnection::localHostAndFreePort();
|
||||
|
||||
QTest::addColumn<QString>("host");
|
||||
QVarLengthArray<QString> hosts({"", "/-/|\\-\\|/-", hostName});
|
||||
|
||||
QTest::addColumn<Utils::Port>("port");
|
||||
QVarLengthArray<Utils::Port> ports({Utils::Port(), Utils::Port(5), port});
|
||||
|
||||
QTest::addColumn<QString>("socket");
|
||||
QVarLengthArray<QString> sockets({"", "/-/|\\-\\|/-", QmlProfilerRunner::findFreeSocket()});
|
||||
QTest::addColumn<QUrl>("serverUrl");
|
||||
QVarLengthArray<QString> hosts({"", "/-/|\\-\\|/-", localUrl.host()});
|
||||
QVarLengthArray<int> ports({-1, 5, localUrl.port()});
|
||||
QVarLengthArray<QString> sockets({"", "/-/|\\-\\|/-", UrlConnection::localSocket().path()});
|
||||
|
||||
foreach (QmlProfilerModelManager *modelManager, modelManagers) {
|
||||
foreach (QmlProfilerStateManager *stateManager, stateManagers) {
|
||||
foreach (QString host, hosts) {
|
||||
foreach (Utils::Port port, ports) {
|
||||
foreach (QString socket, sockets) {
|
||||
QString tag = QString::fromLatin1("%1, %2, %3, %4, %5")
|
||||
.arg(QLatin1String(modelManager ? "modelManager" : "<null>"))
|
||||
.arg(QLatin1String(stateManager ? "stateManager" : "<null>"))
|
||||
.arg(host.isEmpty() ? "<empty>" : host)
|
||||
.arg(port.isValid() ? port.number() : 0)
|
||||
.arg(socket.isEmpty() ? "<empty>" : socket);
|
||||
QTest::newRow(tag.toLatin1().constData())
|
||||
<< modelManager << stateManager << host << port << socket;
|
||||
}
|
||||
foreach (int port, ports) {
|
||||
QString tag = QString::fromLatin1("%1, %2, %3, %4, %5")
|
||||
.arg(QLatin1String(modelManager ? "modelManager" : "<null>"))
|
||||
.arg(QLatin1String(stateManager ? "stateManager" : "<null>"))
|
||||
.arg(host.isEmpty() ? "<empty>" : host)
|
||||
.arg(Utils::Port(port).isValid() ? port : 0)
|
||||
.arg("<empty>");
|
||||
QUrl url;
|
||||
url.setHost(host);
|
||||
url.setPort(port);
|
||||
QTest::newRow(tag.toLatin1().constData()) << modelManager << stateManager << url;
|
||||
}
|
||||
}
|
||||
foreach (QString socket, sockets) {
|
||||
QString tag = QString::fromLatin1("%1, %2, %3, %4, %5")
|
||||
.arg(QLatin1String(modelManager ? "modelManager" : "<null>"))
|
||||
.arg(QLatin1String(stateManager ? "stateManager" : "<null>"))
|
||||
.arg("<empty>")
|
||||
.arg(0)
|
||||
.arg(socket);
|
||||
QUrl url;
|
||||
url.setScheme(ProjectExplorer::UrlConnection::socketScheme());
|
||||
url.setPath(socket);
|
||||
QTest::newRow(tag.toLatin1().constData()) << modelManager << stateManager << url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,9 +127,7 @@ void QmlProfilerClientManagerTest::testConnectionFailure()
|
||||
|
||||
QFETCH(QmlProfilerModelManager *, modelManager);
|
||||
QFETCH(QmlProfilerStateManager *, stateManager);
|
||||
QFETCH(QString, host);
|
||||
QFETCH(Utils::Port, port);
|
||||
QFETCH(QString, socket);
|
||||
QFETCH(QUrl, serverUrl);
|
||||
|
||||
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
|
||||
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
|
||||
@@ -130,11 +137,7 @@ void QmlProfilerClientManagerTest::testConnectionFailure()
|
||||
|
||||
clientManager.setModelManager(modelManager);
|
||||
clientManager.setProfilerStateManager(stateManager);
|
||||
if (socket.isEmpty()) {
|
||||
clientManager.setTcpConnection(host, port);
|
||||
} else {
|
||||
clientManager.setLocalSocket(socket);
|
||||
}
|
||||
clientManager.setServerUrl(serverUrl);
|
||||
|
||||
QVERIFY(!clientManager.isConnected());
|
||||
|
||||
@@ -172,14 +175,13 @@ void QmlProfilerClientManagerTest::testUnresponsiveTcp()
|
||||
clientManager.setProfilerStateManager(&stateManager);
|
||||
clientManager.setModelManager(&modelManager);
|
||||
|
||||
QString hostName;
|
||||
Utils::Port port = QmlProfilerRunner::findFreePort(hostName);
|
||||
QUrl serverUrl = UrlConnection::localHostAndFreePort();
|
||||
|
||||
QTcpServer server;
|
||||
server.listen(QHostAddress(hostName), port.number());
|
||||
server.listen(QHostAddress(serverUrl.host()), serverUrl.port());
|
||||
QSignalSpy connectionSpy(&server, SIGNAL(newConnection()));
|
||||
|
||||
clientManager.setTcpConnection(hostName, port);
|
||||
clientManager.setServerUrl(serverUrl);
|
||||
clientManager.connectToTcpServer();
|
||||
|
||||
QTRY_VERIFY(connectionSpy.count() > 0);
|
||||
@@ -202,14 +204,14 @@ void QmlProfilerClientManagerTest::testUnresponsiveLocal()
|
||||
clientManager.setProfilerStateManager(&stateManager);
|
||||
clientManager.setModelManager(&modelManager);
|
||||
|
||||
QString socketFile = QmlProfilerRunner::findFreeSocket();
|
||||
QUrl socketUrl = UrlConnection::localSocket();
|
||||
QLocalSocket socket;
|
||||
QSignalSpy connectionSpy(&socket, SIGNAL(connected()));
|
||||
|
||||
clientManager.setLocalSocket(socketFile);
|
||||
clientManager.setServerUrl(socketUrl);
|
||||
clientManager.startLocalServer();
|
||||
|
||||
socket.connectToServer(socketFile);
|
||||
socket.connectToServer(socketUrl.path());
|
||||
QTRY_COMPARE(connectionSpy.count(), 1);
|
||||
QTRY_COMPARE(failedSpy.count(), 1);
|
||||
QCOMPARE(openedSpy.count(), 0);
|
||||
@@ -254,8 +256,7 @@ void QmlProfilerClientManagerTest::testResponsiveTcp()
|
||||
{
|
||||
QFETCH(quint32, flushInterval);
|
||||
|
||||
QString hostName;
|
||||
Utils::Port port = QmlProfilerRunner::findFreePort(hostName);
|
||||
QUrl serverUrl = UrlConnection::localHostAndFreePort();
|
||||
|
||||
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
|
||||
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
|
||||
@@ -270,7 +271,7 @@ void QmlProfilerClientManagerTest::testResponsiveTcp()
|
||||
fakeDebugServer(socket.data());
|
||||
});
|
||||
|
||||
server.listen(QHostAddress(hostName), port.number());
|
||||
server.listen(QHostAddress(serverUrl.host()), serverUrl.port());
|
||||
|
||||
clientManager.setProfilerStateManager(&stateManager);
|
||||
clientManager.setModelManager(&modelManager);
|
||||
@@ -279,7 +280,7 @@ void QmlProfilerClientManagerTest::testResponsiveTcp()
|
||||
connect(&clientManager, &QmlProfilerClientManager::connectionFailed,
|
||||
&clientManager, &QmlProfilerClientManager::retryConnect);
|
||||
|
||||
clientManager.setTcpConnection(hostName, port);
|
||||
clientManager.setServerUrl(serverUrl);
|
||||
clientManager.connectToTcpServer();
|
||||
|
||||
QTRY_COMPARE(openedSpy.count(), 1);
|
||||
@@ -314,7 +315,7 @@ void QmlProfilerClientManagerTest::testResponsiveLocal()
|
||||
{
|
||||
QFETCH(quint32, flushInterval);
|
||||
|
||||
QString socketFile = QmlProfilerRunner::findFreeSocket();
|
||||
QUrl socketUrl = UrlConnection::localSocket();
|
||||
|
||||
QSignalSpy openedSpy(&clientManager, SIGNAL(connectionOpened()));
|
||||
QSignalSpy closedSpy(&clientManager, SIGNAL(connectionClosed()));
|
||||
@@ -328,12 +329,12 @@ void QmlProfilerClientManagerTest::testResponsiveLocal()
|
||||
connect(&clientManager, &QmlProfilerClientManager::connectionFailed,
|
||||
&clientManager, &QmlProfilerClientManager::retryConnect);
|
||||
|
||||
clientManager.setLocalSocket(socketFile);
|
||||
clientManager.setServerUrl(socketUrl);
|
||||
clientManager.startLocalServer();
|
||||
|
||||
{
|
||||
QScopedPointer<QLocalSocket> socket(new QLocalSocket(this));
|
||||
socket->connectToServer(socketFile);
|
||||
socket->connectToServer(socketUrl.path());
|
||||
QVERIFY(socket->isOpen());
|
||||
fakeDebugServer(socket.data());
|
||||
|
||||
@@ -379,8 +380,7 @@ void QmlProfilerClientManagerTest::testInvalidData()
|
||||
clientManager.setProfilerStateManager(&stateManager);
|
||||
clientManager.setModelManager(&modelManager);
|
||||
|
||||
QString hostName;
|
||||
Utils::Port port = QmlProfilerRunner::findFreePort(hostName);
|
||||
QUrl serverUrl = UrlConnection::localHostAndFreePort();
|
||||
|
||||
bool dataSent = false;
|
||||
QTcpServer server;
|
||||
@@ -395,9 +395,9 @@ void QmlProfilerClientManagerTest::testInvalidData()
|
||||
dataSent = true;
|
||||
});
|
||||
|
||||
server.listen(QHostAddress(hostName), port.number());
|
||||
server.listen(QHostAddress(serverUrl.host()), serverUrl.port());
|
||||
|
||||
clientManager.setTcpConnection(hostName, port);
|
||||
clientManager.setServerUrl(serverUrl);
|
||||
clientManager.connectToTcpServer();
|
||||
|
||||
QTRY_VERIFY(dataSent);
|
||||
@@ -411,7 +411,7 @@ void QmlProfilerClientManagerTest::testInvalidData()
|
||||
|
||||
void QmlProfilerClientManagerTest::testStopRecording()
|
||||
{
|
||||
QString socketFile = QmlProfilerRunner::findFreeSocket();
|
||||
QUrl socketUrl = UrlConnection::localSocket();
|
||||
|
||||
{
|
||||
QmlProfilerClientManager clientManager;
|
||||
@@ -427,11 +427,11 @@ void QmlProfilerClientManagerTest::testStopRecording()
|
||||
connect(&clientManager, &QmlProfilerClientManager::connectionFailed,
|
||||
&clientManager, &QmlProfilerClientManager::retryConnect);
|
||||
|
||||
clientManager.setLocalSocket(socketFile);
|
||||
clientManager.setServerUrl(socketUrl);
|
||||
clientManager.startLocalServer();
|
||||
|
||||
QScopedPointer<QLocalSocket> socket(new QLocalSocket(this));
|
||||
socket->connectToServer(socketFile);
|
||||
socket->connectToServer(socketUrl.path());
|
||||
QVERIFY(socket->isOpen());
|
||||
fakeDebugServer(socket.data());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user