Commit 28e163de authored by Christian Kandeler's avatar Christian Kandeler

SSH: Fix exit code of tests.

The test apps now return != 0 in case of an error.

Change-Id: I2380bc4b8e0c85e68d79f90ccc39ad9419851b04
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@theqtcompany.com>
parent 1ef9137c
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include <QPair> #include <QPair>
#include <QTimer> #include <QTimer>
#include <cstdlib>
using namespace QSsh; using namespace QSsh;
class Test : public QObject { class Test : public QObject {
...@@ -117,27 +119,27 @@ private slots: ...@@ -117,27 +119,27 @@ private slots:
void handleConnected() void handleConnected()
{ {
qDebug("Error: Received unexpected connected() signal."); qDebug("Error: Received unexpected connected() signal.");
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
void handleDisconnected() void handleDisconnected()
{ {
qDebug("Error: Received unexpected disconnected() signal."); qDebug("Error: Received unexpected disconnected() signal.");
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
void handleDataAvailable(const QString &msg) void handleDataAvailable(const QString &msg)
{ {
qDebug("Error: Received unexpected dataAvailable() signal. " qDebug("Error: Received unexpected dataAvailable() signal. "
"Message was: '%s'.", qPrintable(msg)); "Message was: '%s'.", qPrintable(msg));
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
void handleError(QSsh::SshError error) void handleError(QSsh::SshError error)
{ {
if (m_testSet.isEmpty()) { if (m_testSet.isEmpty()) {
qDebug("Error: Received error %d, but no test was running.", error); qDebug("Error: Received error %d, but no test was running.", error);
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
const TestItem testItem = m_testSet.takeFirst(); const TestItem testItem = m_testSet.takeFirst();
...@@ -151,7 +153,7 @@ private slots: ...@@ -151,7 +153,7 @@ private slots:
} }
} else { } else {
qDebug("Received unexpected error %d.", error); qDebug("Received unexpected error %d.", error);
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
} }
...@@ -159,7 +161,7 @@ private slots: ...@@ -159,7 +161,7 @@ private slots:
{ {
if (m_testSet.isEmpty()) { if (m_testSet.isEmpty()) {
qDebug("Error: timeout, but no test was running."); qDebug("Error: timeout, but no test was running.");
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
const TestItem testItem = m_testSet.takeFirst(); const TestItem testItem = m_testSet.takeFirst();
qDebug("Error: The following test timed out: %s", testItem.description); qDebug("Error: The following test timed out: %s", testItem.description);
......
...@@ -82,14 +82,14 @@ void RemoteProcessTest::handleConnectionError() ...@@ -82,14 +82,14 @@ void RemoteProcessTest::handleConnectionError()
? m_sshConnection->errorString() : m_remoteRunner->lastConnectionErrorString(); ? m_sshConnection->errorString() : m_remoteRunner->lastConnectionErrorString();
std::cerr << "Error: Connection failure (" << qPrintable(error) << ")." << std::endl; std::cerr << "Error: Connection failure (" << qPrintable(error) << ")." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
void RemoteProcessTest::handleProcessStarted() void RemoteProcessTest::handleProcessStarted()
{ {
if (m_started) { if (m_started) {
std::cerr << "Error: Received started() signal again." << std::endl; std::cerr << "Error: Received started() signal again." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} else { } else {
m_started = true; m_started = true;
if (m_state == TestingCrash) { if (m_state == TestingCrash) {
...@@ -109,11 +109,11 @@ void RemoteProcessTest::handleProcessStdout() ...@@ -109,11 +109,11 @@ void RemoteProcessTest::handleProcessStdout()
if (!m_started) { if (!m_started) {
std::cerr << "Error: Remote output from non-started process." std::cerr << "Error: Remote output from non-started process."
<< std::endl; << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} else if (m_state != TestingSuccess && m_state != TestingTerminal) { } else if (m_state != TestingSuccess && m_state != TestingTerminal) {
std::cerr << "Error: Got remote standard output in state " << m_state std::cerr << "Error: Got remote standard output in state " << m_state
<< "." << std::endl; << "." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} else { } else {
m_remoteStdout += m_remoteRunner->readAllStandardOutput(); m_remoteStdout += m_remoteRunner->readAllStandardOutput();
} }
...@@ -124,11 +124,11 @@ void RemoteProcessTest::handleProcessStderr() ...@@ -124,11 +124,11 @@ void RemoteProcessTest::handleProcessStderr()
if (!m_started) { if (!m_started) {
std::cerr << "Error: Remote error output from non-started process." std::cerr << "Error: Remote error output from non-started process."
<< std::endl; << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} else if (m_state == TestingSuccess) { } else if (m_state == TestingSuccess) {
std::cerr << "Error: Unexpected remote standard error output." std::cerr << "Error: Unexpected remote standard error output."
<< std::endl; << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} else { } else {
m_remoteStderr += m_remoteRunner->readAllStandardError(); m_remoteStderr += m_remoteRunner->readAllStandardError();
} }
...@@ -140,7 +140,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -140,7 +140,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
case SshRemoteProcess::NormalExit: case SshRemoteProcess::NormalExit:
if (!m_started) { if (!m_started) {
std::cerr << "Error: Process exited without starting." << std::endl; std::cerr << "Error: Process exited without starting." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
switch (m_state) { switch (m_state) {
...@@ -149,13 +149,13 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -149,13 +149,13 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
if (exitCode != 0) { if (exitCode != 0) {
std::cerr << "Error: exit code is " << exitCode std::cerr << "Error: exit code is " << exitCode
<< ", expected zero." << std::endl; << ", expected zero." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
if (m_remoteStdout.isEmpty()) { if (m_remoteStdout.isEmpty()) {
std::cerr << "Error: Command did not produce output." std::cerr << "Error: Command did not produce output."
<< std::endl; << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
...@@ -171,12 +171,12 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -171,12 +171,12 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
if (exitCode == 0) { if (exitCode == 0) {
std::cerr << "Error: exit code is zero, expected non-zero." std::cerr << "Error: exit code is zero, expected non-zero."
<< std::endl; << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
if (m_remoteStderr.isEmpty()) { if (m_remoteStderr.isEmpty()) {
std::cerr << "Error: Command did not produce error output." << std::flush; std::cerr << "Error: Command did not produce error output." << std::flush;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
...@@ -191,7 +191,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -191,7 +191,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
if (m_remoteRunner->processExitCode() == 0) { 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->exit(EXIT_FAILURE);
} else { } else {
// Some shells (e.g. mksh) don't report "killed", but just a non-zero exit code. // Some shells (e.g. mksh) don't report "killed", but just a non-zero exit code.
handleSuccessfulCrashTest(); handleSuccessfulCrashTest();
...@@ -202,13 +202,13 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -202,13 +202,13 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
if (exitCode != 0) { if (exitCode != 0) {
std::cerr << "Error: exit code is " << exitCode std::cerr << "Error: exit code is " << exitCode
<< ", expected zero." << std::endl; << ", expected zero." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
if (m_remoteStdout.isEmpty()) { if (m_remoteStdout.isEmpty()) {
std::cerr << "Error: Command did not produce output." std::cerr << "Error: Command did not produce output."
<< std::endl; << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
std::cout << "Ok.\nTesting I/O device functionality... " << std::flush; std::cout << "Ok.\nTesting I/O device functionality... " << std::flush;
...@@ -256,7 +256,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -256,7 +256,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
} else { } else {
std::cerr << "Error: Process failed to start." << std::endl; std::cerr << "Error: Process failed to start." << std::endl;
} }
qApp->quit(); qApp->exit(EXIT_FAILURE);
break; break;
case SshRemoteProcess::CrashExit: case SshRemoteProcess::CrashExit:
switch (m_state) { switch (m_state) {
...@@ -268,7 +268,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -268,7 +268,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
break; break;
default: default:
std::cerr << "Error: Unexpected crash." << std::endl; std::cerr << "Error: Unexpected crash." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
return; return;
} }
} }
...@@ -277,7 +277,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus) ...@@ -277,7 +277,7 @@ void RemoteProcessTest::handleProcessClosed(int exitStatus)
void RemoteProcessTest::handleTimeout() void RemoteProcessTest::handleTimeout()
{ {
std::cerr << "Error: Timeout waiting for progress." << std::endl; std::cerr << "Error: Timeout waiting for progress." << std::endl;
qApp->quit(); qApp->exit(EXIT_FAILURE);
} }
void RemoteProcessTest::handleConnected() void RemoteProcessTest::handleConnected()
...@@ -305,7 +305,7 @@ void RemoteProcessTest::handleReadyRead() ...@@ -305,7 +305,7 @@ void RemoteProcessTest::handleReadyRead()
if (data != testString()) { if (data != testString()) {
std::cerr << "Testing of QIODevice functionality failed: Expected '" std::cerr << "Testing of QIODevice functionality failed: Expected '"
<< qPrintable(testString()) << "', got '" << qPrintable(data) << "'." << std::endl; << qPrintable(testString()) << "', got '" << qPrintable(data) << "'." << std::endl;
qApp->exit(1); qApp->exit(EXIT_FAILURE);
} }
SshRemoteProcessRunner * const killer = new SshRemoteProcessRunner(this); SshRemoteProcessRunner * const killer = new SshRemoteProcessRunner(this);
killer->run("pkill -9 cat", m_sshParams); killer->run("pkill -9 cat", m_sshParams);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment