forked from qt-creator/qt-creator
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: hjk <hjk@qt.io>
This commit is contained in:
@@ -25,17 +25,13 @@
|
|||||||
|
|
||||||
#include "localqmlprofilerrunner_test.h"
|
#include "localqmlprofilerrunner_test.h"
|
||||||
|
|
||||||
#include "../qmlprofilerruncontrol.h"
|
|
||||||
|
|
||||||
#include <debugger/analyzer/analyzermanager.h>
|
#include <debugger/analyzer/analyzermanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/runnables.h>
|
#include <projectexplorer/runnables.h>
|
||||||
|
#include <qmlprofiler/qmlprofilerruncontrol.h>
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
|
||||||
|
|
||||||
namespace QmlProfiler {
|
namespace QmlProfiler {
|
||||||
namespace Internal {
|
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()
|
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.executable = "\\-/|\\-/";
|
||||||
debuggee.environment = Utils::Environment::systemEnvironment();
|
debuggee.environment = Utils::Environment::systemEnvironment();
|
||||||
|
|
||||||
// should not be used anywhere but cannot be empty
|
// should not be used anywhere but cannot be empty
|
||||||
serverUrl.setPath("invalid");
|
serverUrl.setPath("invalid");
|
||||||
|
|
||||||
start();
|
runControl = new ProjectExplorer::RunControl(nullptr,
|
||||||
|
ProjectExplorer::Constants::QML_PROFILER_RUN_MODE);
|
||||||
|
runControl->setRunnable(debuggee);
|
||||||
|
profiler = new LocalQmlProfilerSupport(runControl, serverUrl);
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner1);
|
auto connectRunner = [&]() {
|
||||||
QTRY_COMPARE_WITH_TIMEOUT(runControl, static_cast<ProjectExplorer::RunControl *>(nullptr), 70000);
|
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;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
void LocalQmlProfilerRunnerTest::testRunner1()
|
connectRunner();
|
||||||
{
|
|
||||||
QTRY_COMPARE_WITH_TIMEOUT(runCount, 1, 10000);
|
|
||||||
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
|
|
||||||
|
|
||||||
serverUrl = urlFromLocalSocket();
|
runControl->initiateStart();
|
||||||
|
|
||||||
|
QTRY_COMPARE_WITH_TIMEOUT(startCount, 1, 10000);
|
||||||
|
QTRY_VERIFY_WITH_TIMEOUT(!started, 10000);
|
||||||
|
QCOMPARE(stopCount, 1);
|
||||||
|
QCOMPARE(runCount, 0);
|
||||||
|
|
||||||
|
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.
|
// comma is used to specify a test function. In this case, an invalid one.
|
||||||
debuggee.commandLineArguments = QString("-test QmlProfiler,");
|
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();
|
QTRY_VERIFY_WITH_TIMEOUT(running, 10000);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
runControl->initiateFinish();
|
||||||
|
QTRY_VERIFY(runControl.isNull());
|
||||||
|
QVERIFY(profiler.isNull());
|
||||||
|
|
||||||
debuggee.commandLineArguments.clear();
|
debuggee.commandLineArguments.clear();
|
||||||
serverUrl = urlFromLocalHostAndFreePort();
|
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();
|
||||||
|
|
||||||
start();
|
QTRY_VERIFY_WITH_TIMEOUT(running, 10000);
|
||||||
|
|
||||||
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalQmlProfilerRunnerTest::testRunner3()
|
|
||||||
{
|
|
||||||
QTRY_COMPARE_WITH_TIMEOUT(runCount, 3, 10000);
|
|
||||||
runControl->initiateStop();
|
runControl->initiateStop();
|
||||||
QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner4);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalQmlProfilerRunnerTest::testRunner4()
|
|
||||||
{
|
|
||||||
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
|
QTRY_VERIFY_WITH_TIMEOUT(!running, 10000);
|
||||||
delete runControl;
|
QCOMPARE(startCount, 3);
|
||||||
runControl = nullptr;
|
QCOMPARE(stopCount, 3);
|
||||||
|
QCOMPARE(runCount, 2);
|
||||||
|
|
||||||
|
runControl->initiateFinish();
|
||||||
|
QTRY_VERIFY(runControl.isNull());
|
||||||
|
QVERIFY(profiler.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalQmlProfilerRunnerTest::testFindFreePort()
|
void LocalQmlProfilerRunnerTest::testFindFreePort()
|
||||||
{
|
{
|
||||||
QUrl serverUrl = urlFromLocalHostAndFreePort();
|
QUrl serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort();
|
||||||
QVERIFY(serverUrl.port() != -1);
|
QVERIFY(serverUrl.port() != -1);
|
||||||
QVERIFY(!serverUrl.host().isEmpty());
|
QVERIFY(!serverUrl.host().isEmpty());
|
||||||
QTcpServer server;
|
QTcpServer server;
|
||||||
@@ -130,7 +156,7 @@ void LocalQmlProfilerRunnerTest::testFindFreePort()
|
|||||||
|
|
||||||
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
|
void LocalQmlProfilerRunnerTest::testFindFreeSocket()
|
||||||
{
|
{
|
||||||
QUrl serverUrl = urlFromLocalSocket();
|
QUrl serverUrl = ProjectExplorer::urlFromLocalSocket();
|
||||||
QString socket = serverUrl.path();
|
QString socket = serverUrl.path();
|
||||||
QVERIFY(!socket.isEmpty());
|
QVERIFY(!socket.isEmpty());
|
||||||
QVERIFY(!QFile::exists(socket));
|
QVERIFY(!QFile::exists(socket));
|
||||||
|
|||||||
@@ -43,19 +43,6 @@ private slots:
|
|||||||
void testRunner();
|
void testRunner();
|
||||||
void testFindFreePort();
|
void testFindFreePort();
|
||||||
void testFindFreeSocket();
|
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
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user