forked from qt-creator/qt-creator
GenericLinuxDeviceTester: Replace connection test with echo
If the echo command succeeds, the connection is established properly. Remove the usage of SshConnection from this test. Change-Id: I02c6bf9214e01353be938ed6cd87d625b37672ee Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -29,8 +29,6 @@
|
|||||||
#include "remotelinux_constants.h"
|
#include "remotelinux_constants.h"
|
||||||
|
|
||||||
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
||||||
#include <ssh/sshconnection.h>
|
|
||||||
#include <ssh/sshconnectionmanager.h>
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/port.h>
|
#include <utils/port.h>
|
||||||
#include <utils/processinterface.h>
|
#include <utils/processinterface.h>
|
||||||
@@ -38,14 +36,13 @@
|
|||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace QSsh;
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
enum State { Inactive, Connecting, RunningUname, TestingPorts, TestingSftp, TestingRsync };
|
enum State { Inactive, TestingEcho, TestingUname, TestingPorts, TestingSftp, TestingRsync };
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
@@ -53,7 +50,7 @@ class GenericLinuxDeviceTesterPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IDevice::Ptr device;
|
IDevice::Ptr device;
|
||||||
SshConnection *connection = nullptr;
|
QtcProcess echoProcess;
|
||||||
QtcProcess unameProcess;
|
QtcProcess unameProcess;
|
||||||
DeviceUsedPortsGatherer portsGatherer;
|
DeviceUsedPortsGatherer portsGatherer;
|
||||||
FileTransfer fileTransfer;
|
FileTransfer fileTransfer;
|
||||||
@@ -68,6 +65,8 @@ using namespace Internal;
|
|||||||
GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
|
GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
|
||||||
: DeviceTester(parent), d(new GenericLinuxDeviceTesterPrivate)
|
: DeviceTester(parent), d(new GenericLinuxDeviceTesterPrivate)
|
||||||
{
|
{
|
||||||
|
connect(&d->echoProcess, &QtcProcess::done, this,
|
||||||
|
&GenericLinuxDeviceTester::handleEchoDone);
|
||||||
connect(&d->unameProcess, &QtcProcess::done, this,
|
connect(&d->unameProcess, &QtcProcess::done, this,
|
||||||
&GenericLinuxDeviceTester::handleUnameDone);
|
&GenericLinuxDeviceTester::handleUnameDone);
|
||||||
connect(&d->portsGatherer, &DeviceUsedPortsGatherer::error,
|
connect(&d->portsGatherer, &DeviceUsedPortsGatherer::error,
|
||||||
@@ -78,11 +77,7 @@ GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
|
|||||||
this, &GenericLinuxDeviceTester::handleFileTransferDone);
|
this, &GenericLinuxDeviceTester::handleFileTransferDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
|
GenericLinuxDeviceTester::~GenericLinuxDeviceTester() = default;
|
||||||
{
|
|
||||||
if (d->connection)
|
|
||||||
SshConnectionManager::releaseConnection(d->connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GenericLinuxDeviceTester::testDevice(const IDevice::Ptr &deviceConfiguration)
|
void GenericLinuxDeviceTester::testDevice(const IDevice::Ptr &deviceConfiguration)
|
||||||
{
|
{
|
||||||
@@ -90,16 +85,8 @@ void GenericLinuxDeviceTester::testDevice(const IDevice::Ptr &deviceConfiguratio
|
|||||||
|
|
||||||
d->device = deviceConfiguration;
|
d->device = deviceConfiguration;
|
||||||
d->fileTransfer.setDevice(d->device);
|
d->fileTransfer.setDevice(d->device);
|
||||||
SshConnectionManager::forceNewConnection(deviceConfiguration->sshParameters());
|
|
||||||
d->connection = SshConnectionManager::acquireConnection(deviceConfiguration->sshParameters());
|
|
||||||
connect(d->connection, &SshConnection::connected,
|
|
||||||
this, &GenericLinuxDeviceTester::handleConnected);
|
|
||||||
connect(d->connection, &SshConnection::errorOccurred,
|
|
||||||
this, &GenericLinuxDeviceTester::handleConnectionFailure);
|
|
||||||
|
|
||||||
emit progressMessage(tr("Connecting to device..."));
|
testEcho();
|
||||||
d->state = Connecting;
|
|
||||||
d->connection->connectToHost();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLinuxDeviceTester::stopTest()
|
void GenericLinuxDeviceTester::stopTest()
|
||||||
@@ -107,13 +94,13 @@ void GenericLinuxDeviceTester::stopTest()
|
|||||||
QTC_ASSERT(d->state != Inactive, return);
|
QTC_ASSERT(d->state != Inactive, return);
|
||||||
|
|
||||||
switch (d->state) {
|
switch (d->state) {
|
||||||
case Connecting:
|
case TestingEcho:
|
||||||
d->connection->disconnectFromHost();
|
d->echoProcess.close();
|
||||||
break;
|
break;
|
||||||
case TestingPorts:
|
case TestingPorts:
|
||||||
d->portsGatherer.stop();
|
d->portsGatherer.stop();
|
||||||
break;
|
break;
|
||||||
case RunningUname:
|
case TestingUname:
|
||||||
d->unameProcess.close();
|
d->unameProcess.close();
|
||||||
break;
|
break;
|
||||||
case TestingSftp:
|
case TestingSftp:
|
||||||
@@ -127,26 +114,41 @@ void GenericLinuxDeviceTester::stopTest()
|
|||||||
setFinished(TestFailure);
|
setFinished(TestFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLinuxDeviceTester::handleConnectionFailure()
|
static const char s_echoContents[] = "Hello Remote World!";
|
||||||
|
|
||||||
|
void GenericLinuxDeviceTester::testEcho()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state != Inactive, return);
|
d->state = TestingEcho;
|
||||||
|
emit progressMessage(tr("Sending echo to device..."));
|
||||||
|
|
||||||
emit errorMessage(d->connection->errorString() + QLatin1Char('\n'));
|
d->echoProcess.setCommand({d->device->filePath("echo"), {s_echoContents}});
|
||||||
|
d->echoProcess.start();
|
||||||
setFinished(TestFailure);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLinuxDeviceTester::handleConnected()
|
void GenericLinuxDeviceTester::handleEchoDone()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state == Connecting, return);
|
QTC_ASSERT(d->state == TestingEcho, return);
|
||||||
emit progressMessage(tr("Connection to device established.") + QLatin1Char('\n'));
|
if (d->echoProcess.result() != ProcessResult::FinishedWithSuccess) {
|
||||||
|
const QByteArray stdErrOutput = d->echoProcess.readAllStandardError();
|
||||||
|
if (!stdErrOutput.isEmpty())
|
||||||
|
emit errorMessage(tr("echo failed: %1").arg(QString::fromUtf8(stdErrOutput)) + '\n');
|
||||||
|
else
|
||||||
|
emit errorMessage(tr("echo failed.") + '\n');
|
||||||
|
setFinished(TestFailure);
|
||||||
|
} else {
|
||||||
|
const QString reply = d->echoProcess.stdOut().chopped(1); // Remove trailing \n
|
||||||
|
if (reply != s_echoContents)
|
||||||
|
emit errorMessage(tr("Device replied to echo with unexpected contents.") + '\n');
|
||||||
|
else
|
||||||
|
emit progressMessage(tr("Device replied to echo with expected contents.") + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
testUname();
|
testUname();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericLinuxDeviceTester::testUname()
|
void GenericLinuxDeviceTester::testUname()
|
||||||
{
|
{
|
||||||
d->state = RunningUname;
|
d->state = TestingUname;
|
||||||
emit progressMessage(tr("Checking kernel version..."));
|
emit progressMessage(tr("Checking kernel version..."));
|
||||||
|
|
||||||
d->unameProcess.setCommand({d->device->filePath("uname"), {"-rsm"}});
|
d->unameProcess.setCommand({d->device->filePath("uname"), {"-rsm"}});
|
||||||
@@ -155,7 +157,7 @@ void GenericLinuxDeviceTester::testUname()
|
|||||||
|
|
||||||
void GenericLinuxDeviceTester::handleUnameDone()
|
void GenericLinuxDeviceTester::handleUnameDone()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state == RunningUname, return);
|
QTC_ASSERT(d->state == TestingUname, return);
|
||||||
|
|
||||||
if (!d->unameProcess.errorString().isEmpty() || d->unameProcess.exitCode() != 0) {
|
if (!d->unameProcess.errorString().isEmpty() || d->unameProcess.exitCode() != 0) {
|
||||||
const QByteArray stderrOutput = d->unameProcess.readAllStandardError();
|
const QByteArray stderrOutput = d->unameProcess.readAllStandardError();
|
||||||
@@ -259,11 +261,6 @@ void GenericLinuxDeviceTester::handleFileTransferDone(const ProcessResultData &r
|
|||||||
void GenericLinuxDeviceTester::setFinished(TestResult result)
|
void GenericLinuxDeviceTester::setFinished(TestResult result)
|
||||||
{
|
{
|
||||||
d->state = Inactive;
|
d->state = Inactive;
|
||||||
if (d->connection) {
|
|
||||||
disconnect(d->connection, nullptr, this, nullptr);
|
|
||||||
SshConnectionManager::releaseConnection(d->connection);
|
|
||||||
d->connection = nullptr;
|
|
||||||
}
|
|
||||||
emit finished(result);
|
emit finished(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ public:
|
|||||||
void stopTest() override;
|
void stopTest() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleConnectionFailure();
|
void testEcho();
|
||||||
void handleConnected();
|
void handleEchoDone();
|
||||||
|
|
||||||
void testUname();
|
void testUname();
|
||||||
void handleUnameDone();
|
void handleUnameDone();
|
||||||
|
|||||||
Reference in New Issue
Block a user