aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-10-31 12:44:48 +0100
committerAndreas Schneider <asn@cryptomilk.org>2013-10-31 12:48:55 +0100
commit24ebbb8b398c61e68fd17f689b30aa5fb890e0cd (patch)
tree934898128716c4bb1a1e43abf0eebcae8528cd66
parent447ee309b03ce2885deeb4b5d88083b359b21890 (diff)
downloadlibssh-24ebbb8b398c61e68fd17f689b30aa5fb890e0cd.tar.gz
libssh-24ebbb8b398c61e68fd17f689b30aa5fb890e0cd.tar.xz
libssh-24ebbb8b398c61e68fd17f689b30aa5fb890e0cd.zip
tests: Add a test for ssh_channel().
-rw-r--r--tests/unittests/CMakeLists.txt2
-rw-r--r--tests/unittests/torture_channel.c48
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt
index d8a6125f..38203991 100644
--- a/tests/unittests/CMakeLists.txt
+++ b/tests/unittests/CMakeLists.txt
@@ -13,4 +13,6 @@ if (UNIX AND NOT WIN32)
add_cmocka_test(torture_pki torture_pki.c ${TORTURE_LIBRARY})
# requires pthread
add_cmocka_test(torture_rand torture_rand.c ${TORTURE_LIBRARY})
+ # requires /dev/null
+ add_cmocka_test(torture_channel torture_channel.c ${TORTURE_LIBRARY})
endif (UNIX AND NOT WIN32)
diff --git a/tests/unittests/torture_channel.c b/tests/unittests/torture_channel.c
new file mode 100644
index 00000000..5bf34fd9
--- /dev/null
+++ b/tests/unittests/torture_channel.c
@@ -0,0 +1,48 @@
+#define LIBSSH_STATIC
+#include <libssh/priv.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "torture.h"
+#include "channels.c"
+
+static void torture_channel_select(void **state)
+{
+ fd_set readfds;
+ int fd;
+ int rc;
+ int i;
+
+ (void)state; /* unused */
+
+ fd = open("/dev/null", 0);
+ assert_true(fd > 2);
+
+ FD_SET(fd, &readfds);
+
+ for (i = 0; i < 10; i++) {
+ ssh_channel cin[1] = { NULL, };
+ ssh_channel cout[1] = { NULL, };
+ struct timeval tv = { .tv_sec = 0, .tv_usec = 1000 };
+
+ rc = ssh_select(cin, cout, fd + 1, &readfds, &tv);
+ assert_int_equal(rc, SSH_OK);
+ }
+
+ close(fd);
+}
+
+int torture_run_tests(void) {
+ int rc;
+ const UnitTest tests[] = {
+ unit_test(torture_channel_select),
+ };
+
+ ssh_init();
+ rc = run_tests(tests);
+ ssh_finalize();
+
+ return rc;
+}