aboutsummaryrefslogtreecommitdiffstats
path: root/tests/timer/timer_misc_test.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-05-31 18:13:40 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-05-31 18:13:40 +0200
commita928399a67d0311fab9ec7a305c1790fc2470dc7 (patch)
treee426a9a524356eecbd4d54ccc68ddc092c82c232 /tests/timer/timer_misc_test.c
parentfe2be43bce7b56ec0ee4ece18c4ba0ed7cc4ad94 (diff)
move to timespec WIPneels/monotonic_timers
Diffstat (limited to 'tests/timer/timer_misc_test.c')
-rw-r--r--tests/timer/timer_misc_test.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/tests/timer/timer_misc_test.c b/tests/timer/timer_misc_test.c
index 9e604b5a..e31423bc 100644
--- a/tests/timer/timer_misc_test.c
+++ b/tests/timer/timer_misc_test.c
@@ -25,42 +25,42 @@
#include <osmocom/core/timer.h>
struct timer_remaining_testcase {
- struct timeval now;
- struct timeval timeout;
+ struct timespec now;
+ struct timespec timeout;
int expect_rc;
- struct timeval expect_diff;
+ struct timespec expect_diff;
};
struct timer_remaining_testcase timer_remaining_data[] = {
{
- .now = { .tv_sec = 1000000, .tv_usec = 0 },
- .timeout = { .tv_sec = 1000123, .tv_usec = 1 },
+ .now = { .tv_sec = 1000000, .tv_nsec = 0 },
+ .timeout = { .tv_sec = 1000123, .tv_nsec = 1 },
.expect_rc = 0,
- .expect_diff = { .tv_sec = 123, .tv_usec = 1 },
+ .expect_diff = { .tv_sec = 123, .tv_nsec = 1 },
},
{
- .now = { .tv_sec = 1000000, .tv_usec = 0 },
- .timeout = { .tv_sec = 1000000, .tv_usec = 1 },
+ .now = { .tv_sec = 1000000, .tv_nsec = 0 },
+ .timeout = { .tv_sec = 1000000, .tv_nsec = 1 },
.expect_rc = 0,
- .expect_diff = { .tv_sec = 0, .tv_usec = 1 },
+ .expect_diff = { .tv_sec = 0, .tv_nsec = 1 },
},
{
- .now = { .tv_sec = 1000000, .tv_usec = 1 },
- .timeout = { .tv_sec = 1000000, .tv_usec = 0 },
+ .now = { .tv_sec = 1000000, .tv_nsec = 1 },
+ .timeout = { .tv_sec = 1000000, .tv_nsec = 0 },
.expect_rc = -1,
- .expect_diff = { .tv_sec = 0 - 1, .tv_usec = 999999 },
+ .expect_diff = { .tv_sec = 0 - 1, .tv_nsec = 999999999 },
},
{
- .now = { .tv_sec = 1000001, .tv_usec = 1 },
- .timeout = { .tv_sec = 1000000, .tv_usec = 0 },
+ .now = { .tv_sec = 1000001, .tv_nsec = 1 },
+ .timeout = { .tv_sec = 1000000, .tv_nsec = 0 },
.expect_rc = -1,
- .expect_diff = { .tv_sec = -1 - 1, .tv_usec = 999999 },
+ .expect_diff = { .tv_sec = -1 - 1, .tv_nsec = 999999999 },
},
{
- .now = { .tv_sec = 1000123, .tv_usec = 1 },
- .timeout = { .tv_sec = 1000000, .tv_usec = 0 },
+ .now = { .tv_sec = 1000123, .tv_nsec = 1 },
+ .timeout = { .tv_sec = 1000000, .tv_nsec = 0 },
.expect_rc = -1,
- .expect_diff = { .tv_sec = -123 - 1, .tv_usec = 999999 },
+ .expect_diff = { .tv_sec = -123 - 1, .tv_nsec = 999999999 },
},
};
@@ -68,24 +68,28 @@ void test_timer_remaining()
{
int i;
bool all_ok = true;
+ struct timespec *now;
printf("\n--- start: %s\n", __func__);
+ osmo_clock_override_enable(CLOCK_MONOTONIC, true);
+ now = osmo_clock_override_gettimespec(CLOCK_MONOTONIC);
for (i = 0; i < ARRAY_SIZE(timer_remaining_data); i++) {
struct timer_remaining_testcase *tc = &timer_remaining_data[i];
struct osmo_timer_list t = {
- .timeout = tc->timeout,
+ .timeout_at = tc->timeout,
.active = 1,
};
- struct timeval diff;
+ struct timespec diff;
int rc;
bool ok = true;
- rc = osmo_timer_remaining(&t, &tc->now, &diff);
+ *now = tc->now;
+ rc = osmo_timer_remaining2(&t, &diff);
printf("timeout:%ld.%06ld - now:%ld.%06ld = diff:%ld.%06ld; rc=%d\n",
- t.timeout.tv_sec, t.timeout.tv_usec,
- tc->now.tv_sec, tc->now.tv_usec,
- diff.tv_sec, diff.tv_usec,
+ t.timeout_at.tv_sec, t.timeout_at.tv_nsec,
+ tc->now.tv_sec, tc->now.tv_nsec,
+ diff.tv_sec, diff.tv_nsec,
rc);
if (rc != tc->expect_rc) {
@@ -93,9 +97,9 @@ void test_timer_remaining()
ok = false;
}
- if (diff.tv_sec != tc->expect_diff.tv_sec || diff.tv_usec != tc->expect_diff.tv_usec) {
+ if (diff.tv_sec != tc->expect_diff.tv_sec || diff.tv_nsec != tc->expect_diff.tv_nsec) {
printf(" ERROR: expected diff = %ld.%06ld\n",
- tc->expect_diff.tv_sec, tc->expect_diff.tv_usec);
+ tc->expect_diff.tv_sec, tc->expect_diff.tv_nsec);
ok = false;
}