diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-12-13 08:54:29 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-12-13 08:54:29 -0500 |
commit | dd6dec2665af9964d8f940c27f3f0815a649424a (patch) | |
tree | b584ee84311bba9a26f3e4c6dbb1f7b52442d433 /src/test | |
parent | 4c877ae87483d6e63c9e0309eb8abc009f9b9b87 (diff) | |
download | tor-dd6dec2665af9964d8f940c27f3f0815a649424a.tar.gz tor-dd6dec2665af9964d8f940c27f3f0815a649424a.zip |
Add a function to add msec to a monotime.
We'll use this for the channel padding logic.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_util.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 7210f16746..1c58ad695d 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -5948,6 +5948,33 @@ test_util_monotonic_time_zero(void *arg) } static void +test_util_monotonic_time_add_msec(void *arg) +{ + (void) arg; + monotime_t t1, t2; + monotime_coarse_t ct1, ct2; + monotime_init(); + + monotime_get(&t1); + monotime_coarse_get(&ct1); + + /* adding zero does nothing */ + monotime_add_msec(&t2, &t1, 0); + monotime_coarse_add_msec(&ct2, &ct1, 0); + tt_i64_op(monotime_diff_msec(&t1, &t2), OP_EQ, 0); + tt_i64_op(monotime_coarse_diff_msec(&ct1, &ct2), OP_EQ, 0); + + /* Add 1337 msec; see if the diff function agree */ + monotime_add_msec(&t2, &t1, 1337); + 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); + + done: + ; +} + +static void test_util_htonll(void *arg) { (void)arg; @@ -6181,6 +6208,7 @@ struct testcase_t util_tests[] = { UTIL_TEST(monotonic_time, 0), UTIL_TEST(monotonic_time_ratchet, TT_FORK), UTIL_TEST(monotonic_time_zero, 0), + UTIL_TEST(monotonic_time_add_msec, 0), UTIL_TEST(htonll, 0), UTIL_TEST(get_unquoted_path, 0), END_OF_TESTCASES |