Clean up SFMT test.

Refactor array declarations to remove some dubious casts.

Reduce array size to what is actually used.

Extract magic numbers into cpp macro definitions.
This commit is contained in:
Jason Evans 2013-12-10 15:05:24 -08:00
parent 6edc97db15
commit 19609724f9

View File

@ -35,9 +35,10 @@
*/
#include "test/jemalloc_test.h"
#define BLOCK_SIZE 100000
#define BLOCK_SIZE64 50000
#define COUNT 1000
#define BLOCK_SIZE 10000
#define BLOCK_SIZE64 (BLOCK_SIZE / 2)
#define COUNT_1 1000
#define COUNT_2 700
static const uint32_t init_gen_rand_32_expected[] = {
3440181298U, 1564997079U, 1510669302U, 2930277156U, 1452439940U,
@ -1450,23 +1451,22 @@ static const uint64_t init_by_array_64_expected[] = {
TEST_BEGIN(test_gen_rand_32)
{
uint64_t array1[BLOCK_SIZE / 4][2] JEMALLOC_ATTR(aligned(16));
uint64_t array2[10000 / 4][2] JEMALLOC_ATTR(aligned(16));
uint32_t array32[BLOCK_SIZE] JEMALLOC_ATTR(aligned(16));
uint32_t array32_2[BLOCK_SIZE] JEMALLOC_ATTR(aligned(16));
int i;
uint32_t *array32 = (uint32_t *)array1;
uint32_t *array32_2 = (uint32_t *)array2;
uint32_t r32;
sfmt_t *ctx;
assert_d_le(get_min_array_size32(), 10000, "Array size too small");
assert_d_le(get_min_array_size32(), BLOCK_SIZE,
"Array size too small");
ctx = init_gen_rand(1234);
fill_array32(ctx, array32, 10000);
fill_array32(ctx, array32_2, 10000);
fill_array32(ctx, array32, BLOCK_SIZE);
fill_array32(ctx, array32_2, BLOCK_SIZE);
fini_gen_rand(ctx);
ctx = init_gen_rand(1234);
for (i = 0; i < 10000; i++) {
if (i < 1000) {
for (i = 0; i < BLOCK_SIZE; i++) {
if (i < COUNT_1) {
assert_u32_eq(array32[i], init_gen_rand_32_expected[i],
"Output mismatch for i=%d", i);
}
@ -1474,7 +1474,7 @@ TEST_BEGIN(test_gen_rand_32)
assert_u32_eq(r32, array32[i],
"Mismatch at array32[%d]=%x, gen=%x", i, array32[i], r32);
}
for (i = 0; i < 700; i++) {
for (i = 0; i < COUNT_2; i++) {
r32 = gen_rand32(ctx);
assert_u32_eq(r32, array32_2[i],
"Mismatch at array32_2[%d]=%x, gen=%x", i, array32_2[i],
@ -1486,24 +1486,23 @@ TEST_END
TEST_BEGIN(test_by_array_32)
{
uint64_t array1[BLOCK_SIZE / 4][2] JEMALLOC_ATTR(aligned(16));
uint64_t array2[10000 / 4][2] JEMALLOC_ATTR(aligned(16));
uint32_t array32[BLOCK_SIZE] JEMALLOC_ATTR(aligned(16));
uint32_t array32_2[BLOCK_SIZE] JEMALLOC_ATTR(aligned(16));
int i;
uint32_t *array32 = (uint32_t *)array1;
uint32_t *array32_2 = (uint32_t *)array2;
uint32_t ini[4] = {0x1234, 0x5678, 0x9abc, 0xdef0};
uint32_t r32;
sfmt_t *ctx;
assert_d_le(get_min_array_size32(), 10000, "Array size too small");
assert_d_le(get_min_array_size32(), BLOCK_SIZE,
"Array size too small");
ctx = init_by_array(ini, 4);
fill_array32(ctx, array32, 10000);
fill_array32(ctx, array32_2, 10000);
fill_array32(ctx, array32, BLOCK_SIZE);
fill_array32(ctx, array32_2, BLOCK_SIZE);
fini_gen_rand(ctx);
ctx = init_by_array(ini, 4);
for (i = 0; i < 10000; i++) {
if (i < 1000) {
for (i = 0; i < BLOCK_SIZE; i++) {
if (i < COUNT_1) {
assert_u32_eq(array32[i], init_by_array_32_expected[i],
"Output mismatch for i=%d", i);
}
@ -1511,7 +1510,7 @@ TEST_BEGIN(test_by_array_32)
assert_u32_eq(r32, array32[i],
"Mismatch at array32[%d]=%x, gen=%x", i, array32[i], r32);
}
for (i = 0; i < 700; i++) {
for (i = 0; i < COUNT_2; i++) {
r32 = gen_rand32(ctx);
assert_u32_eq(r32, array32_2[i],
"Mismatch at array32_2[%d]=%x, gen=%x", i, array32_2[i],
@ -1523,23 +1522,22 @@ TEST_END
TEST_BEGIN(test_gen_rand_64)
{
uint64_t array1[BLOCK_SIZE / 4][2] JEMALLOC_ATTR(aligned(16));
uint64_t array2[10000 / 4][2] JEMALLOC_ATTR(aligned(16));
uint64_t array64[BLOCK_SIZE64] JEMALLOC_ATTR(aligned(16));
uint64_t array64_2[BLOCK_SIZE64] JEMALLOC_ATTR(aligned(16));
int i;
uint64_t *array64 = (uint64_t *)array1;
uint64_t *array64_2 = (uint64_t *)array2;
uint64_t r;
sfmt_t *ctx;
assert_d_le(get_min_array_size64(), 5000, "Array size too small");
assert_d_le(get_min_array_size64(), BLOCK_SIZE64,
"Array size too small");
ctx = init_gen_rand(4321);
fill_array64(ctx, array64, 5000);
fill_array64(ctx, array64_2, 5000);
fill_array64(ctx, array64, BLOCK_SIZE64);
fill_array64(ctx, array64_2, BLOCK_SIZE64);
fini_gen_rand(ctx);
ctx = init_gen_rand(4321);
for (i = 0; i < 5000; i++) {
if (i < 1000) {
for (i = 0; i < BLOCK_SIZE64; i++) {
if (i < COUNT_1) {
assert_u64_eq(array64[i], init_gen_rand_64_expected[i],
"Output mismatch for i=%d", i);
}
@ -1548,7 +1546,7 @@ TEST_BEGIN(test_gen_rand_64)
"Mismatch at array64[%d]=%"PRIx64", gen=%"PRIx64, i,
array64[i], r);
}
for (i = 0; i < 700; i++) {
for (i = 0; i < COUNT_2; i++) {
r = gen_rand64(ctx);
assert_u64_eq(r, array64_2[i],
"Mismatch at array64_2[%d]=%"PRIx64" gen=%"PRIx64"", i,
@ -1560,24 +1558,23 @@ TEST_END
TEST_BEGIN(test_by_array_64)
{
uint64_t array1[BLOCK_SIZE / 4][2] JEMALLOC_ATTR(aligned(16));
uint64_t array2[10000 / 4][2] JEMALLOC_ATTR(aligned(16));
uint64_t array64[BLOCK_SIZE64] JEMALLOC_ATTR(aligned(16));
uint64_t array64_2[BLOCK_SIZE64] JEMALLOC_ATTR(aligned(16));
int i;
uint64_t *array64 = (uint64_t *)array1;
uint64_t *array64_2 = (uint64_t *)array2;
uint64_t r;
uint32_t ini[] = {5, 4, 3, 2, 1};
sfmt_t *ctx;
assert_d_le(get_min_array_size64(), 5000, "Array size too small");
assert_d_le(get_min_array_size64(), BLOCK_SIZE64,
"Array size too small");
ctx = init_by_array(ini, 5);
fill_array64(ctx, array64, 5000);
fill_array64(ctx, array64_2, 5000);
fill_array64(ctx, array64, BLOCK_SIZE64);
fill_array64(ctx, array64_2, BLOCK_SIZE64);
fini_gen_rand(ctx);
ctx = init_by_array(ini, 5);
for (i = 0; i < 5000; i++) {
if (i < 1000) {
for (i = 0; i < BLOCK_SIZE64; i++) {
if (i < COUNT_1) {
assert_u64_eq(array64[i], init_by_array_64_expected[i],
"Output mismatch for i=%d");
}
@ -1586,7 +1583,7 @@ TEST_BEGIN(test_by_array_64)
"Mismatch at array64[%d]=%"PRIx64" gen=%"PRIx64, i,
array64[i], r);
}
for (i = 0; i < 700; i++) {
for (i = 0; i < COUNT_2; i++) {
r = gen_rand64(ctx);
assert_u64_eq(r, array64_2[i],
"Mismatch at array64_2[%d]=%"PRIx64" gen=%"PRIx64, i,