forked from qt-creator/qt-creator
Squish: Extract functions for re-use
Change-Id: I3243619c8bb6a9ac6c4c9bfc6a438b23cc8bd37f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -281,7 +281,7 @@ void SquishTools::startSquishServer(Request request)
|
|||||||
|
|
||||||
const FilePath squishServer = Environment::systemEnvironment().searchInPath(
|
const FilePath squishServer = Environment::systemEnvironment().searchInPath(
|
||||||
toolsSettings.serverPath.toString());
|
toolsSettings.serverPath.toString());
|
||||||
if (squishServer.isEmpty()) {
|
if (!squishServer.isExecutableFile()) {
|
||||||
QMessageBox::critical(Core::ICore::dialogParent(),
|
QMessageBox::critical(Core::ICore::dialogParent(),
|
||||||
tr("Squish Server Error"),
|
tr("Squish Server Error"),
|
||||||
tr("\"%1\" could not be found or is not executable.\n"
|
tr("\"%1\" could not be found or is not executable.\n"
|
||||||
@@ -339,53 +339,8 @@ void SquishTools::stopSquishServer()
|
|||||||
|
|
||||||
void SquishTools::startSquishRunner()
|
void SquishTools::startSquishRunner()
|
||||||
{
|
{
|
||||||
if (!m_serverProcess.isRunning()) {
|
if (!isValidToStartRunner() || !setupRunnerPath())
|
||||||
QMessageBox::critical(Core::ICore::dialogParent(),
|
|
||||||
tr("No Squish Server"),
|
|
||||||
tr("Squish server does not seem to be running.\n"
|
|
||||||
"(state: %1, request: %2)\n"
|
|
||||||
"Try again.")
|
|
||||||
.arg(m_state)
|
|
||||||
.arg(m_request));
|
|
||||||
setState(Idle);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (m_serverPort == -1) {
|
|
||||||
QMessageBox::critical(Core::ICore::dialogParent(),
|
|
||||||
tr("No Squish Server Port"),
|
|
||||||
tr("Failed to get the server port.\n"
|
|
||||||
"(state: %1, request: %2)\n"
|
|
||||||
"Try again.")
|
|
||||||
.arg(m_state)
|
|
||||||
.arg(m_request));
|
|
||||||
// setting state to ServerStartFailed will terminate/kill the current unusable server
|
|
||||||
setState(ServerStartFailed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_runnerProcess.state() != QProcess::NotRunning) {
|
|
||||||
QMessageBox::critical(Core::ICore::dialogParent(),
|
|
||||||
tr("Squish Runner Running"),
|
|
||||||
tr("Squish runner seems to be running already.\n"
|
|
||||||
"(state: %1, request: %2)\n"
|
|
||||||
"Wait until it has finished and try again.")
|
|
||||||
.arg(m_state)
|
|
||||||
.arg(m_request));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const FilePath squishRunner = Environment::systemEnvironment().searchInPath(
|
|
||||||
toolsSettings.runnerPath.toString());
|
|
||||||
if (squishRunner.isEmpty()) {
|
|
||||||
QMessageBox::critical(Core::ICore::dialogParent(),
|
|
||||||
tr("Squish Runner Error"),
|
|
||||||
tr("\"%1\" could not be found or is not executable.\n"
|
|
||||||
"Check the settings.")
|
|
||||||
.arg(toolsSettings.runnerPath.toUserOutput()));
|
|
||||||
setState(RunnerStopped);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
toolsSettings.runnerPath = squishRunner;
|
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << m_additionalServerArguments;
|
args << m_additionalServerArguments;
|
||||||
@@ -410,38 +365,7 @@ void SquishTools::startSquishRunner()
|
|||||||
args << "--reportgen"
|
args << "--reportgen"
|
||||||
<< QString::fromLatin1("xml2.2,%1").arg(caseReportFilePath);
|
<< QString::fromLatin1("xml2.2,%1").arg(caseReportFilePath);
|
||||||
|
|
||||||
m_runnerProcess.setCommand({toolsSettings.runnerPath, args});
|
setupAndStartSquishRunnerProcess(args, caseReportFilePath);
|
||||||
m_runnerProcess.setEnvironment(squishEnvironment());
|
|
||||||
|
|
||||||
setState(RunnerStarting);
|
|
||||||
|
|
||||||
// set up the file system watcher for being able to read the results.xml file
|
|
||||||
m_resultsFileWatcher = new QFileSystemWatcher;
|
|
||||||
// on second run this directory exists and won't emit changes, so use the current subdirectory
|
|
||||||
if (QDir(m_currentResultsDirectory).exists())
|
|
||||||
m_resultsFileWatcher->addPath(m_currentResultsDirectory + QDir::separator()
|
|
||||||
+ QDir(m_suitePath).dirName());
|
|
||||||
else
|
|
||||||
m_resultsFileWatcher->addPath(QFileInfo(m_currentResultsDirectory).absolutePath());
|
|
||||||
|
|
||||||
connect(m_resultsFileWatcher,
|
|
||||||
&QFileSystemWatcher::directoryChanged,
|
|
||||||
this,
|
|
||||||
&SquishTools::onResultsDirChanged);
|
|
||||||
|
|
||||||
m_runnerProcess.start();
|
|
||||||
if (!m_runnerProcess.waitForStarted()) {
|
|
||||||
QMessageBox::critical(Core::ICore::dialogParent(),
|
|
||||||
tr("Squish Runner Error"),
|
|
||||||
tr("Squish runner failed to start within given timeframe."));
|
|
||||||
delete m_resultsFileWatcher;
|
|
||||||
m_resultsFileWatcher = nullptr;
|
|
||||||
setState(RunnerStartFailed);
|
|
||||||
m_runnerProcess.close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(RunnerStarted);
|
|
||||||
m_currentResultsXML = new QFile(caseReportFilePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment SquishTools::squishEnvironment()
|
Environment SquishTools::squishEnvironment()
|
||||||
@@ -673,5 +597,101 @@ void SquishTools::restoreQtCreatorWindows()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SquishTools::isValidToStartRunner()
|
||||||
|
{
|
||||||
|
if (!m_serverProcess.isRunning()) {
|
||||||
|
QMessageBox::critical(Core::ICore::dialogParent(),
|
||||||
|
tr("No Squish Server"),
|
||||||
|
tr("Squish server does not seem to be running.\n"
|
||||||
|
"(state: %1, request: %2)\n"
|
||||||
|
"Try again.")
|
||||||
|
.arg(m_state)
|
||||||
|
.arg(m_request));
|
||||||
|
setState(Idle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (m_serverPort == -1) {
|
||||||
|
QMessageBox::critical(Core::ICore::dialogParent(),
|
||||||
|
tr("No Squish Server Port"),
|
||||||
|
tr("Failed to get the server port.\n"
|
||||||
|
"(state: %1, request: %2)\n"
|
||||||
|
"Try again.")
|
||||||
|
.arg(m_state)
|
||||||
|
.arg(m_request));
|
||||||
|
// setting state to ServerStartFailed will terminate/kill the current unusable server
|
||||||
|
setState(ServerStartFailed);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_runnerProcess.state() != QProcess::NotRunning) {
|
||||||
|
QMessageBox::critical(Core::ICore::dialogParent(),
|
||||||
|
tr("Squish Runner Running"),
|
||||||
|
tr("Squish runner seems to be running already.\n"
|
||||||
|
"(state: %1, request: %2)\n"
|
||||||
|
"Wait until it has finished and try again.")
|
||||||
|
.arg(m_state)
|
||||||
|
.arg(m_request));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SquishTools::setupRunnerPath()
|
||||||
|
{
|
||||||
|
const FilePath squishRunner = Environment::systemEnvironment().searchInPath(
|
||||||
|
toolsSettings.runnerPath.toString());
|
||||||
|
if (!squishRunner.isExecutableFile()) {
|
||||||
|
QMessageBox::critical(Core::ICore::dialogParent(),
|
||||||
|
tr("Squish Runner Error"),
|
||||||
|
tr("\"%1\" could not be found or is not executable.\n"
|
||||||
|
"Check the settings.")
|
||||||
|
.arg(toolsSettings.runnerPath.toUserOutput()));
|
||||||
|
setState(RunnerStopped);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
toolsSettings.runnerPath = squishRunner;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SquishTools::setupAndStartSquishRunnerProcess(const QStringList &args,
|
||||||
|
const QString &caseReportFilePath)
|
||||||
|
{
|
||||||
|
m_runnerProcess.setCommand({toolsSettings.runnerPath, args});
|
||||||
|
m_runnerProcess.setEnvironment(squishEnvironment());
|
||||||
|
|
||||||
|
setState(RunnerStarting);
|
||||||
|
|
||||||
|
if (m_request == RunTestRequested) {
|
||||||
|
// set up the file system watcher for being able to read the results.xml file
|
||||||
|
m_resultsFileWatcher = new QFileSystemWatcher;
|
||||||
|
// on 2nd run this directory exists and won't emit changes, so use the current subdirectory
|
||||||
|
if (QDir(m_currentResultsDirectory).exists())
|
||||||
|
m_resultsFileWatcher->addPath(m_currentResultsDirectory + QDir::separator()
|
||||||
|
+ QDir(m_suitePath).dirName());
|
||||||
|
else
|
||||||
|
m_resultsFileWatcher->addPath(QFileInfo(m_currentResultsDirectory).absolutePath());
|
||||||
|
|
||||||
|
connect(m_resultsFileWatcher,
|
||||||
|
&QFileSystemWatcher::directoryChanged,
|
||||||
|
this,
|
||||||
|
&SquishTools::onResultsDirChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_runnerProcess.start();
|
||||||
|
if (!m_runnerProcess.waitForStarted()) {
|
||||||
|
QMessageBox::critical(Core::ICore::dialogParent(),
|
||||||
|
tr("Squish Runner Error"),
|
||||||
|
tr("Squish runner failed to start within given timeframe."));
|
||||||
|
delete m_resultsFileWatcher;
|
||||||
|
m_resultsFileWatcher = nullptr;
|
||||||
|
setState(RunnerStartFailed);
|
||||||
|
m_runnerProcess.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(RunnerStarted);
|
||||||
|
if (m_request == RunTestRequested)
|
||||||
|
m_currentResultsXML = new QFile(caseReportFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Squish
|
} // namespace Squish
|
||||||
|
@@ -103,6 +103,10 @@ private:
|
|||||||
static void logrotateTestResults();
|
static void logrotateTestResults();
|
||||||
void minimizeQtCreatorWindows();
|
void minimizeQtCreatorWindows();
|
||||||
void restoreQtCreatorWindows();
|
void restoreQtCreatorWindows();
|
||||||
|
bool isValidToStartRunner();
|
||||||
|
bool setupRunnerPath();
|
||||||
|
void setupAndStartSquishRunnerProcess(const QStringList &arg,
|
||||||
|
const QString &caseReportFilePath = {});
|
||||||
|
|
||||||
std::unique_ptr<SquishXmlOutputHandler> m_xmlOutputHandler;
|
std::unique_ptr<SquishXmlOutputHandler> m_xmlOutputHandler;
|
||||||
Utils::QtcProcess m_serverProcess;
|
Utils::QtcProcess m_serverProcess;
|
||||||
|
Reference in New Issue
Block a user