forked from qt-creator/qt-creator
SSH: Update tests.
- Adapt to recent API change. - Take into account that some shells don't report the "killed" signal. - Take into account that cat and sleep are built-ins in some shells. Change-Id: Ib33d89c65641340d704f88114834085b4c9b0e8b Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
@@ -48,7 +48,7 @@ public:
|
|||||||
Test()
|
Test()
|
||||||
{
|
{
|
||||||
m_timeoutTimer.setSingleShot(true);
|
m_timeoutTimer.setSingleShot(true);
|
||||||
m_connection = SshConnection::create(SshConnectionParameters(SshConnectionParameters::DefaultProxy));
|
m_connection = SshConnection::create(SshConnectionParameters());
|
||||||
if (m_connection->state() != SshConnection::Unconnected) {
|
if (m_connection->state() != SshConnection::Unconnected) {
|
||||||
qDebug("Error: Newly created SSH connection has state %d.",
|
qDebug("Error: Newly created SSH connection has state %d.",
|
||||||
m_connection->state());
|
m_connection->state());
|
||||||
@@ -59,13 +59,13 @@ public:
|
|||||||
if (m_connection->createSftpChannel())
|
if (m_connection->createSftpChannel())
|
||||||
qDebug("Error: Unconnected SSH connection creates SFTP channel.");
|
qDebug("Error: Unconnected SSH connection creates SFTP channel.");
|
||||||
|
|
||||||
SshConnectionParameters noHost = SshConnectionParameters(SshConnectionParameters::DefaultProxy);
|
SshConnectionParameters noHost;
|
||||||
noHost.host = QLatin1String("hgdfxgfhgxfhxgfchxgcf");
|
noHost.host = QLatin1String("hgdfxgfhgxfhxgfchxgcf");
|
||||||
noHost.port = 12345;
|
noHost.port = 12345;
|
||||||
noHost.timeout = 10;
|
noHost.timeout = 10;
|
||||||
noHost.authenticationType = SshConnectionParameters::AuthenticationByPassword;
|
noHost.authenticationType = SshConnectionParameters::AuthenticationByPassword;
|
||||||
|
|
||||||
SshConnectionParameters noUser = SshConnectionParameters(SshConnectionParameters::DefaultProxy);
|
SshConnectionParameters noUser;
|
||||||
noUser.host = QLatin1String("localhost");
|
noUser.host = QLatin1String("localhost");
|
||||||
noUser.port = 22;
|
noUser.port = 22;
|
||||||
noUser.timeout = 30;
|
noUser.timeout = 30;
|
||||||
@@ -73,7 +73,7 @@ public:
|
|||||||
noUser.userName = QLatin1String("dumdidumpuffpuff");
|
noUser.userName = QLatin1String("dumdidumpuffpuff");
|
||||||
noUser.password = QLatin1String("whatever");
|
noUser.password = QLatin1String("whatever");
|
||||||
|
|
||||||
SshConnectionParameters wrongPwd = SshConnectionParameters(SshConnectionParameters::DefaultProxy);
|
SshConnectionParameters wrongPwd;
|
||||||
wrongPwd.host = QLatin1String("localhost");
|
wrongPwd.host = QLatin1String("localhost");
|
||||||
wrongPwd.port = 22;
|
wrongPwd.port = 22;
|
||||||
wrongPwd.timeout = 30;
|
wrongPwd.timeout = 30;
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
wrongPwd.userName = QLatin1String("root");
|
wrongPwd.userName = QLatin1String("root");
|
||||||
noUser.password = QLatin1String("thiscantpossiblybeapasswordcanit");
|
noUser.password = QLatin1String("thiscantpossiblybeapasswordcanit");
|
||||||
|
|
||||||
SshConnectionParameters invalidKeyFile = SshConnectionParameters(SshConnectionParameters::DefaultProxy);
|
SshConnectionParameters invalidKeyFile;
|
||||||
invalidKeyFile.host = QLatin1String("localhost");
|
invalidKeyFile.host = QLatin1String("localhost");
|
||||||
invalidKeyFile.port = 22;
|
invalidKeyFile.port = 22;
|
||||||
invalidKeyFile.timeout = 30;
|
invalidKeyFile.timeout = 30;
|
||||||
|
@@ -46,7 +46,7 @@ ArgumentsCollector::ArgumentsCollector(const QStringList &args)
|
|||||||
|
|
||||||
Utils::SshConnectionParameters ArgumentsCollector::collect(bool &success) const
|
Utils::SshConnectionParameters ArgumentsCollector::collect(bool &success) const
|
||||||
{
|
{
|
||||||
SshConnectionParameters parameters(Utils::SshConnectionParameters::NoProxy);
|
SshConnectionParameters parameters;
|
||||||
try {
|
try {
|
||||||
bool authTypeGiven = false;
|
bool authTypeGiven = false;
|
||||||
bool portGiven = false;
|
bool portGiven = false;
|
||||||
|
@@ -185,13 +185,18 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
|
|||||||
m_state = TestingCrash;
|
m_state = TestingCrash;
|
||||||
m_started = false;
|
m_started = false;
|
||||||
m_timeoutTimer->start();
|
m_timeoutTimer->start();
|
||||||
m_remoteRunner->run("sleep 100", m_sshParams);
|
m_remoteRunner->run("/bin/sleep 100", m_sshParams);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TestingCrash:
|
case TestingCrash:
|
||||||
|
if (m_remoteRunner->processExitCode() == 0) {
|
||||||
std::cerr << "Error: Successful exit from process that was "
|
std::cerr << "Error: Successful exit from process that was "
|
||||||
"supposed to crash." << std::endl;
|
"supposed to crash." << std::endl;
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
|
} else {
|
||||||
|
// Some shells (e.g. mksh) don't report "killed", but just a non-zero exit code.
|
||||||
|
handleSuccessfulCrashTest();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TestingTerminal: {
|
case TestingTerminal: {
|
||||||
const int exitCode = m_remoteRunner->processExitCode();
|
const int exitCode = m_remoteRunner->processExitCode();
|
||||||
@@ -218,9 +223,13 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TestingIoDevice:
|
case TestingIoDevice:
|
||||||
|
if (m_catProcess->exitCode() == 0) {
|
||||||
std::cerr << "Error: Successful exit from process that was supposed to crash."
|
std::cerr << "Error: Successful exit from process that was supposed to crash."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
qApp->exit(EXIT_FAILURE);
|
qApp->exit(EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
handleSuccessfulIoTest();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TestingProcessChannels:
|
case TestingProcessChannels:
|
||||||
if (m_remoteStderr.isEmpty()) {
|
if (m_remoteStderr.isEmpty()) {
|
||||||
@@ -253,26 +262,10 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
|
|||||||
case SshRemoteProcess::KilledBySignal:
|
case SshRemoteProcess::KilledBySignal:
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
case TestingCrash:
|
case TestingCrash:
|
||||||
std::cout << "Ok.\nTesting remote process with terminal... " << std::flush;
|
handleSuccessfulCrashTest();
|
||||||
m_state = TestingTerminal;
|
|
||||||
m_started = false;
|
|
||||||
m_timeoutTimer->start();
|
|
||||||
m_remoteRunner->runInTerminal("top -n 1", SshPseudoTerminal(), m_sshParams);
|
|
||||||
break;
|
break;
|
||||||
case TestingIoDevice:
|
case TestingIoDevice:
|
||||||
std::cout << "Ok\nTesting process channels... " << std::flush;
|
handleSuccessfulIoTest();
|
||||||
m_state = TestingProcessChannels;
|
|
||||||
m_started = false;
|
|
||||||
m_remoteStderr.clear();
|
|
||||||
m_echoProcess = m_sshConnection->createRemoteProcess("printf " + StderrOutput + " >&2");
|
|
||||||
m_echoProcess->setReadChannel(QProcess::StandardError);
|
|
||||||
connect(m_echoProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
|
|
||||||
connect(m_echoProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
|
|
||||||
connect(m_echoProcess.data(), SIGNAL(readyRead()), SLOT(handleReadyRead()));
|
|
||||||
connect(m_echoProcess.data(), SIGNAL(readyReadStandardError()),
|
|
||||||
SLOT(handleReadyReadStderr()));
|
|
||||||
m_echoProcess->start();
|
|
||||||
m_timeoutTimer->start();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cerr << "Error: Unexpected crash." << std::endl;
|
std::cerr << "Error: Unexpected crash." << std::endl;
|
||||||
@@ -292,7 +285,7 @@ void RemoteProcessTest::handleConnected()
|
|||||||
{
|
{
|
||||||
Q_ASSERT(m_state == TestingIoDevice);
|
Q_ASSERT(m_state == TestingIoDevice);
|
||||||
|
|
||||||
m_catProcess = m_sshConnection->createRemoteProcess(QString::fromLocal8Bit("cat").toUtf8());
|
m_catProcess = m_sshConnection->createRemoteProcess(QString::fromLocal8Bit("/bin/cat").toUtf8());
|
||||||
connect(m_catProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
|
connect(m_catProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
|
||||||
connect(m_catProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
|
connect(m_catProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
|
||||||
m_started = false;
|
m_started = false;
|
||||||
@@ -302,7 +295,7 @@ void RemoteProcessTest::handleConnected()
|
|||||||
|
|
||||||
QString RemoteProcessTest::testString() const
|
QString RemoteProcessTest::testString() const
|
||||||
{
|
{
|
||||||
return QLatin1String("x");
|
return QLatin1String("x\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteProcessTest::handleReadyRead()
|
void RemoteProcessTest::handleReadyRead()
|
||||||
@@ -342,3 +335,29 @@ void RemoteProcessTest::handleReadyReadStderr()
|
|||||||
|
|
||||||
m_remoteStderr = "dummy";
|
m_remoteStderr = "dummy";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RemoteProcessTest::handleSuccessfulCrashTest()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoteProcessTest::handleSuccessfulIoTest()
|
||||||
|
{
|
||||||
|
std::cout << "Ok\nTesting process channels... " << std::flush;
|
||||||
|
m_state = TestingProcessChannels;
|
||||||
|
m_started = false;
|
||||||
|
m_remoteStderr.clear();
|
||||||
|
m_echoProcess = m_sshConnection->createRemoteProcess("printf " + StderrOutput + " >&2");
|
||||||
|
m_echoProcess->setReadChannel(QProcess::StandardError);
|
||||||
|
connect(m_echoProcess.data(), SIGNAL(started()), SLOT(handleProcessStarted()));
|
||||||
|
connect(m_echoProcess.data(), SIGNAL(closed(int)), SLOT(handleProcessClosed(int)));
|
||||||
|
connect(m_echoProcess.data(), SIGNAL(readyRead()), SLOT(handleReadyRead()));
|
||||||
|
connect(m_echoProcess.data(), SIGNAL(readyReadStandardError()),
|
||||||
|
SLOT(handleReadyReadStderr()));
|
||||||
|
m_echoProcess->start();
|
||||||
|
m_timeoutTimer->start();
|
||||||
|
}
|
||||||
|
@@ -67,6 +67,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QString testString() const;
|
QString testString() const;
|
||||||
|
void handleSuccessfulCrashTest();
|
||||||
|
void handleSuccessfulIoTest();
|
||||||
|
|
||||||
const Utils::SshConnectionParameters m_sshParams;
|
const Utils::SshConnectionParameters m_sshParams;
|
||||||
QTimer * const m_timeoutTimer;
|
QTimer * const m_timeoutTimer;
|
||||||
|
@@ -36,8 +36,6 @@
|
|||||||
#include <utils/ssh/sshconnection.h>
|
#include <utils/ssh/sshconnection.h>
|
||||||
|
|
||||||
struct Parameters {
|
struct Parameters {
|
||||||
Parameters() : sshParams(Utils::SshConnectionParameters::DefaultProxy) {}
|
|
||||||
|
|
||||||
Utils::SshConnectionParameters sshParams;
|
Utils::SshConnectionParameters sshParams;
|
||||||
int smallFileCount;
|
int smallFileCount;
|
||||||
int bigFileSize;
|
int bigFileSize;
|
||||||
|
@@ -62,7 +62,7 @@ SftpFsWindow::~SftpFsWindow()
|
|||||||
void SftpFsWindow::connectToHost()
|
void SftpFsWindow::connectToHost()
|
||||||
{
|
{
|
||||||
m_ui->connectButton->setEnabled(false);
|
m_ui->connectButton->setEnabled(false);
|
||||||
SshConnectionParameters sshParams(SshConnectionParameters::NoProxy);
|
SshConnectionParameters sshParams;
|
||||||
sshParams.host = m_ui->hostLineEdit->text();
|
sshParams.host = m_ui->hostLineEdit->text();
|
||||||
sshParams.userName = m_ui->userLineEdit->text();
|
sshParams.userName = m_ui->userLineEdit->text();
|
||||||
sshParams.authenticationType = SshConnectionParameters::AuthenticationByPassword;
|
sshParams.authenticationType = SshConnectionParameters::AuthenticationByPassword;
|
||||||
|
Reference in New Issue
Block a user