2016-06-02 17:17:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 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 "localqmlprofilerrunner_test.h"
|
2017-05-09 10:25:11 +02:00
|
|
|
|
2016-06-02 17:17:20 +02:00
|
|
|
#include <debugger/analyzer/analyzermanager.h>
|
2018-05-16 15:42:03 +02:00
|
|
|
|
2017-08-10 11:46:31 +02:00
|
|
|
#include <qmlprofiler/qmlprofilerruncontrol.h>
|
2018-01-09 14:50:12 +01:00
|
|
|
#include <qmlprofiler/qmlprofilertool.h>
|
2017-05-29 16:04:31 +02:00
|
|
|
|
2017-09-29 12:41:53 +02:00
|
|
|
#include <utils/url.h>
|
2018-04-16 13:42:43 +02:00
|
|
|
#include <utils/temporaryfile.h>
|
2017-09-29 12:41:53 +02:00
|
|
|
|
2016-06-02 17:17:20 +02:00
|
|
|
#include <QtTest>
|
|
|
|
|
#include <QTcpServer>
|
|
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
LocalQmlProfilerRunnerTest::LocalQmlProfilerRunnerTest(QObject *parent) : QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalQmlProfilerRunnerTest::testRunner()
|
|
|
|
|
{
|
2018-02-15 14:40:18 +01:00
|
|
|
QmlProfilerTool tool;
|
2017-08-10 11:46:31 +02:00
|
|
|
QPointer<ProjectExplorer::RunControl> runControl;
|
|
|
|
|
QPointer<LocalQmlProfilerSupport> profiler;
|
2018-05-16 15:42:03 +02:00
|
|
|
ProjectExplorer::Runnable debuggee;
|
2017-08-10 11:46:31 +02:00
|
|
|
QUrl serverUrl;
|
|
|
|
|
|
|
|
|
|
bool running = false;
|
|
|
|
|
bool started = false;
|
|
|
|
|
int startCount = 0;
|
|
|
|
|
int runCount = 0;
|
|
|
|
|
int stopCount = 0;
|
|
|
|
|
|
2019-06-20 17:19:12 +02:00
|
|
|
debuggee.executable = Utils::FilePath::fromString("\\-/|\\-/");
|
2017-05-29 16:04:31 +02:00
|
|
|
debuggee.environment = Utils::Environment::systemEnvironment();
|
2016-07-04 17:36:59 +02:00
|
|
|
|
|
|
|
|
// should not be used anywhere but cannot be empty
|
2017-09-29 12:41:53 +02:00
|
|
|
serverUrl.setScheme(Utils::urlSocketScheme());
|
2017-06-13 11:43:04 +02:00
|
|
|
serverUrl.setPath("invalid");
|
2016-07-04 17:36:59 +02:00
|
|
|
|
2019-03-12 15:53:54 +01:00
|
|
|
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
2017-08-10 11:46:31 +02:00
|
|
|
runControl->setRunnable(debuggee);
|
2018-01-09 14:50:12 +01:00
|
|
|
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
2017-08-10 11:46:31 +02:00
|
|
|
|
|
|
|
|
auto connectRunner = [&]() {
|
|
|
|
|
connect(runControl, &ProjectExplorer::RunControl::aboutToStart, this, [&]() {
|
|
|
|
|
QVERIFY(!started);
|
|
|
|
|
QVERIFY(!running);
|
|
|
|
|
++startCount;
|
|
|
|
|
started = true;
|
|
|
|
|
});
|
|
|
|
|
connect(runControl, &ProjectExplorer::RunControl::started, this, [&]() {
|
|
|
|
|
QVERIFY(started);
|
|
|
|
|
QVERIFY(!running);
|
|
|
|
|
++runCount;
|
|
|
|
|
running = true;
|
|
|
|
|
});
|
|
|
|
|
connect(runControl, &ProjectExplorer::RunControl::stopped, this, [&]() {
|
|
|
|
|
QVERIFY(started);
|
|
|
|
|
++stopCount;
|
|
|
|
|
running = false;
|
|
|
|
|
started = false;
|
|
|
|
|
});
|
|
|
|
|
connect(runControl, &ProjectExplorer::RunControl::finished, this, [&]() {
|
|
|
|
|
running = false;
|
|
|
|
|
started = false;
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
connectRunner();
|
2016-06-02 17:17:20 +02:00
|
|
|
|
2018-05-28 18:22:54 +02:00
|
|
|
QTest::ignoreMessage(
|
|
|
|
|
QtDebugMsg, "Invalid run control state transition from "
|
|
|
|
|
"\"RunControlState::Starting\" to \"RunControlState::Stopped\"");
|
2017-08-10 11:46:31 +02:00
|
|
|
runControl->initiateStart();
|
2016-06-02 17:17:20 +02:00
|
|
|
|
2017-09-26 10:24:31 +02:00
|
|
|
QTRY_COMPARE_WITH_TIMEOUT(startCount, 1, 30000);
|
|
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!started, 30000);
|
2017-08-10 11:46:31 +02:00
|
|
|
QCOMPARE(stopCount, 1);
|
|
|
|
|
QCOMPARE(runCount, 0);
|
2016-06-02 17:17:20 +02:00
|
|
|
|
2017-08-10 11:46:31 +02:00
|
|
|
runControl->initiateFinish();
|
|
|
|
|
QTRY_VERIFY(runControl.isNull());
|
|
|
|
|
QVERIFY(profiler.isNull());
|
|
|
|
|
|
2017-09-29 12:41:53 +02:00
|
|
|
serverUrl = Utils::urlFromLocalSocket();
|
2019-06-20 17:19:12 +02:00
|
|
|
debuggee.executable = Utils::FilePath::fromString(QCoreApplication::applicationFilePath());
|
2016-07-04 17:36:59 +02:00
|
|
|
|
|
|
|
|
// comma is used to specify a test function. In this case, an invalid one.
|
2017-05-29 16:04:31 +02:00
|
|
|
debuggee.commandLineArguments = QString("-test QmlProfiler,");
|
2019-03-12 15:53:54 +01:00
|
|
|
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
2017-08-10 11:46:31 +02:00
|
|
|
runControl->setRunnable(debuggee);
|
2018-01-09 14:50:12 +01:00
|
|
|
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
2017-08-10 11:46:31 +02:00
|
|
|
connectRunner();
|
|
|
|
|
runControl->initiateStart();
|
2016-06-02 17:17:20 +02:00
|
|
|
|
2017-09-26 10:24:31 +02:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(running, 30000);
|
|
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!running, 30000);
|
2017-08-10 11:46:31 +02:00
|
|
|
QCOMPARE(startCount, 2);
|
|
|
|
|
QCOMPARE(stopCount, 2);
|
|
|
|
|
QCOMPARE(runCount, 1);
|
2016-06-02 17:17:20 +02:00
|
|
|
|
2017-08-10 11:46:31 +02:00
|
|
|
runControl->initiateFinish();
|
|
|
|
|
QTRY_VERIFY(runControl.isNull());
|
|
|
|
|
QVERIFY(profiler.isNull());
|
2016-06-02 17:17:20 +02:00
|
|
|
|
2017-08-10 11:46:31 +02:00
|
|
|
debuggee.commandLineArguments.clear();
|
|
|
|
|
serverUrl.clear();
|
2017-09-29 12:41:53 +02:00
|
|
|
serverUrl = Utils::urlFromLocalHostAndFreePort();
|
2019-03-12 15:53:54 +01:00
|
|
|
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
2017-08-10 11:46:31 +02:00
|
|
|
runControl->setRunnable(debuggee);
|
2018-01-09 14:50:12 +01:00
|
|
|
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
2017-08-10 11:46:31 +02:00
|
|
|
connectRunner();
|
|
|
|
|
runControl->initiateStart();
|
2017-03-13 13:48:55 +01:00
|
|
|
|
2017-09-26 10:24:31 +02:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(running, 30000);
|
2017-06-26 16:48:28 +02:00
|
|
|
runControl->initiateStop();
|
2017-09-26 10:24:31 +02:00
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!running, 30000);
|
2017-08-10 11:46:31 +02:00
|
|
|
QCOMPARE(startCount, 3);
|
|
|
|
|
QCOMPARE(stopCount, 3);
|
|
|
|
|
QCOMPARE(runCount, 2);
|
|
|
|
|
|
|
|
|
|
runControl->initiateFinish();
|
|
|
|
|
QTRY_VERIFY(runControl.isNull());
|
|
|
|
|
QVERIFY(profiler.isNull());
|
2018-04-16 13:42:43 +02:00
|
|
|
|
|
|
|
|
debuggee.commandLineArguments = QString("-test QmlProfiler,");
|
|
|
|
|
serverUrl.setScheme(Utils::urlSocketScheme());
|
|
|
|
|
{
|
|
|
|
|
Utils::TemporaryFile file("file with spaces");
|
|
|
|
|
if (file.open())
|
|
|
|
|
serverUrl.setPath(file.fileName());
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-12 15:53:54 +01:00
|
|
|
runControl = new ProjectExplorer::RunControl(ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
2018-04-16 13:42:43 +02:00
|
|
|
runControl->setRunnable(debuggee);
|
|
|
|
|
profiler = new LocalQmlProfilerSupport(&tool, runControl, serverUrl);
|
|
|
|
|
connectRunner();
|
|
|
|
|
runControl->initiateStart();
|
|
|
|
|
|
|
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(running, 30000);
|
|
|
|
|
QTRY_VERIFY_WITH_TIMEOUT(!running, 30000);
|
|
|
|
|
QCOMPARE(startCount, 4);
|
|
|
|
|
QCOMPARE(stopCount, 4);
|
|
|
|
|
QCOMPARE(runCount, 3);
|
|
|
|
|
|
|
|
|
|
runControl->initiateFinish();
|
|
|
|
|
QTRY_VERIFY(runControl.isNull());
|
|
|
|
|
QVERIFY(profiler.isNull());
|
2016-06-02 17:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalQmlProfilerRunnerTest::testFindFreePort()
|
|
|
|
|
{
|
2017-09-29 12:41:53 +02:00
|
|
|
QUrl serverUrl = Utils::urlFromLocalHostAndFreePort();
|
2017-06-13 11:43:04 +02:00
|
|
|
QVERIFY(serverUrl.port() != -1);
|
|
|
|
|
QVERIFY(!serverUrl.host().isEmpty());
|
2016-06-02 17:17:20 +02:00
|
|
|
QTcpServer server;
|
2017-06-13 11:43:04 +02:00
|
|
|
QVERIFY(server.listen(QHostAddress(serverUrl.host()), serverUrl.port()));
|
2016-06-02 17:17:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
|
|
|
|
|
{
|
2017-09-29 12:41:53 +02:00
|
|
|
QUrl serverUrl = Utils::urlFromLocalSocket();
|
2017-06-13 11:43:04 +02:00
|
|
|
QString socket = serverUrl.path();
|
2016-06-02 17:17:20 +02:00
|
|
|
QVERIFY(!socket.isEmpty());
|
|
|
|
|
QVERIFY(!QFile::exists(socket));
|
|
|
|
|
QFile file(socket);
|
|
|
|
|
QVERIFY(file.open(QIODevice::WriteOnly));
|
|
|
|
|
file.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|