aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/gb/bssgp_fc_test.c25
-rw-r--r--tests/timer/timer_misc_test.c56
2 files changed, 44 insertions, 37 deletions
diff --git a/tests/gb/bssgp_fc_test.c b/tests/gb/bssgp_fc_test.c
index cc387771..1890d1c3 100644
--- a/tests/gb/bssgp_fc_test.c
+++ b/tests/gb/bssgp_fc_test.c
@@ -13,21 +13,22 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/talloc.h>
+#include <osmocom/core/timer_compat.h>
#include <osmocom/gprs/gprs_bssgp.h>
static unsigned long in_ctr = 1;
-static struct timeval tv_start;
+static struct timespec ts_start;
void *ctx = NULL;
int get_centisec_diff(void)
{
- struct timeval tv;
- struct timeval now;
- osmo_gettimeofday(&now, NULL);
+ struct timespec ts;
+ struct timespec now;
+ osmo_clock_gettime(CLOCK_MONOTONIC, &now);
- timersub(&now, &tv_start, &tv);
+ timespecsub(&now, &ts_start, &ts);
- return tv.tv_sec * 100 + tv.tv_usec/10000;
+ return ts.tv_sec * 100 + ts.tv_nsec/10000000;
}
static int fc_out_cb(struct bssgp_flow_control *fc, struct msgb *msg,
@@ -74,17 +75,19 @@ static void test_fc(uint32_t bucket_size_max, uint32_t bucket_leak_rate,
{
struct bssgp_flow_control *fc = talloc_zero(ctx, struct bssgp_flow_control);
int i;
+ struct timespec *now;
+ osmo_clock_override_enable(CLOCK_MONOTONIC, true);
+ now = osmo_clock_override_gettimespec(CLOCK_MONOTONIC);
- osmo_gettimeofday_override_time = (struct timeval){
+ *now = (struct timespec){
.tv_sec = 1486385000,
- .tv_usec = 423423,
+ .tv_nsec = 423423423,
};
- osmo_gettimeofday_override = true;
bssgp_fc_init(fc, bucket_size_max, bucket_leak_rate, max_queue_depth,
fc_out_cb);
- osmo_gettimeofday(&tv_start, NULL);
+ osmo_clock_gettime(CLOCK_MONOTONIC, &ts_start);
/* Fill the queue with PDUs, possibly beyond the queue being full. If it is full, additional PDUs
* are discarded. */
@@ -96,7 +99,7 @@ static void test_fc(uint32_t bucket_size_max, uint32_t bucket_leak_rate,
}
while (1) {
- osmo_gettimeofday_override_add(0, 100000);
+ osmo_clock_override_add(CLOCK_MONOTONIC, 0, 100000000L);
osmo_timers_check();
osmo_timers_prepare();
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;
}