diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-02-24 07:45:20 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-02-24 07:45:20 -0500 |
commit | caa392a73ad6c8e215a4686955c9de98eeb07661 (patch) | |
tree | 50de29ea7cbbf27ae656a4b7a865f76c1a66ae63 /src/test/test_util.c | |
parent | 7ba7f9c0de9d1b2435a01961379b3d85c4fc2ab5 (diff) | |
parent | 93cb8072becb4213525d08a87fdf7284e6257168 (diff) | |
download | tor-caa392a73ad6c8e215a4686955c9de98eeb07661.tar.gz tor-caa392a73ad6c8e215a4686955c9de98eeb07661.zip |
Merge remote-tracking branch 'tor-github/pr/1685/head'
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 0d86a5ab5d..b1e4335652 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4572,6 +4572,35 @@ test_util_di_ops(void *arg) } static void +test_util_memcpy_iftrue_timei(void *arg) +{ + (void)arg; + char buf1[25]; + char buf2[25]; + char buf3[25]; + + for (int i = 0; i < 100; ++i) { + crypto_rand(buf1, sizeof(buf1)); + crypto_rand(buf2, sizeof(buf2)); + memcpy(buf3, buf1, sizeof(buf1)); + + /* We just copied buf1 into buf3. Now we're going to copy buf2 into buf2, + iff our coin flip comes up heads. */ + bool coinflip = crypto_rand_int(2) == 0; + + memcpy_if_true_timei(coinflip, buf3, buf2, sizeof(buf3)); + + if (coinflip) { + tt_mem_op(buf3, OP_EQ, buf2, sizeof(buf2)); + } else { + tt_mem_op(buf3, OP_EQ, buf1, sizeof(buf1)); + } + } + done: + ; +} + +static void test_util_di_map(void *arg) { (void)arg; @@ -6386,6 +6415,7 @@ struct testcase_t util_tests[] = { UTIL_LEGACY(path_is_relative), UTIL_LEGACY(strtok), UTIL_LEGACY(di_ops), + UTIL_TEST(memcpy_iftrue_timei, 0), UTIL_TEST(di_map, 0), UTIL_TEST(round_to_next_multiple_of, 0), UTIL_TEST(laplace, 0), |