From 09b0018b938bfbbe0d5b5363b8e011aa7bfbf2f2 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Tue, 24 May 2011 23:26:18 +0200 Subject: 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. (cherry picked from commit 59f7647cd97c62ab7a26725e5a166dcb54b27bc6) --- tests/unittests/torture_misc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index c20f3585..f95f8662 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(); -- cgit