Commit a8426626 authored by Ulf Hermann's avatar Ulf Hermann

QmlProfiler: Fix and extend the local qml profiler runner test

We need to indirectly verify that the profiler support is doing the
right thing by watching the RunControl's state transitions.

Change-Id: I8f92f21022668ed3bb28477152132ccdcffaaea6
Reviewed-by: default avatarhjk <hjk@qt.io>
parent f4f240ad
......@@ -25,17 +25,13 @@
#include "localqmlprofilerrunner_test.h"
#include "../qmlprofilerruncontrol.h"
#include <debugger/analyzer/analyzermanager.h>
#include <projectexplorer/runnables.h>
#include <qmlprofiler/qmlprofilerruncontrol.h>
#include <QtTest>
#include <QTcpServer>
using namespace ProjectExplorer;
namespace QmlProfiler {
namespace Internal {
......@@ -43,85 +39,115 @@ LocalQmlProfilerRunnerTest::LocalQmlProfilerRunnerTest(QObject *parent) : QObjec
{
}
void LocalQmlProfilerRunnerTest::start()
{
delete runControl;
runControl = new ProjectExplorer::RunControl(nullptr, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
auto runner = new LocalQmlProfilerSupport(runControl, serverUrl);
connect(runner, &LocalQmlProfilerSupport::localRunnerStarted, this, [this] {
QVERIFY(!running);
++runCount;
running = true;
});
connect(runner, &LocalQmlProfilerSupport::localRunnerStopped, this, [this] {
QVERIFY(running);
running = false;
});
runControl->initiateStart();
}
void LocalQmlProfilerRunnerTest::testRunner()
{
QPointer<ProjectExplorer::RunControl> runControl;
QPointer<LocalQmlProfilerSupport> profiler;
ProjectExplorer::StandardRunnable debuggee;
QUrl serverUrl;
bool running = false;
bool started = false;
int startCount = 0;
int runCount = 0;
int stopCount = 0;
debuggee.executable = "\\-/|\\-/";
debuggee.environment = Utils::Environment::systemEnvironment();
// should not be used anywhere but cannot be empty
serverUrl.setPath("invalid");
start();
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
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();
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner1);
QTRY_COMPARE_WITH_TIMEOUT(runControl, static_cast<ProjectExplorer::RunControl *>(nullptr), 70000);
}
runControl->initiateStart();
void LocalQmlProfilerRunnerTest::testRunner1()
{
QTRY_COMPARE_WITH_TIMEOUT(runCount, 1, 10000);
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
QTRY_COMPARE_WITH_TIMEOUT(startCount, 1, 10000);
QTRY_VERIFY_WITH_TIMEOUT(!started, 10000);
QCOMPARE(stopCount, 1);
QCOMPARE(runCount, 0);
serverUrl = urlFromLocalSocket();
runControl->initiateFinish();
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
serverUrl = ProjectExplorer::urlFromLocalSocket();
debuggee.executable = qApp->applicationFilePath();
debuggee.executable = QCoreApplication::applicationFilePath();
// comma is used to specify a test function. In this case, an invalid one.
debuggee.commandLineArguments = QString("-test QmlProfiler,");
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
connectRunner();
runControl->initiateStart();
start();
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner2);
}
void LocalQmlProfilerRunnerTest::testRunner2()
{
QTRY_COMPARE_WITH_TIMEOUT(runCount, 2, 10000);
QTRY_VERIFY_WITH_TIMEOUT(running, 10000);
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
QCOMPARE(startCount, 2);
QCOMPARE(stopCount, 2);
QCOMPARE(runCount, 1);
debuggee.commandLineArguments.clear();
serverUrl = urlFromLocalHostAndFreePort();
start();
runControl->initiateFinish();
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner3);
}
debuggee.commandLineArguments.clear();
serverUrl.clear();
serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort();
runControl = new ProjectExplorer::RunControl(nullptr,
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
runControl->setRunnable(debuggee);
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
connectRunner();
runControl->initiateStart();
void LocalQmlProfilerRunnerTest::testRunner3()
{
QTRY_COMPARE_WITH_TIMEOUT(runCount, 3, 10000);
QTRY_VERIFY_WITH_TIMEOUT(running, 10000);
runControl->initiateStop();
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner4);
}
void LocalQmlProfilerRunnerTest::testRunner4()
{
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
delete runControl;
runControl = nullptr;
QCOMPARE(startCount, 3);
QCOMPARE(stopCount, 3);
QCOMPARE(runCount, 2);
runControl->initiateFinish();
QTRY_VERIFY(runControl.isNull());
QVERIFY(profiler.isNull());
}
void LocalQmlProfilerRunnerTest::testFindFreePort()
{
QUrl serverUrl = urlFromLocalHostAndFreePort();
QUrl serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort();
QVERIFY(serverUrl.port() != -1);
QVERIFY(!serverUrl.host().isEmpty());
QTcpServer server;
......@@ -130,7 +156,7 @@ void LocalQmlProfilerRunnerTest::testFindFreePort()
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
{
QUrl serverUrl = urlFromLocalSocket();
QUrl serverUrl = ProjectExplorer::urlFromLocalSocket();
QString socket = serverUrl.path();
QVERIFY(!socket.isEmpty());
QVERIFY(!QFile::exists(socket));
......
......@@ -43,19 +43,6 @@ private slots:
void testRunner();
void testFindFreePort();
void testFindFreeSocket();
private:
void start();
void testRunner1();
void testRunner2();
void testRunner3();
void testRunner4();
bool running = false;
int runCount = 0;
ProjectExplorer::RunControl *runControl = nullptr;
ProjectExplorer::StandardRunnable debuggee;
QUrl serverUrl;
};
} // namespace Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment