Use test_timeval_diff_eq more consistently

This commit is contained in:
Nick Mathewson 2012-01-24 14:59:37 -05:00
parent 67a1763bc4
commit b77b43fcdf
2 changed files with 6 additions and 17 deletions

View File

@ -563,7 +563,7 @@ end:
static void static void
test_simpletimeout(void) test_simpletimeout(void)
{ {
struct timeval tv, elapsed; struct timeval tv;
struct event ev; struct event ev;
setup_test("Simple timeout: "); setup_test("Simple timeout: ");
@ -576,10 +576,7 @@ test_simpletimeout(void)
evutil_gettimeofday(&tset, NULL); evutil_gettimeofday(&tset, NULL);
event_dispatch(); event_dispatch();
evutil_timersub(&tcalled, &tset, &elapsed); test_timeval_diff_eq(&tset, &tcalled, 200);
tt_int_op(0, ==, elapsed.tv_sec);
tt_int_op(elapsed.tv_usec, >, 150000);
tt_int_op(elapsed.tv_usec, <, 300000);
test_ok = 1; test_ok = 1;
end: end:
@ -750,16 +747,11 @@ test_common_timeout(void *ptr)
for (i=0; i<10; ++i) { for (i=0; i<10; ++i) {
struct timeval tmp; struct timeval tmp;
int ms_elapsed;
tt_int_op(info[i].count, ==, 4); tt_int_op(info[i].count, ==, 4);
evutil_timersub(&info[i].called_at, &start, &tmp);
ms_elapsed = tmp.tv_usec/1000 + tmp.tv_sec*1000;
if (i % 2) { if (i % 2) {
tt_int_op(ms_elapsed, >, 300); test_timeval_diff_eq(&start, &info[i].called_at, 400);
tt_int_op(ms_elapsed, <, 500);
} else { } else {
tt_int_op(ms_elapsed, >, 700); test_timeval_diff_eq(&start, &info[i].called_at, 800);
tt_int_op(ms_elapsed, <, 900);
} }
} }
@ -2108,10 +2100,8 @@ test_event_pending(void *ptr)
tt_assert( event_pending(t, EV_TIMEOUT, &tv2)); tt_assert( event_pending(t, EV_TIMEOUT, &tv2));
tt_assert(evutil_timercmp(&tv2, &now, >)); tt_assert(evutil_timercmp(&tv2, &now, >));
evutil_timeradd(&now, &tv, &tv);
evutil_timersub(&tv2, &tv, &diff); test_timeval_diff_eq(&now, &tv2, 500);
tt_int_op(diff.tv_sec, ==, 0);
tt_int_op(labs(diff.tv_usec), <, 1000);
end: end:
if (r) { if (r) {

View File

@ -85,7 +85,6 @@ timeval_msec_diff(const struct timeval *start, const struct timeval *end)
ms *= 1000; ms *= 1000;
ms += ((end->tv_usec - start->tv_usec)+500) / 1000; ms += ((end->tv_usec - start->tv_usec)+500) / 1000;
return ms; return ms;
} }
/* ============================================================ */ /* ============================================================ */