diff options
author | Aleksandra Tsvetkova <aleksandra.tsvetkova@intel.com> | 2015-02-27 15:01:59 +0300 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-12-07 15:44:20 -0800 |
commit | 608b4514cb37170349bc3bf8936f18bdb0d35054 (patch) | |
tree | 2bf70158dc1f625b73332bbf569573119fad492c /tests/stdlib_test.cpp | |
parent | c1f6219c32543cb1d6701b13eb53b82abe1e0a12 (diff) |
A few new bionic tests.
Trivial tests for <alloca.h> and <byteswap.h>, plus slightly improved
test coverage for <inttypes.h> and <stdlib.h>.
Bug: N/A
Test: ran tests
Change-Id: Idac4141ffc760c4f7756332477ce5112950d61a5
Signed-off-by: Aleksandra Tsvetkova <aleksandra.tsvetkova@intel.com>
Diffstat (limited to 'tests/stdlib_test.cpp')
-rw-r--r-- | tests/stdlib_test.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 0c403807d..ed5767c16 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -138,6 +138,47 @@ TEST(stdlib, mrand48) { EXPECT_EQ(795539493, mrand48()); } +TEST(stdlib, jrand48_distribution) { + const int iterations = 4096; + const int pivot_low = 1536; + const int pivot_high = 2560; + + unsigned short xsubi[3]; + int bits[32] = {}; + + for (int iter = 0; iter < iterations; ++iter) { + long rand_val = jrand48(xsubi); + for (int bit = 0; bit < 32; ++bit) { + bits[bit] += (static_cast<unsigned long>(rand_val) >> bit) & 0x01; + } + } + + // Check that bit probability is uniform + for (int bit = 0; bit < 32; ++bit) { + EXPECT_TRUE((pivot_low <= bits[bit]) && (bits[bit] <= pivot_high)); + } +} + +TEST(stdlib, mrand48_distribution) { + const int iterations = 4096; + const int pivot_low = 1536; + const int pivot_high = 2560; + + int bits[32] = {}; + + for (int iter = 0; iter < iterations; ++iter) { + long rand_val = mrand48(); + for (int bit = 0; bit < 32; ++bit) { + bits[bit] += (static_cast<unsigned long>(rand_val) >> bit) & 0x01; + } + } + + // Check that bit probability is uniform + for (int bit = 0; bit < 32; ++bit) { + EXPECT_TRUE((pivot_low <= bits[bit]) && (bits[bit] <= pivot_high)); + } +} + TEST(stdlib, posix_memalign_sweep) { void* ptr; |