1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

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.
This commit is contained in:
Aris Adamantiadis
2011-05-24 23:26:18 +02:00
parent 4d6b1aa2c7
commit 59f7647cd9
7 changed files with 162 additions and 16 deletions

View File

@ -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();