Qnx: Reuse setExtraTasks()

Change-Id: Ia392015a7a410a1920e8e79637ac6ac51c988b74
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-11-24 09:36:17 +01:00
parent fbe8d85401
commit 74ba41f82c
2 changed files with 32 additions and 85 deletions

View File

@@ -6,6 +6,7 @@
#include "qnxtr.h" #include "qnxtr.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
using namespace Utils; using namespace Utils;
@@ -20,14 +21,18 @@ QnxDeviceTester::QnxDeviceTester(QObject *parent)
connect(m_genericTester, &DeviceTester::errorMessage, connect(m_genericTester, &DeviceTester::errorMessage,
this, &DeviceTester::errorMessage); this, &DeviceTester::errorMessage);
connect(m_genericTester, &DeviceTester::finished, connect(m_genericTester, &DeviceTester::finished,
this, &QnxDeviceTester::handleGenericTestFinished); this, &QnxDeviceTester::finished);
}
connect(&m_varRunProcess, &QtcProcess::done, this, &QnxDeviceTester::handleVarRunDone); static QStringList versionSpecificCommandsToTest(int versionNumber)
{
if (versionNumber > 0x060500)
return {"slog2info"};
return {};
} }
void QnxDeviceTester::testDevice(const ProjectExplorer::IDevice::Ptr &deviceConfiguration) void QnxDeviceTester::testDevice(const ProjectExplorer::IDevice::Ptr &deviceConfiguration)
{ {
QTC_ASSERT(m_state == Inactive, return);
static const QStringList s_commandsToTest = {"awk", static const QStringList s_commandsToTest = {"awk",
"cat", "cat",
"cut", "cut",
@@ -45,76 +50,38 @@ void QnxDeviceTester::testDevice(const ProjectExplorer::IDevice::Ptr &deviceConf
"sleep", "sleep",
"tail", "tail",
"uname"}; "uname"};
m_deviceConfiguration = deviceConfiguration; m_deviceConfiguration = deviceConfiguration;
m_state = GenericTest;
QnxDevice::ConstPtr qnxDevice = m_deviceConfiguration.dynamicCast<const QnxDevice>(); QnxDevice::ConstPtr qnxDevice = m_deviceConfiguration.dynamicCast<const QnxDevice>();
m_genericTester->setExtraCommandsToTest( m_genericTester->setExtraCommandsToTest(
s_commandsToTest + versionSpecificCommandsToTest(qnxDevice->qnxVersion())); s_commandsToTest + versionSpecificCommandsToTest(qnxDevice->qnxVersion()));
using namespace Tasking;
auto setupHandler = [this](QtcProcess &process) {
emit progressMessage(Tr::tr("Checking that files can be created in /var/run..."));
const CommandLine cmd {m_deviceConfiguration->filePath("/bin/sh"),
{"-c", QLatin1String("rm %1 > /dev/null 2>&1; echo ABC > %1 && rm %1")
.arg("/var/run/qtc_xxxx.pid")}};
process.setCommand(cmd);
};
auto doneHandler = [this](const QtcProcess &) {
emit progressMessage(Tr::tr("Files can be created in /var/run.") + '\n');
};
auto errorHandler = [this](const QtcProcess &process) {
const QString message = process.result() == ProcessResult::StartFailed
? Tr::tr("An error occurred while checking that files can be created in /var/run.")
+ '\n' + process.errorString()
: Tr::tr("Files cannot be created in /var/run.");
emit errorMessage(message + '\n');
};
m_genericTester->setExtraTests({Process(setupHandler, doneHandler, errorHandler)});
m_genericTester->testDevice(deviceConfiguration); m_genericTester->testDevice(deviceConfiguration);
} }
void QnxDeviceTester::stopTest() void QnxDeviceTester::stopTest()
{ {
QTC_ASSERT(m_state != Inactive, return);
if (m_state == GenericTest)
m_genericTester->stopTest(); m_genericTester->stopTest();
setFinished(TestFailure);
}
void QnxDeviceTester::handleGenericTestFinished(TestResult result)
{
QTC_ASSERT(m_state == GenericTest, return);
if (result == TestFailure) {
setFinished(TestFailure);
return;
}
m_state = VarRunTest;
emit progressMessage(Tr::tr("Checking that files can be created in /var/run..."));
const CommandLine cmd {m_deviceConfiguration->filePath("/bin/sh"),
{"-c", QLatin1String("rm %1 > /dev/null 2>&1; echo ABC > %1 && rm %1")
.arg("/var/run/qtc_xxxx.pid")}};
m_varRunProcess.setCommand(cmd);
m_varRunProcess.start();
}
void QnxDeviceTester::handleVarRunDone()
{
if (m_varRunProcess.result() == ProcessResult::FinishedWithSuccess) {
emit progressMessage(Tr::tr("Files can be created in /var/run.") + '\n');
} else {
m_result = TestFailure;
const QString message = m_varRunProcess.result() == ProcessResult::StartFailed
? Tr::tr("An error occurred while checking that files can be created in /var/run.")
+ '\n' + m_varRunProcess.errorString()
: Tr::tr("Files cannot be created in /var/run.");
emit errorMessage(message + '\n');
}
setFinished(m_result);
}
void QnxDeviceTester::setFinished(TestResult result)
{
if (m_result == TestSuccess)
m_result = result;
m_state = Inactive;
disconnect(m_genericTester, nullptr, this, nullptr);
m_varRunProcess.close();
emit finished(m_result);
}
QStringList QnxDeviceTester::versionSpecificCommandsToTest(int versionNumber) const
{
QStringList result;
if (versionNumber > 0x060500)
result << QLatin1String("slog2info");
return result;
} }
} // Qnx::Internal } // Qnx::Internal

View File

@@ -4,9 +4,6 @@
#pragma once #pragma once
#include <remotelinux/linuxdevicetester.h> #include <remotelinux/linuxdevicetester.h>
#include <utils/qtcprocess.h>
#include <QStringList>
namespace Qnx { namespace Qnx {
namespace Internal { namespace Internal {
@@ -22,25 +19,8 @@ public:
void stopTest() override; void stopTest() override;
private: private:
enum State { RemoteLinux::GenericLinuxDeviceTester *m_genericTester = nullptr;
Inactive,
GenericTest,
VarRunTest
};
void handleGenericTestFinished(ProjectExplorer::DeviceTester::TestResult result);
void handleVarRunDone();
void setFinished(ProjectExplorer::DeviceTester::TestResult result);
QStringList versionSpecificCommandsToTest(int versionNumber) const;
RemoteLinux::GenericLinuxDeviceTester *m_genericTester;
ProjectExplorer::IDevice::ConstPtr m_deviceConfiguration; ProjectExplorer::IDevice::ConstPtr m_deviceConfiguration;
ProjectExplorer::DeviceTester::TestResult m_result = TestSuccess;
State m_state = Inactive;
Utils::QtcProcess m_varRunProcess;
}; };
} // namespace Internal } // namespace Internal