summaryrefslogtreecommitdiff
path: root/src/test/test_util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-04-26 11:17:48 -0400
committerNick Mathewson <nickm@torproject.org>2018-04-26 12:01:48 -0400
commit9abf541f7f70068b6f7567481739ca6374f1fd57 (patch)
tree2d3feeaa192761116fb7eee48d1b8cde46b86a49 /src/test/test_util.c
parent7cbc44eeb19831bc467f8e1b87062ed1c87934d5 (diff)
downloadtor-9abf541f7f70068b6f7567481739ca6374f1fd57.tar.gz
tor-9abf541f7f70068b6f7567481739ca6374f1fd57.zip
Add a function to compute millisecond time difference quickly.
Our main function, though accurate on all platforms, can be very slow on 32-bit hosts. This one is faster on all 32-bit hosts, and accurate everywhere except apple, where it will typically be off by 1%. But since 32-bit apple is a relic anyway, I think we should be fine.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r--src/test/test_util.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 350273bf4c..9c028fd47d 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -6035,6 +6035,9 @@ test_util_monotonic_time_add_msec(void *arg)
monotime_coarse_add_msec(&ct2, &ct1, 1337);
tt_i64_op(monotime_diff_msec(&t1, &t2), OP_EQ, 1337);
tt_i64_op(monotime_coarse_diff_msec(&ct1, &ct2), OP_EQ, 1337);
+ // The 32-bit variant must be within 1% of the regular one.
+ tt_int_op(monotime_coarse_diff_msec32_(&ct1, &ct2), OP_GT, 1323);
+ tt_int_op(monotime_coarse_diff_msec32_(&ct1, &ct2), OP_LT, 1350);
/* Add 1337 msec twice more; make sure that any second rollover issues
* worked. */
@@ -6044,6 +6047,8 @@ test_util_monotonic_time_add_msec(void *arg)
monotime_coarse_add_msec(&ct2, &ct2, 1337);
tt_i64_op(monotime_diff_msec(&t1, &t2), OP_EQ, 1337*3);
tt_i64_op(monotime_coarse_diff_msec(&ct1, &ct2), OP_EQ, 1337*3);
+ tt_int_op(monotime_coarse_diff_msec32_(&ct1, &ct2), OP_GT, 3970);
+ tt_int_op(monotime_coarse_diff_msec32_(&ct1, &ct2), OP_LT, 4051);
done:
;