summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMike Perry <mikeperry-git@torproject.org>2018-04-02 07:12:15 +0000
committerMike Perry <mikeperry-git@torproject.org>2018-04-16 21:46:31 +0000
commit0e06a9c3e76620881db95718f60441ce7de0f3c9 (patch)
tree4a6c07b250da82aefe90a18bd5a5f0d5cf0ec8e1 /src/test
parentdfa6808f57e5856edd4e25a957f3f06707264199 (diff)
downloadtor-0e06a9c3e76620881db95718f60441ce7de0f3c9.tar.gz
tor-0e06a9c3e76620881db95718f60441ce7de0f3c9.zip
Helper function to add u32 without overflow.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_util.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 24b43c899b..350273bf4c 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -6050,6 +6050,23 @@ test_util_monotonic_time_add_msec(void *arg)
}
static void
+test_util_nowrap_math(void *arg)
+{
+ (void)arg;
+
+ tt_u64_op(0, OP_EQ, tor_add_u32_nowrap(0, 0));
+ tt_u64_op(1, OP_EQ, tor_add_u32_nowrap(0, 1));
+ tt_u64_op(1, OP_EQ, tor_add_u32_nowrap(1, 0));
+ tt_u64_op(4, OP_EQ, tor_add_u32_nowrap(2, 2));
+ tt_u64_op(UINT32_MAX, OP_EQ, tor_add_u32_nowrap(UINT32_MAX-1, 2));
+ tt_u64_op(UINT32_MAX, OP_EQ, tor_add_u32_nowrap(2, UINT32_MAX-1));
+ tt_u64_op(UINT32_MAX, OP_EQ, tor_add_u32_nowrap(UINT32_MAX, UINT32_MAX));
+
+ done:
+ ;
+}
+
+static void
test_util_htonll(void *arg)
{
(void)arg;
@@ -6243,6 +6260,7 @@ struct testcase_t util_tests[] = {
UTIL_TEST(listdir, 0),
UTIL_TEST(parent_dir, 0),
UTIL_TEST(ftruncate, 0),
+ UTIL_TEST(nowrap_math, 0),
UTIL_TEST(num_cpus, 0),
UTIL_TEST_WIN_ONLY(load_win_lib, 0),
UTIL_TEST_NO_WIN(exit_status, 0),