diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-05-24 23:26:18 +0200 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2011-05-24 23:26:18 +0200 |
commit | 59f7647cd97c62ab7a26725e5a166dcb54b27bc6 (patch) | |
tree | 34dad1189e803af0b8d1d3caa83cd220a950bc3f /tests/unittests | |
parent | 4d6b1aa2c7ea67d6909680254b7ae68aa437a6ef (diff) | |
download | libssh-59f7647cd97c62ab7a26725e5a166dcb54b27bc6.tar.gz libssh-59f7647cd97c62ab7a26725e5a166dcb54b27bc6.tar.xz libssh-59f7647cd97c62ab7a26725e5a166dcb54b27bc6.zip |
Introduced ssh_timeout_elapsed functions
Functions to mesure elapsed time before and after a serie of
calls. Introduces a dependancy to clock_gettime() and librt,
hope this doesn't break anything. Porting to gettimeofday() should
not be too hard.
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/torture_misc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index c20f358..f95f866 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -161,6 +161,30 @@ static void torture_path_expand_known_hosts(void **state) { free(tmp); } +static void torture_timeout_elapsed(void **state){ + struct ssh_timestamp ts; + (void) state; + ssh_timestamp_init(&ts); + usleep(50000); + assert_true(ssh_timeout_elapsed(&ts,25)); + assert_false(ssh_timeout_elapsed(&ts,30000)); + assert_false(ssh_timeout_elapsed(&ts,75)); + assert_true(ssh_timeout_elapsed(&ts,0)); + assert_false(ssh_timeout_elapsed(&ts,-1)); +} + +static void torture_timeout_update(void **state){ + struct ssh_timestamp ts; + (void) state; + ssh_timestamp_init(&ts); + usleep(50000); + assert_int_equal(ssh_timeout_update(&ts,25), 0); + assert_in_range(ssh_timeout_update(&ts,30000),29000,29960); + assert_in_range(ssh_timeout_update(&ts,75),1,40); + assert_int_equal(ssh_timeout_update(&ts,0),0); + assert_int_equal(ssh_timeout_update(&ts,-1),-1); +} + int torture_run_tests(void) { int rc; const UnitTest tests[] = { @@ -175,6 +199,8 @@ int torture_run_tests(void) { #endif unit_test_setup_teardown(torture_path_expand_escape, setup, teardown), unit_test_setup_teardown(torture_path_expand_known_hosts, setup, teardown), + unit_test(torture_timeout_elapsed), + unit_test(torture_timeout_update), }; ssh_init(); |