]>
git.proxmox.com Git - rustc.git/blob - src/jemalloc/test/unit/prng.c
1 #include "test/jemalloc_test.h"
3 TEST_BEGIN(test_prng_lg_range
)
5 uint64_t sa
, sb
, ra
, rb
;
9 ra
= prng_lg_range(&sa
, 64);
11 rb
= prng_lg_range(&sa
, 64);
13 "Repeated generation should produce repeated results");
16 rb
= prng_lg_range(&sb
, 64);
18 "Equivalent generation should produce equivalent results");
21 ra
= prng_lg_range(&sa
, 64);
22 rb
= prng_lg_range(&sa
, 64);
24 "Full-width results must not immediately repeat");
27 ra
= prng_lg_range(&sa
, 64);
28 for (lg_range
= 63; lg_range
> 0; lg_range
--) {
30 rb
= prng_lg_range(&sb
, lg_range
);
31 assert_u64_eq((rb
& (UINT64_C(0xffffffffffffffff) << lg_range
)),
32 0, "High order bits should be 0, lg_range=%u", lg_range
);
33 assert_u64_eq(rb
, (ra
>> (64 - lg_range
)),
34 "Expected high order bits of full-width result, "
35 "lg_range=%u", lg_range
);
40 TEST_BEGIN(test_prng_range
)
43 #define MAX_RANGE 10000000
47 for (range
= 2; range
< MAX_RANGE
; range
+= RANGE_STEP
) {
52 for (rep
= 0; rep
< NREPS
; rep
++) {
53 uint64_t r
= prng_range(&s
, range
);
55 assert_u64_lt(r
, range
, "Out of range");