Squish: Modernize SquishTools

Change-Id: I8b9394b95d0e9fe8e054c66df58436aef2ddfb05
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2022-07-04 09:25:46 +02:00
parent 6431932569
commit ec86b12724
2 changed files with 40 additions and 55 deletions

View File

@@ -36,6 +36,7 @@
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <QApplication> #include <QApplication>
#include <QDateTime> #include <QDateTime>
@@ -55,15 +56,6 @@ static const QString resultsDirectory = QFileInfo(QDir::home(), ".squishQC/Test
SquishTools::SquishTools(QObject *parent) SquishTools::SquishTools(QObject *parent)
: QObject(parent) : QObject(parent)
, m_serverProcess(nullptr)
, m_runnerProcess(nullptr)
, m_serverPort(-1)
, m_request(None)
, m_state(Idle)
, m_currentResultsXML(nullptr)
, m_resultsFileWatcher(nullptr)
, m_testRunning(false)
, m_xmlOutputHandler(nullptr)
{ {
SquishOutputPane *outputPane = SquishOutputPane::instance(); SquishOutputPane *outputPane = SquishOutputPane::instance();
connect(this, connect(this,
@@ -330,8 +322,7 @@ void SquishTools::startSquishServer(Request request)
else else
m_lastTopLevelWindows.clear(); m_lastTopLevelWindows.clear();
m_serverProcess = new QProcess; m_serverProcess = new Utils::QtcProcess;
m_serverProcess->setProgram(toolsSettings.serverPath);
QStringList arguments; QStringList arguments;
// TODO if isLocalServer is false we should start a squishserver on remote device // TODO if isLocalServer is false we should start a squishserver on remote device
if (toolsSettings.isLocalServer) if (toolsSettings.isLocalServer)
@@ -341,18 +332,15 @@ void SquishTools::startSquishServer(Request request)
if (toolsSettings.verboseLog) if (toolsSettings.verboseLog)
arguments << "--verbose"; arguments << "--verbose";
m_serverProcess->setArguments(arguments); m_serverProcess->setCommand({Utils::FilePath::fromString(toolsSettings.serverPath), arguments});
m_serverProcess->setProcessEnvironment(squishEnvironment()); m_serverProcess->setEnvironment(squishEnvironment());
connect(m_serverProcess, &QProcess::readyReadStandardOutput, this, &SquishTools::onServerOutput); connect(m_serverProcess, &Utils::QtcProcess::readyReadStandardOutput,
connect(m_serverProcess, this, &SquishTools::onServerOutput);
&QProcess::readyReadStandardError, connect(m_serverProcess, &Utils::QtcProcess::readyReadStandardError,
this, this, &SquishTools::onServerErrorOutput);
&SquishTools::onServerErrorOutput); connect(m_serverProcess, &Utils::QtcProcess::done,
connect(m_serverProcess, this, &SquishTools::onServerFinished);
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this,
&SquishTools::onServerFinished);
setState(ServerStarting); setState(ServerStarting);
m_serverProcess->start(); m_serverProcess->start();
@@ -365,12 +353,11 @@ void SquishTools::startSquishServer(Request request)
void SquishTools::stopSquishServer() void SquishTools::stopSquishServer()
{ {
if (m_serverProcess && m_serverPort > 0) { if (m_serverProcess && m_serverPort > 0) {
QProcess serverKiller; Utils::QtcProcess serverKiller;
serverKiller.setProgram(m_serverProcess->program());
QStringList args; QStringList args;
args << "--stop" << "--port" << QString::number(m_serverPort); args << "--stop" << "--port" << QString::number(m_serverPort);
serverKiller.setArguments(args); serverKiller.setCommand({m_serverProcess->commandLine().executable(), args});
serverKiller.setProcessEnvironment(m_serverProcess->processEnvironment()); serverKiller.setEnvironment(m_serverProcess->environment());
serverKiller.start(); serverKiller.start();
if (serverKiller.waitForStarted()) { if (serverKiller.waitForStarted()) {
if (!serverKiller.waitForFinished()) { if (!serverKiller.waitForFinished()) {
@@ -437,7 +424,7 @@ void SquishTools::startSquishRunner()
} }
toolsSettings.runnerPath = squishRunner.toString(); toolsSettings.runnerPath = squishRunner.toString();
m_runnerProcess = new QProcess; m_runnerProcess = new Utils::QtcProcess;
QStringList args; QStringList args;
args << m_additionalServerArguments; args << m_additionalServerArguments;
@@ -462,18 +449,13 @@ void SquishTools::startSquishRunner()
args << "--reportgen" args << "--reportgen"
<< QString::fromLatin1("xml2.2,%1").arg(caseReportFilePath); << QString::fromLatin1("xml2.2,%1").arg(caseReportFilePath);
m_runnerProcess->setProgram(toolsSettings.runnerPath); m_runnerProcess->setCommand({Utils::FilePath::fromString(toolsSettings.runnerPath), args});
m_runnerProcess->setArguments(args); m_runnerProcess->setEnvironment(squishEnvironment());
m_runnerProcess->setProcessEnvironment(squishEnvironment());
connect(m_runnerProcess, connect(m_runnerProcess, &Utils::QtcProcess::readyReadStandardError,
&QProcess::readyReadStandardError, this, &SquishTools::onRunnerErrorOutput);
this, connect(m_runnerProcess, &Utils::QtcProcess::done,
&SquishTools::onRunnerErrorOutput); this, &SquishTools::onRunnerFinished);
connect(m_runnerProcess,
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this,
&SquishTools::onRunnerFinished);
setState(RunnerStarting); setState(RunnerStarting);
@@ -505,16 +487,16 @@ void SquishTools::startSquishRunner()
m_currentResultsXML = new QFile(caseReportFilePath); m_currentResultsXML = new QFile(caseReportFilePath);
} }
QProcessEnvironment SquishTools::squishEnvironment() Utils::Environment SquishTools::squishEnvironment()
{ {
Utils::Environment environment = Utils::Environment::systemEnvironment(); Utils::Environment environment = Utils::Environment::systemEnvironment();
if (!toolsSettings.licenseKeyPath.isEmpty()) if (!toolsSettings.licenseKeyPath.isEmpty())
environment.prependOrSet("SQUISH_LICENSEKEY_DIR", toolsSettings.licenseKeyPath); environment.prependOrSet("SQUISH_LICENSEKEY_DIR", toolsSettings.licenseKeyPath);
environment.prependOrSet("SQUISH_PREFIX", toolsSettings.squishPath); environment.prependOrSet("SQUISH_PREFIX", toolsSettings.squishPath);
return environment.toProcessEnvironment(); return environment;
} }
void SquishTools::onServerFinished(int, QProcess::ExitStatus) void SquishTools::onServerFinished()
{ {
delete m_serverProcess; delete m_serverProcess;
m_serverProcess = nullptr; m_serverProcess = nullptr;
@@ -522,7 +504,7 @@ void SquishTools::onServerFinished(int, QProcess::ExitStatus)
setState(ServerStopped); setState(ServerStopped);
} }
void SquishTools::onRunnerFinished(int, QProcess::ExitStatus) void SquishTools::onRunnerFinished()
{ {
delete m_runnerProcess; delete m_runnerProcess;
m_runnerProcess = nullptr; m_runnerProcess = nullptr;

View File

@@ -25,8 +25,9 @@
#pragma once #pragma once
#include <utils/environment.h>
#include <QObject> #include <QObject>
#include <QProcess>
#include <QStringList> #include <QStringList>
#include <QWindowList> #include <QWindowList>
@@ -35,6 +36,8 @@ class QFile;
class QFileSystemWatcher; class QFileSystemWatcher;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Utils { class QtcProcess; }
namespace Squish { namespace Squish {
namespace Internal { namespace Internal {
@@ -88,9 +91,9 @@ private:
void startSquishServer(Request request); void startSquishServer(Request request);
void stopSquishServer(); void stopSquishServer();
void startSquishRunner(); void startSquishRunner();
static QProcessEnvironment squishEnvironment(); static Utils::Environment squishEnvironment();
Q_SLOT void onServerFinished(int exitCode, QProcess::ExitStatus status = QProcess::NormalExit); void onServerFinished();
Q_SLOT void onRunnerFinished(int exitCode, QProcess::ExitStatus status = QProcess::NormalExit); void onRunnerFinished();
void onServerOutput(); void onServerOutput();
void onServerErrorOutput(); void onServerErrorOutput();
void onRunnerOutput(); void onRunnerOutput();
@@ -100,24 +103,24 @@ private:
void minimizeQtCreatorWindows(); void minimizeQtCreatorWindows();
void restoreQtCreatorWindows(); void restoreQtCreatorWindows();
QProcess *m_serverProcess; Utils::QtcProcess *m_serverProcess = nullptr;
QProcess *m_runnerProcess; Utils::QtcProcess *m_runnerProcess = nullptr;
int m_serverPort; int m_serverPort = -1;
QString m_serverHost; QString m_serverHost;
Request m_request; Request m_request = None;
State m_state; State m_state = Idle;
QString m_suitePath; QString m_suitePath;
QStringList m_testCases; QStringList m_testCases;
QStringList m_reportFiles; QStringList m_reportFiles;
QString m_currentResultsDirectory; QString m_currentResultsDirectory;
QFile *m_currentResultsXML; QFile *m_currentResultsXML = nullptr;
QFileSystemWatcher *m_resultsFileWatcher; QFileSystemWatcher *m_resultsFileWatcher = nullptr;
QStringList m_additionalServerArguments; QStringList m_additionalServerArguments;
QStringList m_additionalRunnerArguments; QStringList m_additionalRunnerArguments;
QWindowList m_lastTopLevelWindows; QWindowList m_lastTopLevelWindows;
bool m_testRunning; bool m_testRunning = false;
qint64 m_readResultsCount; qint64 m_readResultsCount;
SquishXmlOutputHandler *m_xmlOutputHandler; SquishXmlOutputHandler *m_xmlOutputHandler = nullptr;
}; };
} // namespace Internal } // namespace Internal