Squish: Move recording over to new approach

Change-Id: I7c8b16cd7f58fa772510ea171756577036520e49
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2023-01-03 11:30:22 +01:00
parent 3de8d194c5
commit 58b197e2ae
2 changed files with 58 additions and 146 deletions

View File

@@ -112,21 +112,6 @@ SquishTools::SquishTools(QObject *parent)
connect(this, &SquishTools::squishTestRunFinished, connect(this, &SquishTools::squishTestRunFinished,
outputPane, &SquishOutputPane::onTestRunFinished); outputPane, &SquishOutputPane::onTestRunFinished);
m_runnerProcess.setProcessMode(ProcessMode::Writer);
m_recorderProcess.setProcessMode(ProcessMode::Writer);
m_runnerProcess.setStdOutLineCallback([this](const QString &line) {
onRunnerStdOutput(line);
});
connect(&m_recorderProcess, &QtcProcess::done,
this, &SquishTools::onRecorderFinished);
connect(&m_runnerProcess, &QtcProcess::readyReadStandardError,
this, &SquishTools::onRunnerErrorOutput);
connect(&m_runnerProcess, &QtcProcess::done,
this, &SquishTools::onRunnerFinished);
connect(&m_serverProcess, &SquishServerProcess::stateChanged, connect(&m_serverProcess, &SquishServerProcess::stateChanged,
this, &SquishTools::onServerStateChanged); this, &SquishTools::onServerStateChanged);
connect(&m_serverProcess, &SquishServerProcess::logOutputReceived, connect(&m_serverProcess, &SquishServerProcess::logOutputReceived,
@@ -138,9 +123,7 @@ SquishTools::SquishTools(QObject *parent)
this, [this] { this, [this] {
logRunnerStateChange(m_squishRunnerState, RunnerState::InterruptRequested); logRunnerStateChange(m_squishRunnerState, RunnerState::InterruptRequested);
m_squishRunnerState = RunnerState::InterruptRequested; m_squishRunnerState = RunnerState::InterruptRequested;
if (m_request == RunTestRequested && m_primaryRunner && m_primaryRunner->processId() != -1) if (m_primaryRunner && m_primaryRunner->processId() != -1)
interruptRunner();
else if (m_runnerProcess.processId() != -1)
interruptRunner(); interruptRunner();
}); });
connect(&m_perspective, &SquishPerspective::stopRequested, this, [this] { connect(&m_perspective, &SquishPerspective::stopRequested, this, [this] {
@@ -151,9 +134,7 @@ SquishTools::SquishTools(QObject *parent)
m_squishRunnerState = state; m_squishRunnerState = state;
if (interrupted) if (interrupted)
handlePrompt(); handlePrompt();
else if (m_request == RunTestRequested && m_primaryRunner && m_primaryRunner->processId() != -1) else if (m_primaryRunner && m_primaryRunner->processId() != -1)
terminateRunner();
else if (m_request == RecordTestRequested && m_runnerProcess.processId() != -1)
terminateRunner(); terminateRunner();
}); });
connect(&m_perspective, &SquishPerspective::stopRecordRequested, connect(&m_perspective, &SquishPerspective::stopRecordRequested,
@@ -324,6 +305,7 @@ void SquishTools::recordTestCase(const FilePath &suitePath, const QString &testC
m_additionalRunnerArguments.clear(); m_additionalRunnerArguments.clear();
m_perspective.setPerspectiveMode(SquishPerspective::Recording); m_perspective.setPerspectiveMode(SquishPerspective::Recording);
setupRunnerForRun();
startSquishServer(RecordTestRequested); startSquishServer(RecordTestRequested);
} }
@@ -372,10 +354,7 @@ void SquishTools::setState(SquishTools::State state)
// TODO check whether state transition is legal // TODO check whether state transition is legal
m_state = state; m_state = state;
if (m_request == RecordTestRequested || m_request == KillOldBeforeRecordRunner) { if (m_request == RunnerQueryRequested || m_request == KillOldBeforeQueryRunner) {
handleSetStateStartAppRunner();
return;
} else if (m_request == RunnerQueryRequested || m_request == KillOldBeforeQueryRunner) {
handleSetStateQueryRunner(); handleSetStateQueryRunner();
return; return;
} }
@@ -385,7 +364,7 @@ void SquishTools::setState(SquishTools::State state)
setIdle(); setIdle();
break; break;
case ServerStarted: case ServerStarted:
if (m_request == RunTestRequested) { if (m_request == RunTestRequested || m_request == RecordTestRequested) {
startSquishRunner(); startSquishRunner();
} else if (m_request == ServerConfigChangeRequested) { // nothing to do here } else if (m_request == ServerConfigChangeRequested) { // nothing to do here
} else { } else {
@@ -394,10 +373,9 @@ void SquishTools::setState(SquishTools::State state)
break; break;
case ServerStartFailed: case ServerStartFailed:
m_state = Idle; m_state = Idle;
if (m_request == RunTestRequested) { if (m_request == RunTestRequested)
emit squishTestRunFinished(); emit squishTestRunFinished();
m_perspective.setPerspectiveMode(SquishPerspective::NoMode); m_perspective.setPerspectiveMode(SquishPerspective::NoMode);
}
m_request = None; m_request = None;
if (toolsSettings.minimizeIDE) if (toolsSettings.minimizeIDE)
restoreQtCreatorWindows(); restoreQtCreatorWindows();
@@ -419,15 +397,17 @@ void SquishTools::setState(SquishTools::State state)
emit configChangesWritten(); emit configChangesWritten();
} else if (m_request == ServerStopRequested) { } else if (m_request == ServerStopRequested) {
m_request = None; m_request = None;
if (m_perspective.perspectiveMode() == SquishPerspective::Running) { if (m_perspective.perspectiveMode() == SquishPerspective::Running)
emit squishTestRunFinished(); emit squishTestRunFinished();
m_perspective.setPerspectiveMode(SquishPerspective::NoMode);
} m_perspective.setPerspectiveMode(SquishPerspective::NoMode);
if (toolsSettings.minimizeIDE) if (toolsSettings.minimizeIDE)
restoreQtCreatorWindows(); restoreQtCreatorWindows();
m_perspective.destroyControlBar(); m_perspective.destroyControlBar();
} else if (m_request == KillOldBeforeRunRunner) { } else if (m_request == KillOldBeforeRunRunner) {
startSquishServer(RunTestRequested); startSquishServer(RunTestRequested);
} else if (m_request == KillOldBeforeRecordRunner) {
startSquishServer(RecordTestRequested);
} else { } else {
QTC_ASSERT(false, qDebug() << m_state << m_request); QTC_ASSERT(false, qDebug() << m_state << m_request);
} }
@@ -441,7 +421,15 @@ void SquishTools::setState(SquishTools::State state)
break; break;
case RunnerStartFailed: case RunnerStartFailed:
case RunnerStopped: case RunnerStopped:
if (m_testCases.isEmpty() || (m_squishRunnerState == RunnerState::Canceled)) { if (m_request == RecordTestRequested) {
if (m_secondaryRunner && m_secondaryRunner->isRunning()) {
stopRecorder();
} else {
m_request = ServerStopRequested;
qCInfo(LOG) << "Stopping server from RunnerStopped (startaut)";
stopSquishServer();
}
} else if (m_testCases.isEmpty() || (m_squishRunnerState == RunnerState::Canceled)) {
m_request = ServerStopRequested; m_request = ServerStopRequested;
qCInfo(LOG) << "Stopping server from RunnerStopped"; qCInfo(LOG) << "Stopping server from RunnerStopped";
stopSquishServer(); stopSquishServer();
@@ -466,58 +454,6 @@ void SquishTools::setState(SquishTools::State state)
} }
} }
void SquishTools::handleSetStateStartAppRunner()
{
switch (m_state) {
case Idle:
setIdle();
break;
case ServerStarted:
startSquishRunner();
break;
case ServerStartFailed:
m_state = Idle;
m_request = None;
if (toolsSettings.minimizeIDE)
restoreQtCreatorWindows();
m_perspective.destroyControlBar();
break;
case ServerStopped:
m_state = Idle;
emit shutdownFinished();
if (m_request == ServerStopRequested) {
m_request = None;
if (toolsSettings.minimizeIDE)
restoreQtCreatorWindows();
m_perspective.destroyControlBar();
} else if (m_request == KillOldBeforeRecordRunner) {
startSquishServer(RecordTestRequested);
} else {
QTC_ASSERT(false, qDebug() << m_state << m_request);
}
break;
case ServerStopFailed:
m_serverProcess.closeProcess();
if (toolsSettings.minimizeIDE)
restoreQtCreatorWindows();
m_perspective.destroyControlBar();
m_state = Idle;
break;
case RunnerStartFailed:
case RunnerStopped:
if (m_recorderProcess.isRunning()) {
stopRecorder();
} else {
m_request = ServerStopRequested;
qCInfo(LOG) << "Stopping server from RunnerStopped (startaut)";
stopSquishServer();
}
break;
default:
break;
}
}
void SquishTools::handleSetStateQueryRunner() void SquishTools::handleSetStateQueryRunner()
{ {
switch (m_state) { switch (m_state) {
@@ -640,7 +576,7 @@ void SquishTools::startSquishRunner()
void SquishTools::setupAndStartRecorder() void SquishTools::setupAndStartRecorder()
{ {
QTC_ASSERT(m_autId != 0, return); QTC_ASSERT(m_autId != 0, return);
QTC_ASSERT(!m_recorderProcess.isRunning(), return); QTC_ASSERT(!m_secondaryRunner, return);
QStringList args; QStringList args;
if (!toolsSettings.isLocalServer) if (!toolsSettings.isLocalServer)
@@ -661,22 +597,25 @@ void SquishTools::setupAndStartRecorder()
args << "--useScriptedObjectMap"; args << "--useScriptedObjectMap";
args << "--autid" << QString::number(m_autId); args << "--autid" << QString::number(m_autId);
m_recorderProcess.setCommand({toolsSettings.runnerPath, args}); m_secondaryRunner = new QtcProcess(this);
qCDebug(LOG) << "Recorder starting:" << m_recorderProcess.commandLine().toUserOutput(); m_secondaryRunner->setProcessMode(ProcessMode::Writer);
m_secondaryRunner->setCommand({toolsSettings.runnerPath, args});
connect(m_secondaryRunner, &QtcProcess::done, this, &SquishTools::onRecorderFinished);
qCDebug(LOG) << "Recorder starting:" << m_secondaryRunner->commandLine().toUserOutput();
if (m_suiteConf.objectMapPath().isReadableFile()) if (m_suiteConf.objectMapPath().isReadableFile())
Core::DocumentManager::expectFileChange(m_suiteConf.objectMapPath()); Core::DocumentManager::expectFileChange(m_suiteConf.objectMapPath());
m_recorderProcess.start(); m_secondaryRunner->start();
} }
void SquishTools::stopRecorder() void SquishTools::stopRecorder()
{ {
QTC_ASSERT(m_recorderProcess.isRunning(), return); QTC_ASSERT(m_secondaryRunner && m_secondaryRunner->isRunning(), return);
if (m_squishRunnerState == RunnerState::CancelRequested) { if (m_squishRunnerState == RunnerState::CancelRequested) {
qCDebug(LOG) << "Stopping recorder (exit)"; qCDebug(LOG) << "Stopping recorder (exit)";
m_recorderProcess.write("exit\n"); m_secondaryRunner->write("exit\n");
} else { } else {
qCDebug(LOG) << "Stopping recorder (endrecord)"; qCDebug(LOG) << "Stopping recorder (endrecord)";
m_recorderProcess.write("endrecord\n"); m_secondaryRunner->write("endrecord\n");
} }
} }
@@ -781,11 +720,15 @@ void SquishTools::onRunnerFinished()
void SquishTools::onRecorderFinished() void SquishTools::onRecorderFinished()
{ {
qCDebug(LOG) << "Recorder finished:" << m_recorderProcess.exitCode(); QTC_ASSERT(m_secondaryRunner, return);
if (m_runnerProcess.isRunning()) { qCDebug(LOG) << "Recorder finished:" << m_secondaryRunner->exitCode();
m_secondaryRunner->deleteLater();
m_secondaryRunner = nullptr;
if (m_primaryRunner && m_primaryRunner->isRunning()) {
if (m_closeRunnerOnEndRecord) { if (m_closeRunnerOnEndRecord) {
//terminateRunner(); //terminateRunner();
m_runnerProcess.write("exit\n"); // why doesn't work anymore? m_primaryRunner->write("exit\n"); // why doesn't work anymore?
} }
} else { } else {
m_request = ServerStopRequested; m_request = ServerStopRequested;
@@ -895,8 +838,9 @@ void SquishTools::onRunnerOutput()
void SquishTools::onRunnerErrorOutput() void SquishTools::onRunnerErrorOutput()
{ {
QTC_ASSERT(m_primaryRunner, return);
// output that must be send to the Runner/Server Log // output that must be send to the Runner/Server Log
const QByteArray output = m_runnerProcess.readAllRawStandardError(); const QByteArray output = m_primaryRunner->readAllRawStandardError();
const QList<QByteArray> lines = output.split('\n'); const QList<QByteArray> lines = output.split('\n');
for (const QByteArray &line : lines) { for (const QByteArray &line : lines) {
const QByteArray trimmed = line.trimmed(); const QByteArray trimmed = line.trimmed();
@@ -1105,9 +1049,7 @@ void SquishTools::requestExpansion(const QString &name)
{ {
QTC_ASSERT(m_primaryRunner, return); QTC_ASSERT(m_primaryRunner, return);
QTC_ASSERT(m_squishRunnerState == RunnerState::Interrupted, return); QTC_ASSERT(m_squishRunnerState == RunnerState::Interrupted, return);
QtcProcess *process = m_request == RunTestRequested ? m_primaryRunner m_primaryRunner->write("print variables +" + name + "\n");
: &m_runnerProcess;
process->write("print variables +" + name + "\n");
} }
bool SquishTools::shutdown() bool SquishTools::shutdown()
@@ -1116,11 +1058,9 @@ bool SquishTools::shutdown()
m_shutdownInitiated = true; m_shutdownInitiated = true;
if (m_primaryRunner && m_primaryRunner->isRunning()) if (m_primaryRunner && m_primaryRunner->isRunning())
terminateRunner(); terminateRunner();
if (m_runnerProcess.isRunning())
terminateRunner();
if (m_serverProcess.isRunning()) if (m_serverProcess.isRunning())
m_serverProcess.stop(); m_serverProcess.stop();
return !(m_serverProcess.isRunning() || m_runnerProcess.isRunning() || (m_primaryRunner && m_primaryRunner->isRunning())); return !(m_serverProcess.isRunning() || (m_primaryRunner && m_primaryRunner->isRunning()));
} }
void SquishTools::onResultsDirChanged(const QString &filePath) void SquishTools::onResultsDirChanged(const QString &filePath)
@@ -1218,17 +1158,15 @@ void SquishTools::onRunnerRunRequested(StepMode step)
logRunnerStateChange(m_squishRunnerState, RunnerState::RunRequested); logRunnerStateChange(m_squishRunnerState, RunnerState::RunRequested);
m_squishRunnerState = RunnerState::RunRequested; m_squishRunnerState = RunnerState::RunRequested;
QtcProcess *process = m_request == RunTestRequested ? m_primaryRunner QTC_ASSERT(m_primaryRunner, return);
: &m_runnerProcess;
QTC_ASSERT(process, return);
if (step == StepMode::Continue) if (step == StepMode::Continue)
process->write("continue\n"); m_primaryRunner->write("continue\n");
else if (step == StepMode::StepIn) else if (step == StepMode::StepIn)
process->write("step\n"); m_primaryRunner->write("step\n");
else if (step == StepMode::StepOver) else if (step == StepMode::StepOver)
process->write("next\n"); m_primaryRunner->write("next\n");
else if (step == StepMode::StepOut) else if (step == StepMode::StepOut)
process->write("return\n"); m_primaryRunner->write("return\n");
clearLocationMarker(); clearLocationMarker();
if (toolsSettings.minimizeIDE) if (toolsSettings.minimizeIDE)
@@ -1244,8 +1182,8 @@ void SquishTools::onRunnerRunRequested(StepMode step)
void SquishTools::interruptRunner() void SquishTools::interruptRunner()
{ {
qCDebug(LOG) << "Interrupting runner"; qCDebug(LOG) << "Interrupting runner";
qint64 processId = (m_request == RunTestRequested && m_primaryRunner) QTC_ASSERT(m_primaryRunner, return);
? m_primaryRunner->processId() : m_runnerProcess.processId(); qint64 processId = m_primaryRunner->processId();
const CommandLine cmd(toolsSettings.processComPath, {QString::number(processId), "break"}); const CommandLine cmd(toolsSettings.processComPath, {QString::number(processId), "break"});
QtcProcess process; QtcProcess process;
process.setCommand(cmd); process.setCommand(cmd);
@@ -1260,8 +1198,8 @@ void SquishTools::terminateRunner()
m_currentTestCasePath.clear(); m_currentTestCasePath.clear();
m_perspective.updateStatus(Tr::tr("User stop initiated.")); m_perspective.updateStatus(Tr::tr("User stop initiated."));
// should we terminate the AUT instead of the runner?!? // should we terminate the AUT instead of the runner?!?
qint64 processId = m_request == RunTestRequested ? m_primaryRunner->processId() QTC_ASSERT(m_primaryRunner, return);
: m_runnerProcess.processId(); qint64 processId = m_primaryRunner->processId();
const CommandLine cmd(toolsSettings.processComPath, {QString::number(processId), "terminate"}); const CommandLine cmd(toolsSettings.processComPath, {QString::number(processId), "terminate"});
QtcProcess process; QtcProcess process;
process.setCommand(cmd); process.setCommand(cmd);
@@ -1389,7 +1327,7 @@ bool SquishTools::isValidToStartRunner()
return false; return false;
} }
if (m_runnerProcess.state() != QProcess::NotRunning) { if (m_primaryRunner && m_primaryRunner->state() != QProcess::NotRunning) {
QMessageBox::critical(Core::ICore::dialogParent(), QMessageBox::critical(Core::ICore::dialogParent(),
Tr::tr("Squish Runner Running"), Tr::tr("Squish Runner Running"),
Tr::tr("Squish runner seems to be running already.\n" Tr::tr("Squish runner seems to be running already.\n"
@@ -1421,17 +1359,11 @@ bool SquishTools::setupRunnerPath()
void SquishTools::setupAndStartSquishRunnerProcess(const Utils::CommandLine &cmdLine) void SquishTools::setupAndStartSquishRunnerProcess(const Utils::CommandLine &cmdLine)
{ {
if (m_request == RecordTestRequested) { QTC_ASSERT(m_primaryRunner, return);
m_runnerProcess.close(); // avoid crashes on fast re-usage of QtcProcess
m_runnerProcess.setCommand(cmdLine); m_primaryRunner->close();
m_runnerProcess.setEnvironment(squishEnvironment()); m_primaryRunner->setCommand(cmdLine);
} else { m_primaryRunner->setEnvironment(squishEnvironment());
QTC_ASSERT(m_primaryRunner, return);
// avoid crashes on fast re-usage of QtcProcess
m_primaryRunner->close();
m_primaryRunner->setCommand(cmdLine);
m_primaryRunner->setEnvironment(squishEnvironment());
}
if (m_request == RunTestRequested) { if (m_request == RunTestRequested) {
// set up the file system watcher for being able to read the results.xml file // set up the file system watcher for being able to read the results.xml file
@@ -1448,24 +1380,7 @@ void SquishTools::setupAndStartSquishRunnerProcess(const Utils::CommandLine &cmd
&SquishTools::onResultsDirChanged); &SquishTools::onResultsDirChanged);
} }
if (m_request == RunTestRequested) { startPrimaryRunner();
startPrimaryRunner();
return;
}
setState(RunnerStarting);
qCDebug(LOG) << "Runner starts:" << m_runnerProcess.commandLine().toUserOutput();
m_runnerProcess.start();
if (!m_runnerProcess.waitForStarted()) {
QMessageBox::critical(Core::ICore::dialogParent(),
Tr::tr("Squish Runner Error"),
Tr::tr("Squish runner failed to start within given timeframe."));
delete m_resultsFileWatcher;
m_resultsFileWatcher = nullptr;
setState(RunnerStartFailed);
m_runnerProcess.close();
return;
}
setState(RunnerStarted);
} }
void SquishTools::setupRunnerForQuery() void SquishTools::setupRunnerForQuery()

View File

@@ -91,7 +91,6 @@ private:
void onServerStateChanged(SquishProcessState state); void onServerStateChanged(SquishProcessState state);
void setState(State state); void setState(State state);
void handleSetStateStartAppRunner();
void handleSetStateQueryRunner(); void handleSetStateQueryRunner();
void setIdle(); void setIdle();
void startSquishServer(Request request); void startSquishServer(Request request);
@@ -136,8 +135,6 @@ private:
Utils::QtcProcess *m_primaryRunner = nullptr; Utils::QtcProcess *m_primaryRunner = nullptr;
Utils::QtcProcess *m_secondaryRunner = nullptr; Utils::QtcProcess *m_secondaryRunner = nullptr;
Utils::QtcProcess m_runnerProcess;
Utils::QtcProcess m_recorderProcess;
QString m_serverHost; QString m_serverHost;
Request m_request = None; Request m_request = None;
State m_state = Idle; State m_state = Idle;