diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-02-11 11:28:08 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-02-11 11:28:08 -0500 |
commit | 2b4d4ccb3d1ecf984012b39eb361307785b0c1c0 (patch) | |
tree | 037f87559f31a6804bdf62ab9c948f3138990fae /src/test/test_util.c | |
parent | d86a45f991693cf2367a6ccb94fc29c22f5f7b45 (diff) | |
parent | 69ab7cd8281dcb312eb47b738d1c620e7bc042d9 (diff) | |
download | tor-2b4d4ccb3d1ecf984012b39eb361307785b0c1c0.tar.gz tor-2b4d4ccb3d1ecf984012b39eb361307785b0c1c0.zip |
Merge remote-tracking branch 'public/bug7801_v2'
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index bed33fac25..a66941b004 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -3242,6 +3242,34 @@ test_util_set_env_var_in_sl(void *ptr) } static void +test_util_weak_random(void *arg) +{ + int i, j, n[16]; + tor_weak_rng_t rng; + (void) arg; + + tor_init_weak_random(&rng, (unsigned)time(NULL)); + + for (i = 1; i <= 256; ++i) { + for (j=0;j<100;++j) { + int r = tor_weak_random_range(&rng, i); + tt_int_op(0, <=, r); + tt_int_op(r, <, i); + } + } + + memset(n,0,sizeof(n)); + for (j=0;j<8192;++j) { + n[tor_weak_random_range(&rng, 16)]++; + } + + for (i=0;i<16;++i) + tt_int_op(n[i], >, 0); + done: + ; +} + +static void test_util_mathlog(void *arg) { double d; @@ -3312,6 +3340,7 @@ struct testcase_t util_tests[] = { UTIL_TEST(read_file_eof_two_loops, 0), UTIL_TEST(read_file_eof_zero_bytes, 0), UTIL_TEST(mathlog, 0), + UTIL_TEST(weak_random, 0), END_OF_TESTCASES }; |