diff options
author | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2020-09-24 13:26:09 +0200 |
---|---|---|
committer | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2021-01-11 20:46:02 +0100 |
commit | cdac4fca5fd0ab1b92fcfc0ab93d0797f263c736 (patch) | |
tree | 685a6843f696c7055112e6c70717395a6200eb40 /tests | |
parent | a4b8045fb85e8e674ff86f92d87c3418210a3c4c (diff) | |
download | libssh-cdac4fca5fd0ab1b92fcfc0ab93d0797f263c736.tar.gz libssh-cdac4fca5fd0ab1b92fcfc0ab93d0797f263c736.tar.xz libssh-cdac4fca5fd0ab1b92fcfc0ab93d0797f263c736.zip |
torture_session: Test delayed close
The test for delayed close asks for the execution of a command that
generates big output (larger than the default window) to make data to
remain in buffers while the close message arrives, triggering the
delayed channel closure.
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/client/torture_session.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/client/torture_session.c b/tests/client/torture_session.c index d83ec9b6..2fa2ae33 100644 --- a/tests/client/torture_session.c +++ b/tests/client/torture_session.c @@ -218,6 +218,46 @@ static void torture_max_sessions(void **state) #undef MAX_CHANNELS } +static void torture_channel_delayed_close(void **state) +{ + struct torture_state *s = *state; + ssh_session session = s->ssh.session; + ssh_channel channel; + + char request[256]; + char buff[256] = {0}; + + int rc; + int fd; + + snprintf(request, 256, + "dd if=/dev/urandom of=/tmp/file bs=64000 count=2; hexdump -C /tmp/file"); + + 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); + + /* Make the request, read parts with close */ + rc = ssh_channel_request_exec(channel, request); + assert_ssh_return_code(session, rc); + + do { + rc = ssh_channel_read(channel, buff, 256, 0); + } while(rc > 0); + assert_ssh_return_code(session, rc); + + rc = ssh_channel_poll_timeout(channel, 500, 0); + assert_int_equal(rc, SSH_EOF); + + ssh_channel_free(channel); + +} + int torture_run_tests(void) { int rc; struct CMUnitTest tests[] = { @@ -233,6 +273,9 @@ int torture_run_tests(void) { cmocka_unit_test_setup_teardown(torture_max_sessions, session_setup, session_teardown), + cmocka_unit_test_setup_teardown(torture_channel_delayed_close, + session_setup, + session_teardown), }; ssh_init(); |