From 8e2f7e87f4d854e697c40545326a16e50614dd5c Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Thu, 22 Sep 2016 03:58:13 +0200 Subject: add osmo_gettimeofday as a shim around gettimeofday This allows feeding a custom time for unit tests by overriding osmo_gettimeofday. Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089 --- src/gb/gprs_bssgp.c | 8 ++++---- src/gb/gprs_ns.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/gb') diff --git a/src/gb/gprs_bssgp.c b/src/gb/gprs_bssgp.c index 3ad2f297..1ee942f2 100644 --- a/src/gb/gprs_bssgp.c +++ b/src/gb/gprs_bssgp.c @@ -603,7 +603,7 @@ static void fc_timer_cb(void *data) fc->queue_depth--; /* record the time we transmitted this PDU */ - gettimeofday(&time_now, NULL); + osmo_gettimeofday(&time_now, NULL); fc->time_last_pdu = time_now; /* call the output callback for this FC instance */ @@ -688,7 +688,7 @@ static int bssgp_fc_needs_queueing(struct bssgp_flow_control *fc, uint32_t pdu_l /* compute number of centi-seconds that have elapsed since transmitting * the last PDU (Tc - Tp) */ - gettimeofday(&time_now, NULL); + osmo_gettimeofday(&time_now, NULL); timersub(&time_now, &fc->time_last_pdu, &time_diff); csecs_elapsed = time_diff.tv_sec*100 + time_diff.tv_usec/10000; @@ -747,7 +747,7 @@ int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, return fc_enqueue(fc, msg, llc_pdu_len, priv); } else { /* record the time we transmitted this PDU */ - gettimeofday(&time_now, NULL); + osmo_gettimeofday(&time_now, NULL); fc->time_last_pdu = time_now; return fc->out_cb(priv, msg, llc_pdu_len, NULL); } @@ -766,7 +766,7 @@ void bssgp_fc_init(struct bssgp_flow_control *fc, fc->bucket_leak_rate = bucket_leak_rate; fc->max_queue_depth = max_queue_depth; INIT_LLIST_HEAD(&fc->queue); - gettimeofday(&fc->time_last_pdu, NULL); + osmo_gettimeofday(&fc->time_last_pdu, NULL); } /* Initialize the Flow Control parameters for a new MS according to diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index 6879c708..18845d4b 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -556,7 +556,7 @@ static void nsvc_start_timer(struct gprs_nsvc *nsvc, enum nsvc_timer_mode mode) if (osmo_timer_pending(&nsvc->timer)) osmo_timer_del(&nsvc->timer); - gettimeofday(&nsvc->timer_started, NULL); + osmo_gettimeofday(&nsvc->timer_started, NULL); nsvc->timer_mode = mode; osmo_timer_schedule(&nsvc->timer, seconds, 0); } @@ -564,7 +564,7 @@ static void nsvc_start_timer(struct gprs_nsvc *nsvc, enum nsvc_timer_mode mode) static int nsvc_timer_elapsed_ms(struct gprs_nsvc *nsvc) { struct timeval now, elapsed; - gettimeofday(&now, NULL); + osmo_gettimeofday(&now, NULL); timersub(&now, &nsvc->timer_started, &elapsed); return 1000 * elapsed.tv_sec + elapsed.tv_usec / 1000; -- cgit v1.2.3