forked from qt-creator/qt-creator
SSH: Derive SshRemoteProcess from QIODevice.
Now it looks even more like QProcess. Things like process channels are still missing. Change-Id: I3f30cd00ed4a054d02e83add9a6f4162b48f8345 Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <utils/ssh/sshpseudoterminal.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QTextStream>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#include <iostream>
|
||||
@@ -75,9 +76,10 @@ void RemoteProcessTest::run()
|
||||
|
||||
void RemoteProcessTest::handleConnectionError()
|
||||
{
|
||||
std::cerr << "Error: Connection failure ("
|
||||
<< qPrintable(m_remoteRunner->lastConnectionErrorString()) << ")."
|
||||
<< std::endl;
|
||||
const QString error = m_state == TestingIoDevice
|
||||
? m_sshConnection->errorString() : m_remoteRunner->lastConnectionErrorString();
|
||||
|
||||
std::cerr << "Error: Connection failure (" << qPrintable(error) << ")." << std::endl;
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
@@ -92,6 +94,11 @@ void RemoteProcessTest::handleProcessStarted()
|
||||
Utils::SshRemoteProcessRunner * const killer
|
||||
= new Utils::SshRemoteProcessRunner(this);
|
||||
killer->run("pkill -9 sleep", m_sshParams);
|
||||
} else if (m_state == TestingIoDevice) {
|
||||
connect(m_catProcess.data(), SIGNAL(readyRead()), SLOT(handleReadyRead()));
|
||||
m_textStream = new QTextStream(m_catProcess.data());
|
||||
*m_textStream << testString();
|
||||
m_textStream->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,10 +205,16 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
|
||||
qApp->quit();
|
||||
return;
|
||||
}
|
||||
std::cout << "Ok.\nAll tests succeeded." << std::endl;
|
||||
qApp->quit();
|
||||
std::cout << "Ok.\nTesting I/O device functionality... " << std::flush;
|
||||
m_state = TestingIoDevice;
|
||||
m_sshConnection = Utils::SshConnection::create(m_sshParams);
|
||||
connect(m_sshConnection.data(), SIGNAL(connected()), SLOT(handleConnected()));
|
||||
connect(m_sshConnection.data(), SIGNAL(error(Utils::SshError)),
|
||||
SLOT(handleConnectionError()));
|
||||
m_sshConnection->connectToHost();
|
||||
break;
|
||||
}
|
||||
case TestingIoDevice:
|
||||
case Inactive:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
@@ -216,16 +229,23 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
|
||||
qApp->quit();
|
||||
break;
|
||||
case SshRemoteProcess::KilledBySignal:
|
||||
if (m_state != TestingCrash) {
|
||||
switch (m_state) {
|
||||
case TestingCrash:
|
||||
std::cout << "Ok.\nTesting remote process with terminal... " << std::flush;
|
||||
m_state = TestingTerminal;
|
||||
m_started = false;
|
||||
m_timeoutTimer->start();
|
||||
m_remoteRunner->runInTerminal("top -n 1", SshPseudoTerminal(), m_sshParams);
|
||||
break;
|
||||
case TestingIoDevice:
|
||||
std::cout << "Ok.\nAll tests succeeded." << std::endl;
|
||||
qApp->quit();
|
||||
break;
|
||||
default:
|
||||
std::cerr << "Error: Unexpected crash." << std::endl;
|
||||
qApp->quit();
|
||||
return;
|
||||
}
|
||||
std::cout << "Ok.\nTesting remote process with terminal... " << std::flush;
|
||||
m_state = TestingTerminal;
|
||||
m_started = false;
|
||||
m_timeoutTimer->start();
|
||||
m_remoteRunner->runInTerminal("top -n 1", SshPseudoTerminal(), m_sshParams);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,3 +254,35 @@ void RemoteProcessTest::handleTimeout()
|
||||
std::cerr << "Error: Timeout waiting for progress." << std::endl;
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
void RemoteProcessTest::handleConnected()
|
||||
{
|
||||
Q_ASSERT(m_state == TestingIoDevice);
|
||||
|
||||
m_catProcess = m_sshConnection->createRemoteProcess(QString::fromLocal8Bit("cat").toUtf8());
|
||||
connect(m_catProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
|
||||
connect(m_catProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
|
||||
m_started = false;
|
||||
m_timeoutTimer->start();
|
||||
m_catProcess->start();
|
||||
}
|
||||
|
||||
QString RemoteProcessTest::testString() const
|
||||
{
|
||||
return QLatin1String("x");
|
||||
}
|
||||
|
||||
void RemoteProcessTest::handleReadyRead()
|
||||
{
|
||||
Q_ASSERT(m_state == TestingIoDevice);
|
||||
|
||||
const QString &data = QString::fromUtf8(m_catProcess->readAll());
|
||||
if (data != testString()) {
|
||||
std::cerr << "Testing of QIODevice functionality failed: Expected '"
|
||||
<< qPrintable(testString()) << "', got '" << qPrintable(data) << "'." << std::endl;
|
||||
qApp->exit(1);
|
||||
}
|
||||
|
||||
Utils::SshRemoteProcessRunner * const killer = new Utils::SshRemoteProcessRunner(this);
|
||||
killer->run("pkill -9 cat", m_sshParams);
|
||||
}
|
||||
|
||||
@@ -35,9 +35,11 @@
|
||||
|
||||
#include <utils/ssh/sshremoteprocessrunner.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer);
|
||||
#include <QtCore/QObject>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QTextStream)
|
||||
QT_FORWARD_DECLARE_CLASS(QTimer)
|
||||
|
||||
class RemoteProcessTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -53,13 +55,22 @@ private slots:
|
||||
void handleProcessStderr(const QByteArray &output);
|
||||
void handleProcessClosed(int exitStatus);
|
||||
void handleTimeout();
|
||||
void handleReadyRead();
|
||||
void handleConnected();
|
||||
|
||||
private:
|
||||
enum State { Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal };
|
||||
enum State {
|
||||
Inactive, TestingSuccess, TestingFailure, TestingCrash, TestingTerminal, TestingIoDevice
|
||||
};
|
||||
|
||||
QString testString() const;
|
||||
|
||||
const Utils::SshConnectionParameters m_sshParams;
|
||||
QTimer * const m_timeoutTimer;
|
||||
QTextStream *m_textStream;
|
||||
Utils::SshRemoteProcessRunner * const m_remoteRunner;
|
||||
Utils::SshRemoteProcess::Ptr m_catProcess;
|
||||
Utils::SshConnection::Ptr m_sshConnection;
|
||||
QByteArray m_remoteStdout;
|
||||
QByteArray m_remoteStderr;
|
||||
State m_state;
|
||||
|
||||
@@ -115,5 +115,5 @@ void Shell::handleChannelClosed(int exitStatus)
|
||||
|
||||
void Shell::handleStdin()
|
||||
{
|
||||
m_shell->sendInput(m_stdin->readLine());
|
||||
m_shell->write(m_stdin->readLine());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user