aboutsummaryrefslogtreecommitdiff
path: root/tests/client
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-05-24 23:25:40 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2011-05-24 23:25:40 +0200
commit4d6b1aa2c7ea67d6909680254b7ae68aa437a6ef (patch)
tree45d8c7c9e37538da93fd31d39b6a441ee17d816c /tests/client
parent79434649d012dbf8d89894a34707b5c648b40921 (diff)
downloadlibssh-4d6b1aa2c7ea67d6909680254b7ae68aa437a6ef.tar.gz
libssh-4d6b1aa2c7ea67d6909680254b7ae68aa437a6ef.tar.xz
libssh-4d6b1aa2c7ea67d6909680254b7ae68aa437a6ef.zip
Added testcase for the timeout connecting problem
Diffstat (limited to 'tests/client')
-rw-r--r--tests/client/torture_connect.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/client/torture_connect.c b/tests/client/torture_connect.c
index 24ee0d2..0e23fcd 100644
--- a/tests/client/torture_connect.c
+++ b/tests/client/torture_connect.c
@@ -23,6 +23,11 @@
#include "torture.h"
#include <libssh/libssh.h>
+#include <sys/time.h>
+
+#define HOST "localhost"
+/* Should work until Apnic decides to assign it :) */
+#define BLACKHOLE "1.1.1.1"
static void setup(void **state) {
int verbosity=torture_libssh_verbosity();
@@ -44,7 +49,7 @@ static void torture_connect_nonblocking(void **state) {
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, HOST);
assert_true(rc == SSH_OK);
ssh_set_blocking(session,0);
@@ -57,12 +62,39 @@ static void torture_connect_nonblocking(void **state) {
}
+static void torture_connect_timeout(void **state) {
+ ssh_session session = *state;
+ struct timeval before, after;
+ int rc;
+ long timeout = 2;
+ time_t sec;
+ suseconds_t usec;
+
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, BLACKHOLE);
+ assert_true(rc == SSH_OK);
+ rc = ssh_options_set(session, SSH_OPTIONS_TIMEOUT, &timeout);
+ assert_true(rc == SSH_OK);
+
+ rc = gettimeofday(&before, NULL);
+ assert_true(rc == 0);
+ rc = ssh_connect(session);
+ assert_true(rc == SSH_ERROR);
+ rc = gettimeofday(&after, NULL);
+ assert_true(rc == 0);
+ sec = after.tv_sec - before.tv_sec;
+ usec = after.tv_usec - before.tv_usec;
+ /* Borrow a second for the missing usecs, but don't bother calculating */
+ if(usec < 0)
+ sec--;
+ assert_in_range(sec,1,3);
+}
+
static void torture_connect_double(void **state) {
ssh_session session = *state;
int rc;
- rc = ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
+ rc = ssh_options_set(session, SSH_OPTIONS_HOST, HOST);
assert_true(rc == SSH_OK);
rc = ssh_connect(session);
assert_true(rc == SSH_OK);
@@ -88,6 +120,7 @@ int torture_run_tests(void) {
unit_test_setup_teardown(torture_connect_nonblocking, setup, teardown),
unit_test_setup_teardown(torture_connect_double, setup, teardown),
unit_test_setup_teardown(torture_connect_failure, setup, teardown),
+ unit_test_setup_teardown(torture_connect_timeout, setup, teardown),
};
ssh_init();