diff options
author | Lucas De Marchi <lucas.de.marchi@gmail.com> | 2022-06-03 14:50:46 -0700 |
---|---|---|
committer | Lucas De Marchi <lucas.de.marchi@gmail.com> | 2022-06-26 23:23:46 -0700 |
commit | b253f4c835b0a70d200ceed74ef185dc8f87da9d (patch) | |
tree | 4408dd48eba2ccae148be5cb06278662e73853ff | |
parent | 8ab15eceafd46fcaf2f8874af7d52d0622127655 (diff) | |
download | kmod-b253f4c835b0a70d200ceed74ef185dc8f87da9d.tar.gz kmod-b253f4c835b0a70d200ceed74ef185dc8f87da9d.tar.bz2 kmod-b253f4c835b0a70d200ceed74ef185dc8f87da9d.zip |
testsuite: Add tests for sleep calculation
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
-rw-r--r-- | testsuite/test-util.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/testsuite/test-util.c b/testsuite/test-util.c index 621446b..fb8c9ef 100644 --- a/testsuite/test-util.c +++ b/testsuite/test-util.c @@ -229,4 +229,45 @@ DEFINE_TEST(test_addu64_overflow, ); +static int test_backoff_time(const struct test *t) +{ + unsigned long long delta; + + /* Check exponential increments */ + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 1, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 2, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 4, EXIT_FAILURE); + get_backoff_delta_msec(now_msec(), now_msec() + 10, &delta); + assert_return(delta == 8, EXIT_FAILURE); + + { + unsigned long long t0, tend; + + /* Check tail */ + delta = 4; + tend = now_msec() + 3; + t0 = tend - 10; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 2, EXIT_FAILURE); + tend = now_msec() + 1; + t0 = tend - 9; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 1, EXIT_FAILURE); + tend = now_msec(); + t0 = tend - 10; + get_backoff_delta_msec(t0, tend, &delta); + assert_return(delta == 0, EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} +DEFINE_TEST(test_backoff_time, + .description = "check implementation of get_backoff_delta_msec()", + .need_spawn = false, + ); + + TESTSUITE_MAIN(); |