diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-07-08 14:38:02 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-07-19 11:40:46 +0200 |
commit | 6a2002fc091506f576934bbf50e7b8644b43bf4c (patch) | |
tree | f73f402d2f081b5ba11682e4239d659590943b65 /src/test/test-timers.c | |
parent | dc6f5d1dc1ccc86f32b39b939a5f83c35865d666 (diff) | |
download | tor-6a2002fc091506f576934bbf50e7b8644b43bf4c.tar.gz tor-6a2002fc091506f576934bbf50e7b8644b43bf4c.zip |
convert timers.c to use real monotonic time.
Diffstat (limited to 'src/test/test-timers.c')
-rw-r--r-- | src/test/test-timers.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/test/test-timers.c b/src/test/test-timers.c index 1189fd8792..b5fcade7f8 100644 --- a/src/test/test-timers.c +++ b/src/test/test-timers.c @@ -28,15 +28,26 @@ static tor_timer_t *timers[N_TIMERS] = {NULL}; static int n_active_timers = 0; static int n_fired = 0; +static monotime_t started_at; +static int64_t delay_usec[N_TIMERS]; +static int64_t diffs_mono_usec[N_TIMERS]; + static void -timer_cb(tor_timer_t *t, void *arg, const struct timeval *now) +timer_cb(tor_timer_t *t, void *arg, const monotime_t *now_mono) { + struct timeval now; + + tor_gettimeofday(&now); tor_timer_t **t_ptr = arg; tor_assert(*t_ptr == t); int idx = (int) (t_ptr - timers); ++fired[idx]; - timersub(now, &fire_at[idx], &difference[idx]); + timersub(&now, &fire_at[idx], &difference[idx]); + diffs_mono_usec[idx] = + monotime_diff_usec(&started_at, now_mono) - + delay_usec[idx]; ++n_fired; + // printf("%d / %d\n",n_fired, N_TIMERS); if (n_fired == n_active_timers) { event_base_loopbreak(tor_libevent_get_base()); @@ -57,10 +68,12 @@ main(int argc, char **argv) int ret; struct timeval now; tor_gettimeofday(&now); + monotime_get(&started_at); for (i = 0; i < N_TIMERS; ++i) { struct timeval delay; delay.tv_sec = crypto_rand_int_range(0,MAX_DURATION); delay.tv_usec = crypto_rand_int_range(0,1000000); + delay_usec[i] = delay.tv_sec * 1000000 + delay.tv_usec; timeradd(&now, &delay, &fire_at[i]); timers[i] = timer_new(timer_cb, &timers[i]); timer_schedule(timers[i], &delay); @@ -88,7 +101,8 @@ main(int argc, char **argv) continue; } tor_assert(fired[i] == 1); - int64_t diff = difference[i].tv_usec + difference[i].tv_sec * 1000000; + //int64_t diff = difference[i].tv_usec + difference[i].tv_sec * 1000000; + int64_t diff = diffs_mono_usec[i]; total_difference += diff; total_square_difference += diff*diff; } |