diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-05-24 17:12:57 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-05-24 17:12:57 +0000 |
commit | d3d86b17a761011f62dc2e06c04c0af8f1a75ef6 (patch) | |
tree | efb329c2d77ef6f39c02db8db62bfa18ad5f4d6d /src/or | |
parent | d0a5c4f9848f44c46f001428bd3078673033ef19 (diff) | |
download | tor-d3d86b17a761011f62dc2e06c04c0af8f1a75ef6.tar.gz tor-d3d86b17a761011f62dc2e06c04c0af8f1a75ef6.zip |
r12916@catbus: nickm | 2007-05-24 12:43:45 -0400
Add math functions to round values to the nearest power of 2. Make mempools more careful about making sure that the size of their chunks is a little less than a power of 2, not a little more.
svn:r10304
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/test.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c index ca6ffa0db7..4307b1007e 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -946,6 +946,26 @@ test_util(void) tor_gettimeofday(&end); /* We might've timewarped a little. */ test_assert(tv_udiff(&start, &end) >= -5000); + + /* Test tor_log2(). */ + test_eq(tor_log2(64), 6); + test_eq(tor_log2(65), 6); + test_eq(tor_log2(63), 5); + test_eq(tor_log2(1), 0); + test_eq(tor_log2(2), 1); + test_eq(tor_log2(3), 1); + test_eq(tor_log2(4), 2); + test_eq(tor_log2(5), 2); + test_eq(tor_log2(U64_LITERAL(40000000000000000)), 55); + test_eq(tor_log2(UINT64_MAX), 63); + + /* Test round_to_power_of_2 */ + test_eq(round_to_power_of_2(120), 128); + test_eq(round_to_power_of_2(128), 128); + test_eq(round_to_power_of_2(130), 128); + test_eq(round_to_power_of_2(U64_LITERAL(40000000000000000)), + U64_LITERAL(1)<<55); + test_eq(round_to_power_of_2(0), 2); } static void |