From 9966cc4bcc6d3859f28454c3b53a1d1525803cfa Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 13 Aug 2021 13:30:43 +0200 Subject: [PATCH] Start and stop the process launcher in tst_qtcprocess Change-Id: Ib28450d10c699abe3964f8bef2ff24baae0074f7 Reviewed-by: hjk Reviewed-by: Christian Stenger --- src/libs/utils/launcherinterface.cpp | 13 +++++++------ src/libs/utils/launcherinterface.h | 2 +- tests/auto/utils/qtcprocess/CMakeLists.txt | 4 ++++ tests/auto/utils/qtcprocess/qtcprocess.pro | 4 ++++ tests/auto/utils/qtcprocess/qtcprocess.qbs | 14 ++++++++++---- tests/auto/utils/qtcprocess/tst_qtcprocess.cpp | 9 +++++++++ 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/libs/utils/launcherinterface.cpp b/src/libs/utils/launcherinterface.cpp index 1c67ff9959e..4f03c2be6c1 100644 --- a/src/libs/utils/launcherinterface.cpp +++ b/src/libs/utils/launcherinterface.cpp @@ -90,6 +90,7 @@ public: void handleProcessStderr(); Internal::LauncherSocket *socket() const { return m_socket; } + void setPathToLauncher(const QString &path) { if (!path.isEmpty()) m_pathToLauncher = path; } signals: void errorOccurred(const QString &error); @@ -97,13 +98,14 @@ private: QLocalServer * const m_server; Internal::LauncherSocket *const m_socket; Internal::LauncherProcess *m_process = nullptr; + QString m_pathToLauncher; int m_startRequests = 0; - }; LauncherInterfacePrivate::LauncherInterfacePrivate() : m_server(new QLocalServer(this)), m_socket(new LauncherSocket(this)) { + m_pathToLauncher = qApp->applicationDirPath() + '/' + QLatin1String(RELATIVE_LIBEXEC_PATH); QObject::connect(m_server, &QLocalServer::newConnection, this, &LauncherInterfacePrivate::handleNewConnection); } @@ -130,10 +132,8 @@ void LauncherInterfacePrivate::doStart() this, &LauncherInterfacePrivate::handleProcessFinished); connect(m_process, &QProcess::readyReadStandardError, this, &LauncherInterfacePrivate::handleProcessStderr); - m_process->start(qApp->applicationDirPath() + QLatin1Char('/') - + QLatin1String(RELATIVE_LIBEXEC_PATH) - + QLatin1String("/qtcreator_processlauncher"), - QStringList(m_server->fullServerName())); + const QString launcherPath = m_pathToLauncher + QLatin1String("/qtcreator_processlauncher"); + m_process->start(launcherPath, QStringList(m_server->fullServerName())); } void LauncherInterfacePrivate::doStop() @@ -208,9 +208,10 @@ LauncherInterface::~LauncherInterface() m_thread.wait(); } -void LauncherInterface::startLauncher() +void LauncherInterface::startLauncher(const QString &pathToLauncher) { // Call in launcher's thread. + instance().m_private->setPathToLauncher(pathToLauncher); QMetaObject::invokeMethod(instance().m_private, &LauncherInterfacePrivate::doStart); } diff --git a/src/libs/utils/launcherinterface.h b/src/libs/utils/launcherinterface.h index d274c5ca51c..ffafe26a5c1 100644 --- a/src/libs/utils/launcherinterface.h +++ b/src/libs/utils/launcherinterface.h @@ -48,7 +48,7 @@ public: static LauncherInterface &instance(); ~LauncherInterface() override; - static void startLauncher(); + static void startLauncher(const QString &pathToLauncher = {}); static void stopLauncher(); static Internal::LauncherSocket *socket(); diff --git a/tests/auto/utils/qtcprocess/CMakeLists.txt b/tests/auto/utils/qtcprocess/CMakeLists.txt index 16b9f4a9fa6..daa4dea7d12 100644 --- a/tests/auto/utils/qtcprocess/CMakeLists.txt +++ b/tests/auto/utils/qtcprocess/CMakeLists.txt @@ -1,4 +1,8 @@ +file(RELATIVE_PATH RELATIVE_TEST_PATH "${PROJECT_BINARY_DIR}" "${CMAKE_CURRENT_BINARY_DIR}") +file(RELATIVE_PATH TEST_RELATIVE_LIBEXEC_PATH "/${RELATIVE_TEST_PATH}" "/${IDE_LIBEXEC_PATH}") + add_qtc_test(tst_qtcprocess + DEFINES "TEST_RELATIVE_LIBEXEC_PATH=\"${TEST_RELATIVE_LIBEXEC_PATH}\"" DEPENDS Utils SOURCES tst_qtcprocess.cpp ) diff --git a/tests/auto/utils/qtcprocess/qtcprocess.pro b/tests/auto/utils/qtcprocess/qtcprocess.pro index ed61fd10d0a..a4e8679d990 100644 --- a/tests/auto/utils/qtcprocess/qtcprocess.pro +++ b/tests/auto/utils/qtcprocess/qtcprocess.pro @@ -3,4 +3,8 @@ include(../../qttest.pri) win32:DEFINES += _CRT_SECURE_NO_WARNINGS +TEST_RELATIVE_LIBEXEC_PATH = $$relative_path($$IDE_LIBEXEC_PATH, $$OUT_PWD) +win32:TEST_RELATIVE_LIBEXEC_PATH=../$$TEST_RELATIVE_LIBEXEC_PATH +DEFINES += TEST_RELATIVE_LIBEXEC_PATH=\\\"$$TEST_RELATIVE_LIBEXEC_PATH\\\" + SOURCES += tst_qtcprocess.cpp diff --git a/tests/auto/utils/qtcprocess/qtcprocess.qbs b/tests/auto/utils/qtcprocess/qtcprocess.qbs index 53f5dcfd2fe..966cf6cbe55 100644 --- a/tests/auto/utils/qtcprocess/qtcprocess.qbs +++ b/tests/auto/utils/qtcprocess/qtcprocess.qbs @@ -1,11 +1,17 @@ -import qbs +import qbs.FileInfo QtcAutotest { name: "QtcProcess autotest" Depends { name: "Utils" } files: "tst_qtcprocess.cpp" - Properties { - condition: qbs.targetOS === "windows" - cpp.defines: base.concat(["_CRT_SECURE_NO_WARNINGS"]) + cpp.defines: { + var defines = base; + if (qbs.targetOS === "windows") + defines.push("_CRT_SECURE_NO_WARNINGS"); + var absLibExecPath = FileInfo.joinPaths(qbs.installRoot, qbs.installPrefix, + qtc.ide_libexec_path); + var relLibExecPath = FileInfo.relativePath(destinationDirectory, absLibExecPath); + defines.push('TEST_RELATIVE_LIBEXEC_PATH="' + relLibExecPath + '"'); + return defines; } } diff --git a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp index b5ffc65f1c2..f5d3eb39204 100644 --- a/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp +++ b/tests/auto/utils/qtcprocess/tst_qtcprocess.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -133,6 +134,8 @@ private slots: void lineCallback(); void lineCallbackIntern(); + void cleanupTestCase(); + private: void iteratorEditsHelper(OsType osType); @@ -147,6 +150,8 @@ private: void tst_QtcProcess::initTestCase() { + Utils::LauncherInterface::startLauncher(qApp->applicationDirPath() + '/' + + QLatin1String(TEST_RELATIVE_LIBEXEC_PATH)); if (qEnvironmentVariableIsSet(kExitCodeSubProcessCode)) exitCodeSubProcessMain(); if (qEnvironmentVariableIsSet(kRunBlockingStdOutSubProcessWithEndl)) @@ -195,6 +200,10 @@ void tst_QtcProcess::initTestCase() mxUnix.insert("z", ""); } +void tst_QtcProcess::cleanupTestCase() +{ + Utils::LauncherInterface::stopLauncher(); +} Q_DECLARE_METATYPE(ProcessArgs::SplitError) Q_DECLARE_METATYPE(Utils::OsType)