summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2011-05-24 23:26:18 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-05-25 21:59:51 +0200
commit09b0018b938bfbbe0d5b5363b8e011aa7bfbf2f2 (patch)
treedf73e66ffd908551b2f020a0c4c5b23a35152153 /tests
parent2624e603d4fc47d1bcf16cc1374628fe0b10f555 (diff)
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)
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/torture_misc.c26
1 files changed, 26 insertions, 0 deletions
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();