2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-07-21 11:30:56 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2012-07-26 23:29:00 +02:00
|
|
|
#include "linuxdevicetester.h"
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2012-07-26 23:29:00 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.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-07-25 17:41:01 +02:00
|
|
|
using namespace ProjectExplorer;
|
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
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
IDevice::ConstPtr deviceConfiguration;
|
2012-05-29 13:22:33 +02:00
|
|
|
SshConnection *connection;
|
2011-12-21 20:14:42 +01:00
|
|
|
SshRemoteProcess::Ptr process;
|
2012-07-26 23:29:00 +02:00
|
|
|
DeviceUsedPortsGatherer portsGatherer;
|
2011-12-21 20:14:42 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
void GenericLinuxDeviceTester::testDevice(const IDevice::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-07-26 23:29:00 +02:00
|
|
|
DeviceUsedPortsGatherer *GenericLinuxDeviceTester::usedPortsGatherer() const
|
2012-06-29 07:23:13 +02:00
|
|
|
{
|
|
|
|
|
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)));
|
|
|
|
|
|
2012-11-24 21:06:36 +02:00
|
|
|
emit progressMessage(tr("Checking kernel version..."));
|
2011-12-21 20:14:42 +01:00
|
|
|
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()) {
|
2012-11-24 21:06:36 +02:00
|
|
|
emit progressMessage(tr("All specified ports are available.\n"));
|
2011-12-21 20:14:42 +01:00
|
|
|
} 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
|