aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHeiko Thiery <heiko.thiery@gmail.com>2020-04-21 09:26:17 +0200
committerJakub Jelen <jjelen@redhat.com>2020-04-24 15:57:38 +0200
commit99e0ad75a6d1d5b6dbaaa57204af1f6d71a5dc72 (patch)
treefc9b4cd3b8b7750b84798c4e4d37f5a5f8343106 /tests
parent154765ae8ca53d94825134f3d454001ee06d4cea (diff)
downloadlibssh-99e0ad75a6d1d5b6dbaaa57204af1f6d71a5dc72.tar.gz
libssh-99e0ad75a6d1d5b6dbaaa57204af1f6d71a5dc72.tar.xz
libssh-99e0ad75a6d1d5b6dbaaa57204af1f6d71a5dc72.zip
tests: add testcases for ssh_channel_poll_timeout()
This adds testcases for the regression introduced in 3bad0607. Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/client/torture_session.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/client/torture_session.c b/tests/client/torture_session.c
index b5ed7a62..41309f17 100644
--- a/tests/client/torture_session.c
+++ b/tests/client/torture_session.c
@@ -118,12 +118,66 @@ static void torture_channel_read_error(void **state) {
ssh_channel_free(channel);
}
+static void torture_channel_poll_timeout_valid(void **state) {
+ struct torture_state *s = *state;
+ ssh_session session = s->ssh.session;
+ ssh_channel channel;
+ int rc;
+
+ channel = ssh_channel_new(session);
+ assert_non_null(channel);
+
+ rc = ssh_channel_open_session(channel);
+ assert_ssh_return_code(session, rc);
+
+ rc = ssh_channel_request_exec(channel, "echo -n ABCD");
+ assert_ssh_return_code(session, rc);
+
+ rc = ssh_channel_poll_timeout(channel, 500, 0);
+ assert_int_equal(rc, strlen("ABCD"));
+}
+
+static void torture_channel_poll_timeout(void **state) {
+ struct torture_state *s = *state;
+ ssh_session session = s->ssh.session;
+ ssh_channel channel;
+ int rc;
+ int fd;
+
+ channel = ssh_channel_new(session);
+ assert_non_null(channel);
+
+ rc = ssh_channel_open_session(channel);
+ assert_ssh_return_code(session, rc);
+
+ fd = ssh_get_fd(session);
+ assert_true(fd > 2);
+
+ rc = ssh_channel_poll_timeout(channel, 500, 0);
+ assert_int_equal(rc, SSH_OK);
+
+ /* send crap and for server to send us a disconnect */
+ rc = write(fd, "AAAA", 4);
+ assert_int_equal(rc, 4);
+
+ rc = ssh_channel_poll_timeout(channel, 500, 0);
+ assert_int_equal(rc, SSH_ERROR);
+
+ ssh_channel_free(channel);
+}
+
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(torture_channel_read_error,
session_setup,
session_teardown),
+ cmocka_unit_test_setup_teardown(torture_channel_poll_timeout_valid,
+ session_setup,
+ session_teardown),
+ cmocka_unit_test_setup_teardown(torture_channel_poll_timeout,
+ session_setup,
+ session_teardown),
};
ssh_init();