2011-07-21 11:30:56 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
#include "linuxdevicetester.h"
|
|
|
|
|
|
|
|
|
|
#include "linuxdeviceconfiguration.h"
|
2011-07-22 16:04:55 +02:00
|
|
|
#include "remotelinuxusedportsgatherer.h"
|
2011-07-21 11:30:56 +02:00
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshremoteprocess.h>
|
|
|
|
|
#include <ssh/sshconnection.h>
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2012-05-18 10:49:35 +02:00
|
|
|
using namespace QSsh;
|
2011-07-21 11:30:56 +02:00
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
2011-12-21 20:14:42 +01:00
|
|
|
namespace {
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
enum State { Inactive, Connecting, RunningUname, TestingPorts };
|
|
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
class GenericLinuxDeviceTesterPrivate
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2012-05-29 13:22:33 +02:00
|
|
|
GenericLinuxDeviceTesterPrivate() : connection(0), state(Inactive) {}
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
LinuxDeviceConfiguration::ConstPtr deviceConfiguration;
|
2012-05-29 13:22:33 +02:00
|
|
|
SshConnection *connection;
|
2011-12-21 20:14:42 +01:00
|
|
|
SshRemoteProcess::Ptr process;
|
|
|
|
|
RemoteLinuxUsedPortsGatherer portsGatherer;
|
|
|
|
|
State state;
|
2011-07-21 11:30:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
AbstractLinuxDeviceTester::AbstractLinuxDeviceTester(QObject *parent) : QObject(parent)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
|
|
|
|
|
GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
|
|
|
|
|
: AbstractLinuxDeviceTester(parent), d(new GenericLinuxDeviceTesterPrivate)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
delete d;
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::testDevice(const LinuxDeviceConfiguration::ConstPtr &deviceConfiguration)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == Inactive, return);
|
|
|
|
|
|
|
|
|
|
d->deviceConfiguration = deviceConfiguration;
|
2012-06-08 08:48:03 +02:00
|
|
|
d->connection = new SshConnection(deviceConfiguration->sshParameters(), this);
|
2012-05-29 13:22:33 +02:00
|
|
|
connect(d->connection, SIGNAL(connected()), SLOT(handleConnected()));
|
|
|
|
|
connect(d->connection, SIGNAL(error(QSsh::SshError)),
|
2011-12-21 20:14:42 +01:00
|
|
|
SLOT(handleConnectionFailure()));
|
|
|
|
|
|
|
|
|
|
emit progressMessage(tr("Connecting to host..."));
|
|
|
|
|
d->state = Connecting;
|
|
|
|
|
d->connection->connectToHost();
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::stopTest()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state != Inactive, return);
|
|
|
|
|
|
|
|
|
|
switch (d->state) {
|
|
|
|
|
case Connecting:
|
|
|
|
|
d->connection->disconnectFromHost();
|
|
|
|
|
break;
|
|
|
|
|
case TestingPorts:
|
|
|
|
|
d->portsGatherer.stop();
|
|
|
|
|
break;
|
|
|
|
|
case RunningUname:
|
|
|
|
|
d->process->close();
|
|
|
|
|
break;
|
|
|
|
|
case Inactive:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-29 07:23:13 +02:00
|
|
|
RemoteLinuxUsedPortsGatherer *GenericLinuxDeviceTester::usedPortsGatherer() const
|
|
|
|
|
{
|
|
|
|
|
return &d->portsGatherer;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handleConnected()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == Connecting, return);
|
|
|
|
|
|
|
|
|
|
d->process = d->connection->createRemoteProcess("uname -rsm");
|
|
|
|
|
connect(d->process.data(), SIGNAL(closed(int)), SLOT(handleProcessFinished(int)));
|
|
|
|
|
|
|
|
|
|
emit progressMessage("Checking kernel version...");
|
|
|
|
|
d->state = RunningUname;
|
|
|
|
|
d->process->start();
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handleConnectionFailure()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state != Inactive, return);
|
|
|
|
|
|
|
|
|
|
emit errorMessage(tr("SSH connection failure: %1\n").arg(d->connection->errorString()));
|
|
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handleProcessFinished(int exitStatus)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == RunningUname, return);
|
|
|
|
|
|
2012-06-08 08:23:32 +02:00
|
|
|
if (exitStatus != SshRemoteProcess::NormalExit || d->process->exitCode() != 0) {
|
2011-12-21 20:14:42 +01:00
|
|
|
const QByteArray stderrOutput = d->process->readAllStandardError();
|
|
|
|
|
if (!stderrOutput.isEmpty())
|
|
|
|
|
emit errorMessage(tr("uname failed: %1\n").arg(QString::fromUtf8(stderrOutput)));
|
|
|
|
|
else
|
|
|
|
|
emit errorMessage(tr("uname failed.\n"));
|
|
|
|
|
} else {
|
|
|
|
|
emit progressMessage(QString::fromUtf8(d->process->readAllStandardOutput()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(&d->portsGatherer, SIGNAL(error(QString)), SLOT(handlePortsGatheringError(QString)));
|
|
|
|
|
connect(&d->portsGatherer, SIGNAL(portListReady()), SLOT(handlePortListReady()));
|
|
|
|
|
|
|
|
|
|
emit progressMessage(tr("Checking if specified ports are available..."));
|
|
|
|
|
d->state = TestingPorts;
|
2012-04-03 10:23:59 +02:00
|
|
|
d->portsGatherer.start(d->deviceConfiguration);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handlePortsGatheringError(const QString &message)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == TestingPorts, return);
|
|
|
|
|
|
|
|
|
|
emit errorMessage(tr("Error gathering ports: %1\n").arg(message));
|
|
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handlePortListReady()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == TestingPorts, return);
|
|
|
|
|
|
|
|
|
|
if (d->portsGatherer.usedPorts().isEmpty()) {
|
|
|
|
|
emit progressMessage("All specified ports are available.\n");
|
|
|
|
|
} else {
|
|
|
|
|
QString portList;
|
|
|
|
|
foreach (const int port, d->portsGatherer.usedPorts())
|
|
|
|
|
portList += QString::number(port) + QLatin1String(", ");
|
|
|
|
|
portList.remove(portList.count() - 2, 2);
|
|
|
|
|
emit errorMessage(tr("The following specified ports are currently in use: %1\n")
|
|
|
|
|
.arg(portList));
|
|
|
|
|
}
|
|
|
|
|
setFinished(TestSuccess);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::setFinished(TestResult result)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
d->state = Inactive;
|
|
|
|
|
disconnect(&d->portsGatherer, 0, this, 0);
|
2012-06-05 15:18:55 +02:00
|
|
|
if (d->connection) {
|
|
|
|
|
disconnect(d->connection, 0, this, 0);
|
|
|
|
|
d->connection->deleteLater();
|
|
|
|
|
d->connection = 0;
|
|
|
|
|
}
|
2011-12-21 20:14:42 +01:00
|
|
|
emit finished(result);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|