mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-20 17:31:16 +03:00
Reformat the codebase with the clang-format 18.
This commit is contained in:
parent
0a6215c171
commit
f1bba4a87c
346 changed files with 18286 additions and 17770 deletions
|
|
@ -46,15 +46,15 @@ do_allocs(size_t sz, size_t cnt, bool do_frees) {
|
|||
int
|
||||
main(void) {
|
||||
size_t lg_prof_sample_local = 19;
|
||||
int err = mallctl("prof.reset", NULL, NULL,
|
||||
(void *)&lg_prof_sample_local, sizeof(lg_prof_sample_local));
|
||||
int err = mallctl("prof.reset", NULL, NULL,
|
||||
(void *)&lg_prof_sample_local, sizeof(lg_prof_sample_local));
|
||||
assert(err == 0);
|
||||
|
||||
prof_backtrace_hook_set(mock_backtrace);
|
||||
do_allocs(16, 32 * 1024 * 1024, /* do_frees */ true);
|
||||
do_allocs(32 * 1024* 1024, 16, /* do_frees */ true);
|
||||
do_allocs(32 * 1024 * 1024, 16, /* do_frees */ true);
|
||||
do_allocs(16, 32 * 1024 * 1024, /* do_frees */ false);
|
||||
do_allocs(32 * 1024* 1024, 16, /* do_frees */ false);
|
||||
do_allocs(32 * 1024 * 1024, 16, /* do_frees */ false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ print_buckets(const size_t buckets[], const size_t means[],
|
|||
if (buckets[i] + stddevs[i] <= means[i]) {
|
||||
malloc_write(" ");
|
||||
for (size_t t = means[i] - buckets[i]; t >= stddevs[i];
|
||||
t -= stddevs[i]) {
|
||||
t -= stddevs[i]) {
|
||||
malloc_write("-");
|
||||
}
|
||||
} else if (buckets[i] >= means[i] + stddevs[i]) {
|
||||
malloc_write(" ");
|
||||
for (size_t t = buckets[i] - means[i]; t >= stddevs[i];
|
||||
t -= stddevs[i]) {
|
||||
t -= stddevs[i]) {
|
||||
malloc_write("+");
|
||||
}
|
||||
}
|
||||
|
|
@ -93,8 +93,8 @@ bucket_analysis(uint64_t (*gen)(void *), void *opaque, size_t buckets[],
|
|||
for (size_t i = 1; i <= 3; ++i) {
|
||||
malloc_printf("round %zu\n", i);
|
||||
fill(buckets, n_bucket, 0);
|
||||
collect_buckets(gen, opaque, buckets, n_bucket,
|
||||
lg_bucket_width, n_iter);
|
||||
collect_buckets(
|
||||
gen, opaque, buckets, n_bucket, lg_bucket_width, n_iter);
|
||||
print_buckets(buckets, means, stddevs, n_bucket);
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ bucket_analysis(uint64_t (*gen)(void *), void *opaque, size_t buckets[],
|
|||
|
||||
typedef struct uniform_gen_arg_s uniform_gen_arg_t;
|
||||
struct uniform_gen_arg_s {
|
||||
uint64_t state;
|
||||
uint64_t state;
|
||||
const unsigned lg_range;
|
||||
};
|
||||
|
||||
|
|
@ -131,8 +131,10 @@ TEST_BEGIN(test_uniform) {
|
|||
* integers, and that the minimal bucket mean is at least
|
||||
* MIN_BUCKET_MEAN.
|
||||
*/
|
||||
const size_t q = 1 << QUOTIENT_CEIL(LG_CEIL(QUOTIENT_CEIL(
|
||||
MIN_BUCKET_MEAN, N_BUCKET * (N_BUCKET - 1))), 2);
|
||||
const size_t q = 1 << QUOTIENT_CEIL(
|
||||
LG_CEIL(QUOTIENT_CEIL(
|
||||
MIN_BUCKET_MEAN, N_BUCKET * (N_BUCKET - 1))),
|
||||
2);
|
||||
const size_t stddev = (N_BUCKET - 1) * q;
|
||||
const size_t mean = N_BUCKET * stddev * q;
|
||||
const size_t n_iter = N_BUCKET * mean;
|
||||
|
|
@ -142,14 +144,14 @@ TEST_BEGIN(test_uniform) {
|
|||
size_t stddevs[N_BUCKET];
|
||||
fill(stddevs, N_BUCKET, stddev);
|
||||
|
||||
uniform_gen_arg_t arg = {(uint64_t)(uintptr_t)&lg_range_test,
|
||||
lg_range_test};
|
||||
uniform_gen_arg_t arg = {
|
||||
(uint64_t)(uintptr_t)&lg_range_test, lg_range_test};
|
||||
size_t buckets[N_BUCKET];
|
||||
assert_zu_ge(lg_range_test, LG_N_BUCKET, "");
|
||||
const size_t lg_bucket_width = lg_range_test - LG_N_BUCKET;
|
||||
|
||||
bucket_analysis(uniform_gen, &arg, buckets, means, stddevs,
|
||||
N_BUCKET, lg_bucket_width, n_iter);
|
||||
bucket_analysis(uniform_gen, &arg, buckets, means, stddevs, N_BUCKET,
|
||||
lg_bucket_width, n_iter);
|
||||
|
||||
#undef LG_N_BUCKET
|
||||
#undef N_BUCKET
|
||||
|
|
@ -168,8 +170,8 @@ TEST_END
|
|||
* comments in test_prof_sample for explanations for n_divide.
|
||||
*/
|
||||
static double
|
||||
fill_geometric_proportions(double proportions[], const size_t n_bucket,
|
||||
const size_t n_divide) {
|
||||
fill_geometric_proportions(
|
||||
double proportions[], const size_t n_bucket, const size_t n_divide) {
|
||||
assert(n_bucket > 0);
|
||||
assert(n_divide > 0);
|
||||
double x = 1.;
|
||||
|
|
@ -220,12 +222,12 @@ TEST_BEGIN(test_prof_sample) {
|
|||
#ifdef JEMALLOC_PROF
|
||||
|
||||
/* Number of divisions within [0, mean). */
|
||||
#define LG_N_DIVIDE 3
|
||||
#define N_DIVIDE (1 << LG_N_DIVIDE)
|
||||
# define LG_N_DIVIDE 3
|
||||
# define N_DIVIDE (1 << LG_N_DIVIDE)
|
||||
|
||||
/* Coverage of buckets in terms of multiples of mean. */
|
||||
#define LG_N_MULTIPLY 2
|
||||
#define N_GEO_BUCKET (N_DIVIDE << LG_N_MULTIPLY)
|
||||
# define LG_N_MULTIPLY 2
|
||||
# define N_GEO_BUCKET (N_DIVIDE << LG_N_MULTIPLY)
|
||||
|
||||
test_skip_if(!opt_prof);
|
||||
|
||||
|
|
@ -233,14 +235,15 @@ TEST_BEGIN(test_prof_sample) {
|
|||
|
||||
size_t lg_prof_sample_orig = lg_prof_sample;
|
||||
assert_d_eq(mallctl("prof.reset", NULL, NULL, &lg_prof_sample_test,
|
||||
sizeof(size_t)), 0, "");
|
||||
sizeof(size_t)),
|
||||
0, "");
|
||||
malloc_printf("lg_prof_sample = %zu\n", lg_prof_sample_test);
|
||||
|
||||
double proportions[N_GEO_BUCKET + 1];
|
||||
const double min_proportion = fill_geometric_proportions(proportions,
|
||||
N_GEO_BUCKET + 1, N_DIVIDE);
|
||||
const size_t n_iter = round_to_nearest(MIN_BUCKET_MEAN /
|
||||
min_proportion);
|
||||
double proportions[N_GEO_BUCKET + 1];
|
||||
const double min_proportion = fill_geometric_proportions(
|
||||
proportions, N_GEO_BUCKET + 1, N_DIVIDE);
|
||||
const size_t n_iter = round_to_nearest(
|
||||
MIN_BUCKET_MEAN / min_proportion);
|
||||
size_t means[N_GEO_BUCKET + 1];
|
||||
size_t stddevs[N_GEO_BUCKET + 1];
|
||||
fill_references(means, stddevs, proportions, N_GEO_BUCKET + 1, n_iter);
|
||||
|
|
@ -255,12 +258,13 @@ TEST_BEGIN(test_prof_sample) {
|
|||
N_GEO_BUCKET + 1, lg_bucket_width, n_iter);
|
||||
|
||||
assert_d_eq(mallctl("prof.reset", NULL, NULL, &lg_prof_sample_orig,
|
||||
sizeof(size_t)), 0, "");
|
||||
sizeof(size_t)),
|
||||
0, "");
|
||||
|
||||
#undef LG_N_DIVIDE
|
||||
#undef N_DIVIDE
|
||||
#undef LG_N_MULTIPLY
|
||||
#undef N_GEO_BUCKET
|
||||
# undef LG_N_DIVIDE
|
||||
# undef N_DIVIDE
|
||||
# undef LG_N_MULTIPLY
|
||||
# undef N_GEO_BUCKET
|
||||
|
||||
#endif /* JEMALLOC_PROF */
|
||||
}
|
||||
|
|
@ -270,7 +274,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_uniform,
|
||||
test_prof_sample);
|
||||
return test_no_reentrancy(test_uniform, test_prof_sample);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
static void
|
||||
do_print(const char *name, size_t sz_bytes) {
|
||||
const char *sizes[] = {"bytes", "KB", "MB", "GB", "TB", "PB", "EB",
|
||||
"ZB"};
|
||||
size_t sizes_max = sizeof(sizes)/sizeof(sizes[0]);
|
||||
const char *sizes[] = {
|
||||
"bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB"};
|
||||
size_t sizes_max = sizeof(sizes) / sizeof(sizes[0]);
|
||||
|
||||
size_t ind = 0;
|
||||
double sz = sz_bytes;
|
||||
|
|
@ -30,8 +30,7 @@ do_print(const char *name, size_t sz_bytes) {
|
|||
|
||||
int
|
||||
main(void) {
|
||||
#define P(type) \
|
||||
do_print(#type, sizeof(type))
|
||||
#define P(type) do_print(#type, sizeof(type))
|
||||
P(arena_t);
|
||||
P(arena_stats_t);
|
||||
P(base_t);
|
||||
|
|
|
|||
|
|
@ -61,58 +61,59 @@
|
|||
* @return output
|
||||
*/
|
||||
JEMALLOC_ALWAYS_INLINE
|
||||
vector unsigned int vec_recursion(vector unsigned int a,
|
||||
vector unsigned int b,
|
||||
vector unsigned int c,
|
||||
vector unsigned int d) {
|
||||
|
||||
const vector unsigned int sl1 = ALTI_SL1;
|
||||
const vector unsigned int sr1 = ALTI_SR1;
|
||||
vector unsigned int
|
||||
vec_recursion(vector unsigned int a, vector unsigned int b,
|
||||
vector unsigned int c, vector unsigned int d) {
|
||||
const vector unsigned int sl1 = ALTI_SL1;
|
||||
const vector unsigned int sr1 = ALTI_SR1;
|
||||
#ifdef ONLY64
|
||||
const vector unsigned int mask = ALTI_MSK64;
|
||||
const vector unsigned char perm_sl = ALTI_SL2_PERM64;
|
||||
const vector unsigned char perm_sr = ALTI_SR2_PERM64;
|
||||
const vector unsigned int mask = ALTI_MSK64;
|
||||
const vector unsigned char perm_sl = ALTI_SL2_PERM64;
|
||||
const vector unsigned char perm_sr = ALTI_SR2_PERM64;
|
||||
#else
|
||||
const vector unsigned int mask = ALTI_MSK;
|
||||
const vector unsigned char perm_sl = ALTI_SL2_PERM;
|
||||
const vector unsigned char perm_sr = ALTI_SR2_PERM;
|
||||
const vector unsigned int mask = ALTI_MSK;
|
||||
const vector unsigned char perm_sl = ALTI_SL2_PERM;
|
||||
const vector unsigned char perm_sr = ALTI_SR2_PERM;
|
||||
#endif
|
||||
vector unsigned int v, w, x, y, z;
|
||||
x = vec_perm(a, (vector unsigned int)perm_sl, perm_sl);
|
||||
v = a;
|
||||
y = vec_sr(b, sr1);
|
||||
z = vec_perm(c, (vector unsigned int)perm_sr, perm_sr);
|
||||
w = vec_sl(d, sl1);
|
||||
z = vec_xor(z, w);
|
||||
y = vec_and(y, mask);
|
||||
v = vec_xor(v, x);
|
||||
z = vec_xor(z, y);
|
||||
z = vec_xor(z, v);
|
||||
return z;
|
||||
vector unsigned int v, w, x, y, z;
|
||||
x = vec_perm(a, (vector unsigned int)perm_sl, perm_sl);
|
||||
v = a;
|
||||
y = vec_sr(b, sr1);
|
||||
z = vec_perm(c, (vector unsigned int)perm_sr, perm_sr);
|
||||
w = vec_sl(d, sl1);
|
||||
z = vec_xor(z, w);
|
||||
y = vec_and(y, mask);
|
||||
v = vec_xor(v, x);
|
||||
z = vec_xor(z, y);
|
||||
z = vec_xor(z, v);
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function fills the internal state array with pseudorandom
|
||||
* integers.
|
||||
*/
|
||||
static inline void gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
vector unsigned int r, r1, r2;
|
||||
static inline void
|
||||
gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
vector unsigned int r, r1, r2;
|
||||
|
||||
r1 = ctx->sfmt[N - 2].s;
|
||||
r2 = ctx->sfmt[N - 1].s;
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = vec_recursion(ctx->sfmt[i].s, ctx->sfmt[i + POS1].s, r1, r2);
|
||||
ctx->sfmt[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = vec_recursion(ctx->sfmt[i].s, ctx->sfmt[i + POS1 - N].s, r1, r2);
|
||||
ctx->sfmt[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
r1 = ctx->sfmt[N - 2].s;
|
||||
r2 = ctx->sfmt[N - 1].s;
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = vec_recursion(
|
||||
ctx->sfmt[i].s, ctx->sfmt[i + POS1].s, r1, r2);
|
||||
ctx->sfmt[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = vec_recursion(
|
||||
ctx->sfmt[i].s, ctx->sfmt[i + POS1 - N].s, r1, r2);
|
||||
ctx->sfmt[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,50 +123,57 @@ static inline void gen_rand_all(sfmt_t *ctx) {
|
|||
* @param array an 128-bit array to be filled by pseudorandom numbers.
|
||||
* @param size number of 128-bit pesudorandom numbers to be generated.
|
||||
*/
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
vector unsigned int r, r1, r2;
|
||||
static inline void
|
||||
gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
vector unsigned int r, r1, r2;
|
||||
|
||||
r1 = ctx->sfmt[N - 2].s;
|
||||
r2 = ctx->sfmt[N - 1].s;
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = vec_recursion(ctx->sfmt[i].s, ctx->sfmt[i + POS1].s, r1, r2);
|
||||
array[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = vec_recursion(ctx->sfmt[i].s, array[i + POS1 - N].s, r1, r2);
|
||||
array[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
/* main loop */
|
||||
for (; i < size - N; i++) {
|
||||
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
|
||||
array[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
ctx->sfmt[j].s = array[j + size - N].s;
|
||||
}
|
||||
for (; i < size; i++) {
|
||||
r = vec_recursion(array[i - N].s, array[i + POS1 - N].s, r1, r2);
|
||||
array[i].s = r;
|
||||
ctx->sfmt[j++].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
r1 = ctx->sfmt[N - 2].s;
|
||||
r2 = ctx->sfmt[N - 1].s;
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = vec_recursion(
|
||||
ctx->sfmt[i].s, ctx->sfmt[i + POS1].s, r1, r2);
|
||||
array[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = vec_recursion(
|
||||
ctx->sfmt[i].s, array[i + POS1 - N].s, r1, r2);
|
||||
array[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
/* main loop */
|
||||
for (; i < size - N; i++) {
|
||||
r = vec_recursion(
|
||||
array[i - N].s, array[i + POS1 - N].s, r1, r2);
|
||||
array[i].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
ctx->sfmt[j].s = array[j + size - N].s;
|
||||
}
|
||||
for (; i < size; i++) {
|
||||
r = vec_recursion(
|
||||
array[i - N].s, array[i + POS1 - N].s, r1, r2);
|
||||
array[i].s = r;
|
||||
ctx->sfmt[j++].s = r;
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef ONLY64
|
||||
#if defined(__APPLE__)
|
||||
#define ALTI_SWAP (vector unsigned char) \
|
||||
(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11)
|
||||
#else
|
||||
#define ALTI_SWAP {4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11}
|
||||
#endif
|
||||
# if defined(__APPLE__)
|
||||
# define ALTI_SWAP \
|
||||
(vector unsigned char)(4, 5, 6, 7, 0, 1, 2, 3, 12, 13, \
|
||||
14, 15, 8, 9, 10, 11)
|
||||
# else
|
||||
# define ALTI_SWAP \
|
||||
{ 4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11 }
|
||||
# endif
|
||||
/**
|
||||
* This function swaps high and low 32-bit of 64-bit integers in user
|
||||
* specified array.
|
||||
|
|
@ -173,13 +181,15 @@ static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
|||
* @param array an 128-bit array to be swaped.
|
||||
* @param size size of 128-bit array.
|
||||
*/
|
||||
static inline void swap(w128_t *array, int size) {
|
||||
int i;
|
||||
const vector unsigned char perm = ALTI_SWAP;
|
||||
static inline void
|
||||
swap(w128_t *array, int size) {
|
||||
int i;
|
||||
const vector unsigned char perm = ALTI_SWAP;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
array[i].s = vec_perm(array[i].s, (vector unsigned int)perm, perm);
|
||||
}
|
||||
for (i = 0; i < size; i++) {
|
||||
array[i].s = vec_perm(
|
||||
array[i].s, (vector unsigned int)perm, perm);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,10 @@
|
|||
#define SFMT_PARAMS_H
|
||||
|
||||
#if !defined(MEXP)
|
||||
#ifdef __GNUC__
|
||||
#warning "MEXP is not defined. I assume MEXP is 19937."
|
||||
#endif
|
||||
#define MEXP 19937
|
||||
# ifdef __GNUC__
|
||||
# warning "MEXP is not defined. I assume MEXP is 19937."
|
||||
# endif
|
||||
# define MEXP 19937
|
||||
#endif
|
||||
/*-----------------
|
||||
BASIC DEFINITIONS
|
||||
|
|
@ -100,32 +100,32 @@
|
|||
*/
|
||||
|
||||
#if MEXP == 607
|
||||
#include "test/SFMT-params607.h"
|
||||
# include "test/SFMT-params607.h"
|
||||
#elif MEXP == 1279
|
||||
#include "test/SFMT-params1279.h"
|
||||
# include "test/SFMT-params1279.h"
|
||||
#elif MEXP == 2281
|
||||
#include "test/SFMT-params2281.h"
|
||||
# include "test/SFMT-params2281.h"
|
||||
#elif MEXP == 4253
|
||||
#include "test/SFMT-params4253.h"
|
||||
# include "test/SFMT-params4253.h"
|
||||
#elif MEXP == 11213
|
||||
#include "test/SFMT-params11213.h"
|
||||
# include "test/SFMT-params11213.h"
|
||||
#elif MEXP == 19937
|
||||
#include "test/SFMT-params19937.h"
|
||||
# include "test/SFMT-params19937.h"
|
||||
#elif MEXP == 44497
|
||||
#include "test/SFMT-params44497.h"
|
||||
# include "test/SFMT-params44497.h"
|
||||
#elif MEXP == 86243
|
||||
#include "test/SFMT-params86243.h"
|
||||
# include "test/SFMT-params86243.h"
|
||||
#elif MEXP == 132049
|
||||
#include "test/SFMT-params132049.h"
|
||||
# include "test/SFMT-params132049.h"
|
||||
#elif MEXP == 216091
|
||||
#include "test/SFMT-params216091.h"
|
||||
# include "test/SFMT-params216091.h"
|
||||
#else
|
||||
#ifdef __GNUC__
|
||||
#error "MEXP is not valid."
|
||||
#undef MEXP
|
||||
#else
|
||||
#undef MEXP
|
||||
#endif
|
||||
# ifdef __GNUC__
|
||||
# error "MEXP is not valid."
|
||||
# undef MEXP
|
||||
# else
|
||||
# undef MEXP
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS11213_H
|
||||
#define SFMT_PARAMS11213_H
|
||||
|
||||
#define POS1 68
|
||||
#define SL1 14
|
||||
#define SL2 3
|
||||
#define SR1 7
|
||||
#define SR2 3
|
||||
#define MSK1 0xeffff7fbU
|
||||
#define MSK2 0xffffffefU
|
||||
#define MSK3 0xdfdfbfffU
|
||||
#define MSK4 0x7fffdbfdU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0xe8148000U
|
||||
#define PARITY4 0xd0c7afa3U
|
||||
|
||||
#define POS1 68
|
||||
#define SL1 14
|
||||
#define SL2 3
|
||||
#define SR1 7
|
||||
#define SR2 3
|
||||
#define MSK1 0xeffff7fbU
|
||||
#define MSK2 0xffffffefU
|
||||
#define MSK3 0xdfdfbfffU
|
||||
#define MSK4 0x7fffdbfdU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0xe8148000U
|
||||
#define PARITY4 0xd0c7afa3U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
|
||||
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
|
||||
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
|
||||
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-11213:68-14-3-7-3:effff7fb-ffffffef-dfdfbfff-7fffdbfd"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, \
|
||||
15, 8, 9, 10)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, \
|
||||
14, 15, 0, 1, 2)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, \
|
||||
8, 19, 19, 19, 12)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(13, 14, 15, 0, 1, 2, 3, 4, 19, 19, 19, \
|
||||
8, 9, 10, 11, 12)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, 14, 15, 0, 1, 2 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8, 19, 19, 19, 12 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 13, 14, 15, 0, 1, 2, 3, 4, 19, 19, 19, 8, 9, 10, 11, 12 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-11213:68-14-3-7-3:effff7fb-ffffffef-dfdfbfff-7fffdbfd"
|
||||
|
||||
#endif /* SFMT_PARAMS11213_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS1279_H
|
||||
#define SFMT_PARAMS1279_H
|
||||
|
||||
#define POS1 7
|
||||
#define SL1 14
|
||||
#define SL2 3
|
||||
#define SR1 5
|
||||
#define SR2 1
|
||||
#define MSK1 0xf7fefffdU
|
||||
#define MSK2 0x7fefcfffU
|
||||
#define MSK3 0xaff3ef3fU
|
||||
#define MSK4 0xb5ffff7fU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x20000000U
|
||||
|
||||
#define POS1 7
|
||||
#define SL1 14
|
||||
#define SL2 3
|
||||
#define SR1 5
|
||||
#define SR2 1
|
||||
#define MSK1 0xf7fefffdU
|
||||
#define MSK2 0x7fefcfffU
|
||||
#define MSK3 0xaff3ef3fU
|
||||
#define MSK4 0xb5ffff7fU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x20000000U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
|
||||
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-1279:7-14-3-5-1:f7fefffd-7fefcfff-aff3ef3f-b5ffff7f"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, \
|
||||
15, 8, 9, 10)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, \
|
||||
14, 15, 0, 1, 2)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, 14, 15, 0, 1, 2 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-1279:7-14-3-5-1:f7fefffd-7fefcfff-aff3ef3f-b5ffff7f"
|
||||
|
||||
#endif /* SFMT_PARAMS1279_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS132049_H
|
||||
#define SFMT_PARAMS132049_H
|
||||
|
||||
#define POS1 110
|
||||
#define SL1 19
|
||||
#define SL2 1
|
||||
#define SR1 21
|
||||
#define SR2 1
|
||||
#define MSK1 0xffffbb5fU
|
||||
#define MSK2 0xfb6ebf95U
|
||||
#define MSK3 0xfffefffaU
|
||||
#define MSK4 0xcff77fffU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0xcb520000U
|
||||
#define PARITY4 0xc7e91c7dU
|
||||
|
||||
#define POS1 110
|
||||
#define SL1 19
|
||||
#define SL2 1
|
||||
#define SR1 21
|
||||
#define SR2 1
|
||||
#define MSK1 0xffffbb5fU
|
||||
#define MSK2 0xfb6ebf95U
|
||||
#define MSK3 0xfffefffaU
|
||||
#define MSK4 0xcff77fffU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0xcb520000U
|
||||
#define PARITY4 0xc7e91c7dU
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
|
||||
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-132049:110-19-1-21-1:ffffbb5f-fb6ebf95-fffefffa-cff77fff"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, \
|
||||
13, 14, 15, 8)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, \
|
||||
13, 14, 15, 0)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-132049:110-19-1-21-1:ffffbb5f-fb6ebf95-fffefffa-cff77fff"
|
||||
|
||||
#endif /* SFMT_PARAMS132049_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS19937_H
|
||||
#define SFMT_PARAMS19937_H
|
||||
|
||||
#define POS1 122
|
||||
#define SL1 18
|
||||
#define SL2 1
|
||||
#define SR1 11
|
||||
#define SR2 1
|
||||
#define MSK1 0xdfffffefU
|
||||
#define MSK2 0xddfecb7fU
|
||||
#define MSK3 0xbffaffffU
|
||||
#define MSK4 0xbffffff6U
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x13c9e684U
|
||||
|
||||
#define POS1 122
|
||||
#define SL1 18
|
||||
#define SL2 1
|
||||
#define SR1 11
|
||||
#define SR2 1
|
||||
#define MSK1 0xdfffffefU
|
||||
#define MSK2 0xddfecb7fU
|
||||
#define MSK3 0xbffaffffU
|
||||
#define MSK4 0xbffffff6U
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x13c9e684U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
|
||||
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, \
|
||||
13, 14, 15, 8)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, \
|
||||
13, 14, 15, 0)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
|
||||
|
||||
#endif /* SFMT_PARAMS19937_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS216091_H
|
||||
#define SFMT_PARAMS216091_H
|
||||
|
||||
#define POS1 627
|
||||
#define SL1 11
|
||||
#define SL2 3
|
||||
#define SR1 10
|
||||
#define SR2 1
|
||||
#define MSK1 0xbff7bff7U
|
||||
#define MSK2 0xbfffffffU
|
||||
#define MSK3 0xbffffa7fU
|
||||
#define MSK4 0xffddfbfbU
|
||||
#define PARITY1 0xf8000001U
|
||||
#define PARITY2 0x89e80709U
|
||||
#define PARITY3 0x3bd2b64bU
|
||||
#define PARITY4 0x0c64b1e4U
|
||||
|
||||
#define POS1 627
|
||||
#define SL1 11
|
||||
#define SL2 3
|
||||
#define SR1 10
|
||||
#define SR2 1
|
||||
#define MSK1 0xbff7bff7U
|
||||
#define MSK2 0xbfffffffU
|
||||
#define MSK3 0xbffffa7fU
|
||||
#define MSK4 0xffddfbfbU
|
||||
#define PARITY1 0xf8000001U
|
||||
#define PARITY2 0x89e80709U
|
||||
#define PARITY3 0x3bd2b64bU
|
||||
#define PARITY4 0x0c64b1e4U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
|
||||
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-216091:627-11-3-10-1:bff7bff7-bfffffff-bffffa7f-ffddfbfb"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, \
|
||||
15, 8, 9, 10)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, \
|
||||
14, 15, 0, 1, 2)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, 14, 15, 0, 1, 2 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-216091:627-11-3-10-1:bff7bff7-bfffffff-bffffa7f-ffddfbfb"
|
||||
|
||||
#endif /* SFMT_PARAMS216091_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS2281_H
|
||||
#define SFMT_PARAMS2281_H
|
||||
|
||||
#define POS1 12
|
||||
#define SL1 19
|
||||
#define SL2 1
|
||||
#define SR1 5
|
||||
#define SR2 1
|
||||
#define MSK1 0xbff7ffbfU
|
||||
#define MSK2 0xfdfffffeU
|
||||
#define MSK3 0xf7ffef7fU
|
||||
#define MSK4 0xf2f7cbbfU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x41dfa600U
|
||||
|
||||
#define POS1 12
|
||||
#define SL1 19
|
||||
#define SL2 1
|
||||
#define SR1 5
|
||||
#define SR2 1
|
||||
#define MSK1 0xbff7ffbfU
|
||||
#define MSK2 0xfdfffffeU
|
||||
#define MSK3 0xf7ffef7fU
|
||||
#define MSK4 0xf2f7cbbfU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x41dfa600U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
|
||||
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-2281:12-19-1-5-1:bff7ffbf-fdfffffe-f7ffef7f-f2f7cbbf"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, \
|
||||
13, 14, 15, 8)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, \
|
||||
13, 14, 15, 0)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-2281:12-19-1-5-1:bff7ffbf-fdfffffe-f7ffef7f-f2f7cbbf"
|
||||
|
||||
#endif /* SFMT_PARAMS2281_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS4253_H
|
||||
#define SFMT_PARAMS4253_H
|
||||
|
||||
#define POS1 17
|
||||
#define SL1 20
|
||||
#define SL2 1
|
||||
#define SR1 7
|
||||
#define SR2 1
|
||||
#define MSK1 0x9f7bffffU
|
||||
#define MSK2 0x9fffff5fU
|
||||
#define MSK3 0x3efffffbU
|
||||
#define MSK4 0xfffff7bbU
|
||||
#define PARITY1 0xa8000001U
|
||||
#define PARITY2 0xaf5390a3U
|
||||
#define PARITY3 0xb740b3f8U
|
||||
#define PARITY4 0x6c11486dU
|
||||
|
||||
#define POS1 17
|
||||
#define SL1 20
|
||||
#define SL2 1
|
||||
#define SR1 7
|
||||
#define SR2 1
|
||||
#define MSK1 0x9f7bffffU
|
||||
#define MSK2 0x9fffff5fU
|
||||
#define MSK3 0x3efffffbU
|
||||
#define MSK4 0xfffff7bbU
|
||||
#define PARITY1 0xa8000001U
|
||||
#define PARITY2 0xaf5390a3U
|
||||
#define PARITY3 0xb740b3f8U
|
||||
#define PARITY4 0x6c11486dU
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {1,2,3,23,5,6,7,0,9,10,11,4,13,14,15,8}
|
||||
#define ALTI_SL2_PERM64 {1,2,3,4,5,6,7,31,9,10,11,12,13,14,15,0}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-4253:17-20-1-7-1:9f7bffff-9fffff5f-3efffffb-fffff7bb"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, \
|
||||
13, 14, 15, 8)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, \
|
||||
13, 14, 15, 0)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-4253:17-20-1-7-1:9f7bffff-9fffff5f-3efffffb-fffff7bb"
|
||||
|
||||
#endif /* SFMT_PARAMS4253_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS44497_H
|
||||
#define SFMT_PARAMS44497_H
|
||||
|
||||
#define POS1 330
|
||||
#define SL1 5
|
||||
#define SL2 3
|
||||
#define SR1 9
|
||||
#define SR2 3
|
||||
#define MSK1 0xeffffffbU
|
||||
#define MSK2 0xdfbebfffU
|
||||
#define MSK3 0xbfbf7befU
|
||||
#define MSK4 0x9ffd7bffU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0xa3ac4000U
|
||||
#define PARITY4 0xecc1327aU
|
||||
|
||||
#define POS1 330
|
||||
#define SL1 5
|
||||
#define SL2 3
|
||||
#define SR1 9
|
||||
#define SR2 3
|
||||
#define MSK1 0xeffffffbU
|
||||
#define MSK2 0xdfbebfffU
|
||||
#define MSK3 0xbfbf7befU
|
||||
#define MSK4 0x9ffd7bffU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0xa3ac4000U
|
||||
#define PARITY4 0xecc1327aU
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
|
||||
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
|
||||
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
|
||||
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-44497:330-5-3-9-3:effffffb-dfbebfff-bfbf7bef-9ffd7bff"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, \
|
||||
15, 8, 9, 10)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, \
|
||||
14, 15, 0, 1, 2)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, \
|
||||
8, 19, 19, 19, 12)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(13, 14, 15, 0, 1, 2, 3, 4, 19, 19, 19, \
|
||||
8, 9, 10, 11, 12)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, 14, 15, 0, 1, 2 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8, 19, 19, 19, 12 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 13, 14, 15, 0, 1, 2, 3, 4, 19, 19, 19, 8, 9, 10, 11, 12 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-44497:330-5-3-9-3:effffffb-dfbebfff-bfbf7bef-9ffd7bff"
|
||||
|
||||
#endif /* SFMT_PARAMS44497_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS607_H
|
||||
#define SFMT_PARAMS607_H
|
||||
|
||||
#define POS1 2
|
||||
#define SL1 15
|
||||
#define SL2 3
|
||||
#define SR1 13
|
||||
#define SR2 3
|
||||
#define MSK1 0xfdff37ffU
|
||||
#define MSK2 0xef7f3f7dU
|
||||
#define MSK3 0xff777b7dU
|
||||
#define MSK4 0x7ff7fb2fU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x5986f054U
|
||||
|
||||
#define POS1 2
|
||||
#define SL1 15
|
||||
#define SL2 3
|
||||
#define SR1 13
|
||||
#define SR2 3
|
||||
#define MSK1 0xfdff37ffU
|
||||
#define MSK2 0xef7f3f7dU
|
||||
#define MSK3 0xff777b7dU
|
||||
#define MSK4 0x7ff7fb2fU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0x5986f054U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {3,21,21,21,7,0,1,2,11,4,5,6,15,8,9,10}
|
||||
#define ALTI_SL2_PERM64 {3,4,5,6,7,29,29,29,11,12,13,14,15,0,1,2}
|
||||
#define ALTI_SR2_PERM {5,6,7,0,9,10,11,4,13,14,15,8,19,19,19,12}
|
||||
#define ALTI_SR2_PERM64 {13,14,15,0,1,2,3,4,19,19,19,8,9,10,11,12}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-607:2-15-3-13-3:fdff37ff-ef7f3f7d-ff777b7d-7ff7fb2f"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, \
|
||||
15, 8, 9, 10)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, \
|
||||
14, 15, 0, 1, 2)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, \
|
||||
8, 19, 19, 19, 12)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(13, 14, 15, 0, 1, 2, 3, 4, 19, 19, 19, \
|
||||
8, 9, 10, 11, 12)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 3, 21, 21, 21, 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 3, 4, 5, 6, 7, 29, 29, 29, 11, 12, 13, 14, 15, 0, 1, 2 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8, 19, 19, 19, 12 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 13, 14, 15, 0, 1, 2, 3, 4, 19, 19, 19, 8, 9, 10, 11, 12 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-607:2-15-3-13-3:fdff37ff-ef7f3f7d-ff777b7d-7ff7fb2f"
|
||||
|
||||
#endif /* SFMT_PARAMS607_H */
|
||||
|
|
|
|||
|
|
@ -36,46 +36,56 @@
|
|||
#ifndef SFMT_PARAMS86243_H
|
||||
#define SFMT_PARAMS86243_H
|
||||
|
||||
#define POS1 366
|
||||
#define SL1 6
|
||||
#define SL2 7
|
||||
#define SR1 19
|
||||
#define SR2 1
|
||||
#define MSK1 0xfdbffbffU
|
||||
#define MSK2 0xbff7ff3fU
|
||||
#define MSK3 0xfd77efffU
|
||||
#define MSK4 0xbf9ff3ffU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0xe9528d85U
|
||||
|
||||
#define POS1 366
|
||||
#define SL1 6
|
||||
#define SL2 7
|
||||
#define SR1 19
|
||||
#define SR2 1
|
||||
#define MSK1 0xfdbffbffU
|
||||
#define MSK2 0xbff7ff3fU
|
||||
#define MSK3 0xfd77efffU
|
||||
#define MSK4 0xbf9ff3ffU
|
||||
#define PARITY1 0x00000001U
|
||||
#define PARITY2 0x00000000U
|
||||
#define PARITY3 0x00000000U
|
||||
#define PARITY4 0xe9528d85U
|
||||
|
||||
/* PARAMETERS FOR ALTIVEC */
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
#define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
#define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
#define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
#define ALTI_MSK64 \
|
||||
(vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
#define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6)
|
||||
#define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6)
|
||||
#define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14)
|
||||
#define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
#define ALTI_SL1 {SL1, SL1, SL1, SL1}
|
||||
#define ALTI_SR1 {SR1, SR1, SR1, SR1}
|
||||
#define ALTI_MSK {MSK1, MSK2, MSK3, MSK4}
|
||||
#define ALTI_MSK64 {MSK2, MSK1, MSK4, MSK3}
|
||||
#define ALTI_SL2_PERM {25,25,25,25,3,25,25,25,7,0,1,2,11,4,5,6}
|
||||
#define ALTI_SL2_PERM64 {7,25,25,25,25,25,25,25,15,0,1,2,3,4,5,6}
|
||||
#define ALTI_SR2_PERM {7,0,1,2,11,4,5,6,15,8,9,10,17,12,13,14}
|
||||
#define ALTI_SR2_PERM64 {15,0,1,2,3,4,5,6,17,8,9,10,11,12,13,14}
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-86243:366-6-7-19-1:fdbffbff-bff7ff3f-fd77efff-bf9ff3ff"
|
||||
#if defined(__APPLE__) /* For OSX */
|
||||
# define ALTI_SL1 (vector unsigned int)(SL1, SL1, SL1, SL1)
|
||||
# define ALTI_SR1 (vector unsigned int)(SR1, SR1, SR1, SR1)
|
||||
# define ALTI_MSK (vector unsigned int)(MSK1, MSK2, MSK3, MSK4)
|
||||
# define ALTI_MSK64 (vector unsigned int)(MSK2, MSK1, MSK4, MSK3)
|
||||
# define ALTI_SL2_PERM \
|
||||
(vector unsigned char)(25, 25, 25, 25, 3, 25, 25, 25, 7, 0, 1, \
|
||||
2, 11, 4, 5, 6)
|
||||
# define ALTI_SL2_PERM64 \
|
||||
(vector unsigned char)(7, 25, 25, 25, 25, 25, 25, 25, 15, 0, \
|
||||
1, 2, 3, 4, 5, 6)
|
||||
# define ALTI_SR2_PERM \
|
||||
(vector unsigned char)(7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, \
|
||||
17, 12, 13, 14)
|
||||
# define ALTI_SR2_PERM64 \
|
||||
(vector unsigned char)(15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, \
|
||||
11, 12, 13, 14)
|
||||
#else /* For OTHER OSs(Linux?) */
|
||||
# define ALTI_SL1 \
|
||||
{ SL1, SL1, SL1, SL1 }
|
||||
# define ALTI_SR1 \
|
||||
{ SR1, SR1, SR1, SR1 }
|
||||
# define ALTI_MSK \
|
||||
{ MSK1, MSK2, MSK3, MSK4 }
|
||||
# define ALTI_MSK64 \
|
||||
{ MSK2, MSK1, MSK4, MSK3 }
|
||||
# define ALTI_SL2_PERM \
|
||||
{ 25, 25, 25, 25, 3, 25, 25, 25, 7, 0, 1, 2, 11, 4, 5, 6 }
|
||||
# define ALTI_SL2_PERM64 \
|
||||
{ 7, 25, 25, 25, 25, 25, 25, 25, 15, 0, 1, 2, 3, 4, 5, 6 }
|
||||
# define ALTI_SR2_PERM \
|
||||
{ 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 }
|
||||
# define ALTI_SR2_PERM64 \
|
||||
{ 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 }
|
||||
#endif /* For OSX */
|
||||
#define IDSTR "SFMT-86243:366-6-7-19-1:fdbffbff-bff7ff3f-fd77efff-bf9ff3ff"
|
||||
|
||||
#endif /* SFMT_PARAMS86243_H */
|
||||
|
|
|
|||
|
|
@ -60,48 +60,49 @@
|
|||
* @param mask 128-bit mask
|
||||
* @return output
|
||||
*/
|
||||
JEMALLOC_ALWAYS_INLINE __m128i mm_recursion(__m128i *a, __m128i *b,
|
||||
__m128i c, __m128i d, __m128i mask) {
|
||||
__m128i v, x, y, z;
|
||||
JEMALLOC_ALWAYS_INLINE __m128i
|
||||
mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d, __m128i mask) {
|
||||
__m128i v, x, y, z;
|
||||
|
||||
x = _mm_load_si128(a);
|
||||
y = _mm_srli_epi32(*b, SR1);
|
||||
z = _mm_srli_si128(c, SR2);
|
||||
v = _mm_slli_epi32(d, SL1);
|
||||
z = _mm_xor_si128(z, x);
|
||||
z = _mm_xor_si128(z, v);
|
||||
x = _mm_slli_si128(x, SL2);
|
||||
y = _mm_and_si128(y, mask);
|
||||
z = _mm_xor_si128(z, x);
|
||||
z = _mm_xor_si128(z, y);
|
||||
return z;
|
||||
x = _mm_load_si128(a);
|
||||
y = _mm_srli_epi32(*b, SR1);
|
||||
z = _mm_srli_si128(c, SR2);
|
||||
v = _mm_slli_epi32(d, SL1);
|
||||
z = _mm_xor_si128(z, x);
|
||||
z = _mm_xor_si128(z, v);
|
||||
x = _mm_slli_si128(x, SL2);
|
||||
y = _mm_and_si128(y, mask);
|
||||
z = _mm_xor_si128(z, x);
|
||||
z = _mm_xor_si128(z, y);
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function fills the internal state array with pseudorandom
|
||||
* integers.
|
||||
*/
|
||||
static inline void gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
__m128i r, r1, r2, mask;
|
||||
mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
|
||||
static inline void
|
||||
gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
__m128i r, r1, r2, mask;
|
||||
mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
|
||||
|
||||
r1 = _mm_load_si128(&ctx->sfmt[N - 2].si);
|
||||
r2 = _mm_load_si128(&ctx->sfmt[N - 1].si);
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = mm_recursion(&ctx->sfmt[i].si, &ctx->sfmt[i + POS1].si, r1, r2,
|
||||
mask);
|
||||
_mm_store_si128(&ctx->sfmt[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = mm_recursion(&ctx->sfmt[i].si, &ctx->sfmt[i + POS1 - N].si, r1, r2,
|
||||
mask);
|
||||
_mm_store_si128(&ctx->sfmt[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
r1 = _mm_load_si128(&ctx->sfmt[N - 2].si);
|
||||
r2 = _mm_load_si128(&ctx->sfmt[N - 1].si);
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = mm_recursion(
|
||||
&ctx->sfmt[i].si, &ctx->sfmt[i + POS1].si, r1, r2, mask);
|
||||
_mm_store_si128(&ctx->sfmt[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = mm_recursion(&ctx->sfmt[i].si, &ctx->sfmt[i + POS1 - N].si,
|
||||
r1, r2, mask);
|
||||
_mm_store_si128(&ctx->sfmt[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -111,47 +112,48 @@ static inline void gen_rand_all(sfmt_t *ctx) {
|
|||
* @param array an 128-bit array to be filled by pseudorandom numbers.
|
||||
* @param size number of 128-bit pesudorandom numbers to be generated.
|
||||
*/
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
__m128i r, r1, r2, mask;
|
||||
mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
|
||||
static inline void
|
||||
gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
__m128i r, r1, r2, mask;
|
||||
mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
|
||||
|
||||
r1 = _mm_load_si128(&ctx->sfmt[N - 2].si);
|
||||
r2 = _mm_load_si128(&ctx->sfmt[N - 1].si);
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = mm_recursion(&ctx->sfmt[i].si, &ctx->sfmt[i + POS1].si, r1, r2,
|
||||
mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = mm_recursion(&ctx->sfmt[i].si, &array[i + POS1 - N].si, r1, r2,
|
||||
mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
/* main loop */
|
||||
for (; i < size - N; i++) {
|
||||
r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2,
|
||||
mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
r = _mm_load_si128(&array[j + size - N].si);
|
||||
_mm_store_si128(&ctx->sfmt[j].si, r);
|
||||
}
|
||||
for (; i < size; i++) {
|
||||
r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2,
|
||||
mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
_mm_store_si128(&ctx->sfmt[j++].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
r1 = _mm_load_si128(&ctx->sfmt[N - 2].si);
|
||||
r2 = _mm_load_si128(&ctx->sfmt[N - 1].si);
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
r = mm_recursion(
|
||||
&ctx->sfmt[i].si, &ctx->sfmt[i + POS1].si, r1, r2, mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
r = mm_recursion(
|
||||
&ctx->sfmt[i].si, &array[i + POS1 - N].si, r1, r2, mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
/* main loop */
|
||||
for (; i < size - N; i++) {
|
||||
r = mm_recursion(
|
||||
&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
r = _mm_load_si128(&array[j + size - N].si);
|
||||
_mm_store_si128(&ctx->sfmt[j].si, r);
|
||||
}
|
||||
for (; i < size; i++) {
|
||||
r = mm_recursion(
|
||||
&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
|
||||
_mm_store_si128(&array[i].si, r);
|
||||
_mm_store_si128(&ctx->sfmt[j++].si, r);
|
||||
r1 = r2;
|
||||
r2 = r;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -68,79 +68,89 @@
|
|||
|
||||
typedef struct sfmt_s sfmt_t;
|
||||
|
||||
uint32_t gen_rand32(sfmt_t *ctx);
|
||||
uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit);
|
||||
uint64_t gen_rand64(sfmt_t *ctx);
|
||||
uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit);
|
||||
void fill_array32(sfmt_t *ctx, uint32_t *array, int size);
|
||||
void fill_array64(sfmt_t *ctx, uint64_t *array, int size);
|
||||
sfmt_t *init_gen_rand(uint32_t seed);
|
||||
sfmt_t *init_by_array(uint32_t *init_key, int key_length);
|
||||
void fini_gen_rand(sfmt_t *ctx);
|
||||
uint32_t gen_rand32(sfmt_t *ctx);
|
||||
uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit);
|
||||
uint64_t gen_rand64(sfmt_t *ctx);
|
||||
uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit);
|
||||
void fill_array32(sfmt_t *ctx, uint32_t *array, int size);
|
||||
void fill_array64(sfmt_t *ctx, uint64_t *array, int size);
|
||||
sfmt_t *init_gen_rand(uint32_t seed);
|
||||
sfmt_t *init_by_array(uint32_t *init_key, int key_length);
|
||||
void fini_gen_rand(sfmt_t *ctx);
|
||||
const char *get_idstring(void);
|
||||
int get_min_array_size32(void);
|
||||
int get_min_array_size64(void);
|
||||
int get_min_array_size32(void);
|
||||
int get_min_array_size64(void);
|
||||
|
||||
/* These real versions are due to Isaku Wada */
|
||||
/** generates a random number on [0,1]-real-interval */
|
||||
static inline double to_real1(uint32_t v) {
|
||||
return v * (1.0/4294967295.0);
|
||||
/* divided by 2^32-1 */
|
||||
static inline double
|
||||
to_real1(uint32_t v) {
|
||||
return v * (1.0 / 4294967295.0);
|
||||
/* divided by 2^32-1 */
|
||||
}
|
||||
|
||||
/** generates a random number on [0,1]-real-interval */
|
||||
static inline double genrand_real1(sfmt_t *ctx) {
|
||||
return to_real1(gen_rand32(ctx));
|
||||
static inline double
|
||||
genrand_real1(sfmt_t *ctx) {
|
||||
return to_real1(gen_rand32(ctx));
|
||||
}
|
||||
|
||||
/** generates a random number on [0,1)-real-interval */
|
||||
static inline double to_real2(uint32_t v) {
|
||||
return v * (1.0/4294967296.0);
|
||||
/* divided by 2^32 */
|
||||
static inline double
|
||||
to_real2(uint32_t v) {
|
||||
return v * (1.0 / 4294967296.0);
|
||||
/* divided by 2^32 */
|
||||
}
|
||||
|
||||
/** generates a random number on [0,1)-real-interval */
|
||||
static inline double genrand_real2(sfmt_t *ctx) {
|
||||
return to_real2(gen_rand32(ctx));
|
||||
static inline double
|
||||
genrand_real2(sfmt_t *ctx) {
|
||||
return to_real2(gen_rand32(ctx));
|
||||
}
|
||||
|
||||
/** generates a random number on (0,1)-real-interval */
|
||||
static inline double to_real3(uint32_t v) {
|
||||
return (((double)v) + 0.5)*(1.0/4294967296.0);
|
||||
/* divided by 2^32 */
|
||||
static inline double
|
||||
to_real3(uint32_t v) {
|
||||
return (((double)v) + 0.5) * (1.0 / 4294967296.0);
|
||||
/* divided by 2^32 */
|
||||
}
|
||||
|
||||
/** generates a random number on (0,1)-real-interval */
|
||||
static inline double genrand_real3(sfmt_t *ctx) {
|
||||
return to_real3(gen_rand32(ctx));
|
||||
static inline double
|
||||
genrand_real3(sfmt_t *ctx) {
|
||||
return to_real3(gen_rand32(ctx));
|
||||
}
|
||||
/** These real versions are due to Isaku Wada */
|
||||
|
||||
/** generates a random number on [0,1) with 53-bit resolution*/
|
||||
static inline double to_res53(uint64_t v) {
|
||||
return v * (1.0/18446744073709551616.0L);
|
||||
static inline double
|
||||
to_res53(uint64_t v) {
|
||||
return v * (1.0 / 18446744073709551616.0L);
|
||||
}
|
||||
|
||||
/** generates a random number on [0,1) with 53-bit resolution from two
|
||||
* 32 bit integers */
|
||||
static inline double to_res53_mix(uint32_t x, uint32_t y) {
|
||||
return to_res53(x | ((uint64_t)y << 32));
|
||||
static inline double
|
||||
to_res53_mix(uint32_t x, uint32_t y) {
|
||||
return to_res53(x | ((uint64_t)y << 32));
|
||||
}
|
||||
|
||||
/** generates a random number on [0,1) with 53-bit resolution
|
||||
*/
|
||||
static inline double genrand_res53(sfmt_t *ctx) {
|
||||
return to_res53(gen_rand64(ctx));
|
||||
static inline double
|
||||
genrand_res53(sfmt_t *ctx) {
|
||||
return to_res53(gen_rand64(ctx));
|
||||
}
|
||||
|
||||
/** generates a random number on [0,1) with 53-bit resolution
|
||||
using 32bit integer.
|
||||
*/
|
||||
static inline double genrand_res53_mix(sfmt_t *ctx) {
|
||||
uint32_t x, y;
|
||||
static inline double
|
||||
genrand_res53_mix(sfmt_t *ctx) {
|
||||
uint32_t x, y;
|
||||
|
||||
x = gen_rand32(ctx);
|
||||
y = gen_rand32(ctx);
|
||||
return to_res53_mix(x, y);
|
||||
x = gen_rand32(ctx);
|
||||
y = gen_rand32(ctx);
|
||||
return to_res53_mix(x, y);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
static inline unsigned
|
||||
do_arena_create(ssize_t dirty_decay_ms, ssize_t muzzy_decay_ms) {
|
||||
unsigned arena_ind;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl() failure");
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
|
||||
expect_d_eq(mallctlnametomib("arena.0.dirty_decay_ms", mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib() failure");
|
||||
expect_d_eq(mallctlnametomib("arena.0.dirty_decay_ms", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
expect_d_eq(mallctlbymib(mib, miblen, NULL, NULL,
|
||||
(void *)&dirty_decay_ms, sizeof(dirty_decay_ms)), 0,
|
||||
"Unexpected mallctlbymib() failure");
|
||||
(void *)&dirty_decay_ms, sizeof(dirty_decay_ms)),
|
||||
0, "Unexpected mallctlbymib() failure");
|
||||
|
||||
expect_d_eq(mallctlnametomib("arena.0.muzzy_decay_ms", mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib() failure");
|
||||
expect_d_eq(mallctlnametomib("arena.0.muzzy_decay_ms", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
expect_d_eq(mallctlbymib(mib, miblen, NULL, NULL,
|
||||
(void *)&muzzy_decay_ms, sizeof(muzzy_decay_ms)), 0,
|
||||
"Unexpected mallctlbymib() failure");
|
||||
(void *)&muzzy_decay_ms, sizeof(muzzy_decay_ms)),
|
||||
0, "Unexpected mallctlbymib() failure");
|
||||
|
||||
return arena_ind;
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ do_arena_destroy(unsigned arena_ind) {
|
|||
mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
|
||||
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.destroy", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
|
|
@ -51,7 +51,7 @@ do_epoch(void) {
|
|||
static inline void
|
||||
do_purge(unsigned arena_ind) {
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.purge", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
|
|
@ -62,7 +62,7 @@ do_purge(unsigned arena_ind) {
|
|||
static inline void
|
||||
do_decay(unsigned arena_ind) {
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.decay", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
|
|
@ -73,12 +73,12 @@ do_decay(unsigned arena_ind) {
|
|||
static inline uint64_t
|
||||
get_arena_npurge_impl(const char *mibname, unsigned arena_ind) {
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(mibname, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[2] = (size_t)arena_ind;
|
||||
uint64_t npurge = 0;
|
||||
size_t sz = sizeof(npurge);
|
||||
size_t sz = sizeof(npurge);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&npurge, &sz, NULL, 0),
|
||||
config_stats ? 0 : ENOENT, "Unexpected mallctlbymib() failure");
|
||||
return npurge;
|
||||
|
|
@ -105,15 +105,15 @@ get_arena_muzzy_npurge(unsigned arena_ind) {
|
|||
static inline uint64_t
|
||||
get_arena_npurge(unsigned arena_ind) {
|
||||
do_epoch();
|
||||
return get_arena_npurge_impl("stats.arenas.0.dirty_npurge", arena_ind) +
|
||||
get_arena_npurge_impl("stats.arenas.0.muzzy_npurge", arena_ind);
|
||||
return get_arena_npurge_impl("stats.arenas.0.dirty_npurge", arena_ind)
|
||||
+ get_arena_npurge_impl("stats.arenas.0.muzzy_npurge", arena_ind);
|
||||
}
|
||||
|
||||
static inline size_t
|
||||
get_arena_pdirty(unsigned arena_ind) {
|
||||
do_epoch();
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("stats.arenas.0.pdirty", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[2] = (size_t)arena_ind;
|
||||
|
|
@ -128,7 +128,7 @@ static inline size_t
|
|||
get_arena_pmuzzy(unsigned arena_ind) {
|
||||
do_epoch();
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib)/sizeof(size_t);
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("stats.arenas.0.pmuzzy", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[2] = (size_t)arena_ind;
|
||||
|
|
@ -148,8 +148,7 @@ do_mallocx(size_t size, int flags) {
|
|||
|
||||
static inline void
|
||||
generate_dirty(unsigned arena_ind, size_t size) {
|
||||
int flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
int flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
void *p = do_mallocx(size, flags);
|
||||
dallocx(p, flags);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
static inline void
|
||||
time_func(timedelta_t *timer, uint64_t nwarmup, uint64_t niter,
|
||||
void (*func)(void)) {
|
||||
time_func(
|
||||
timedelta_t *timer, uint64_t nwarmup, uint64_t niter, void (*func)(void)) {
|
||||
uint64_t i;
|
||||
|
||||
for (i = 0; i < nwarmup; i++) {
|
||||
|
|
@ -23,16 +23,16 @@ fmt_nsecs(uint64_t usec, uint64_t iters, char *buf) {
|
|||
uint64_t nsecs_per_iter1000 = nsec1000 / iters;
|
||||
uint64_t intpart = nsecs_per_iter1000 / 1000;
|
||||
uint64_t fracpart = nsecs_per_iter1000 % 1000;
|
||||
malloc_snprintf(buf, FMT_NSECS_BUF_SIZE, "%" FMTu64 ".%03" FMTu64, intpart,
|
||||
fracpart);
|
||||
malloc_snprintf(buf, FMT_NSECS_BUF_SIZE, "%" FMTu64 ".%03" FMTu64,
|
||||
intpart, fracpart);
|
||||
}
|
||||
|
||||
static inline void
|
||||
compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
|
||||
void (*func_a), const char *name_b, void (*func_b)) {
|
||||
void(*func_a), const char *name_b, void(*func_b)) {
|
||||
timedelta_t timer_a, timer_b;
|
||||
char ratio_buf[6];
|
||||
void *p;
|
||||
char ratio_buf[6];
|
||||
void *p;
|
||||
|
||||
p = mallocx(1, 0);
|
||||
if (p == NULL) {
|
||||
|
|
@ -44,16 +44,18 @@ compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
|
|||
time_func(&timer_b, nwarmup, niter, (void (*)(void))func_b);
|
||||
|
||||
uint64_t usec_a = timer_usec(&timer_a);
|
||||
char buf_a[FMT_NSECS_BUF_SIZE];
|
||||
char buf_a[FMT_NSECS_BUF_SIZE];
|
||||
fmt_nsecs(usec_a, niter, buf_a);
|
||||
|
||||
uint64_t usec_b = timer_usec(&timer_b);
|
||||
char buf_b[FMT_NSECS_BUF_SIZE];
|
||||
char buf_b[FMT_NSECS_BUF_SIZE];
|
||||
fmt_nsecs(usec_b, niter, buf_b);
|
||||
|
||||
timer_ratio(&timer_a, &timer_b, ratio_buf, sizeof(ratio_buf));
|
||||
malloc_printf("%" FMTu64 " iterations, %s=%" FMTu64 "us (%s ns/iter), "
|
||||
"%s=%" FMTu64 "us (%s ns/iter), time consumption ratio=%s:1\n",
|
||||
malloc_printf("%" FMTu64 " iterations, %s=%" FMTu64
|
||||
"us (%s ns/iter), "
|
||||
"%s=%" FMTu64
|
||||
"us (%s ns/iter), time consumption ratio=%s:1\n",
|
||||
niter, name_a, usec_a, buf_a, name_b, usec_b, buf_b, ratio_buf);
|
||||
|
||||
dallocx(p, 0);
|
||||
|
|
@ -62,10 +64,10 @@ compare_funcs(uint64_t nwarmup, uint64_t niter, const char *name_a,
|
|||
static inline void *
|
||||
no_opt_ptr(void *ptr) {
|
||||
#ifdef JEMALLOC_HAVE_ASM_VOLATILE
|
||||
asm volatile("" : "+r"(ptr));
|
||||
asm volatile("" : "+r"(ptr));
|
||||
#else
|
||||
void *volatile dup = ptr;
|
||||
ptr = dup;
|
||||
void *volatile dup = ptr;
|
||||
ptr = dup;
|
||||
#endif
|
||||
return ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
static inline bool
|
||||
is_background_thread_enabled(void) {
|
||||
bool enabled;
|
||||
bool enabled;
|
||||
size_t sz = sizeof(bool);
|
||||
int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL,0);
|
||||
int ret = mallctl("background_thread", (void *)&enabled, &sz, NULL, 0);
|
||||
if (ret == ENOENT) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,28 @@
|
|||
/* btalloc() provides a mechanism for allocating via permuted backtraces. */
|
||||
void *btalloc(size_t size, unsigned bits);
|
||||
void *btalloc(size_t size, unsigned bits);
|
||||
|
||||
#define btalloc_n_proto(n) \
|
||||
void *btalloc_##n(size_t size, unsigned bits);
|
||||
btalloc_n_proto(0)
|
||||
btalloc_n_proto(1)
|
||||
#define btalloc_n_proto(n) void *btalloc_##n(size_t size, unsigned bits);
|
||||
btalloc_n_proto(0) btalloc_n_proto(1)
|
||||
|
||||
#define btalloc_n_gen(n) \
|
||||
void * \
|
||||
btalloc_##n(size_t size, unsigned bits) { \
|
||||
void *p; \
|
||||
\
|
||||
if (bits == 0) { \
|
||||
p = mallocx(size, 0); \
|
||||
} else { \
|
||||
switch (bits & 0x1U) { \
|
||||
case 0: \
|
||||
p = (btalloc_0(size, bits >> 1)); \
|
||||
break; \
|
||||
case 1: \
|
||||
p = (btalloc_1(size, bits >> 1)); \
|
||||
break; \
|
||||
default: not_reached(); \
|
||||
} \
|
||||
} \
|
||||
/* Intentionally sabotage tail call optimization. */ \
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() failure"); \
|
||||
return p; \
|
||||
}
|
||||
#define btalloc_n_gen(n) \
|
||||
void *btalloc_##n(size_t size, unsigned bits) { \
|
||||
void *p; \
|
||||
\
|
||||
if (bits == 0) { \
|
||||
p = mallocx(size, 0); \
|
||||
} else { \
|
||||
switch (bits & 0x1U) { \
|
||||
case 0: \
|
||||
p = (btalloc_0(size, bits >> 1)); \
|
||||
break; \
|
||||
case 1: \
|
||||
p = (btalloc_1(size, bits >> 1)); \
|
||||
break; \
|
||||
default: \
|
||||
not_reached(); \
|
||||
} \
|
||||
} \
|
||||
/* Intentionally sabotage tail call optimization. */ \
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() failure"); \
|
||||
return p; \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,40 +3,33 @@
|
|||
* passthrough.
|
||||
*/
|
||||
|
||||
static void *extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr,
|
||||
static void *extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr,
|
||||
size_t size, size_t alignment, bool *zero, bool *commit,
|
||||
unsigned arena_ind);
|
||||
static bool extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, bool committed, unsigned arena_ind);
|
||||
static void extent_destroy_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, bool committed, unsigned arena_ind);
|
||||
static bool extent_commit_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_purge_forced_hook(extent_hooks_t *extent_hooks,
|
||||
void *addr, size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_split_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t size_a, size_t size_b, bool committed,
|
||||
unsigned arena_ind);
|
||||
static bool extent_merge_hook(extent_hooks_t *extent_hooks, void *addr_a,
|
||||
size_t size_a, void *addr_b, size_t size_b, bool committed,
|
||||
unsigned arena_ind);
|
||||
static bool extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, bool committed, unsigned arena_ind);
|
||||
static void extent_destroy_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, bool committed, unsigned arena_ind);
|
||||
static bool extent_commit_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_purge_forced_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t offset, size_t length, unsigned arena_ind);
|
||||
static bool extent_split_hook(extent_hooks_t *extent_hooks, void *addr,
|
||||
size_t size, size_t size_a, size_t size_b, bool committed,
|
||||
unsigned arena_ind);
|
||||
static bool extent_merge_hook(extent_hooks_t *extent_hooks, void *addr_a,
|
||||
size_t size_a, void *addr_b, size_t size_b, bool committed,
|
||||
unsigned arena_ind);
|
||||
|
||||
static extent_hooks_t *default_hooks;
|
||||
static extent_hooks_t hooks = {
|
||||
extent_alloc_hook,
|
||||
extent_dalloc_hook,
|
||||
extent_destroy_hook,
|
||||
extent_commit_hook,
|
||||
extent_decommit_hook,
|
||||
extent_purge_lazy_hook,
|
||||
extent_purge_forced_hook,
|
||||
extent_split_hook,
|
||||
extent_merge_hook
|
||||
};
|
||||
static extent_hooks_t hooks = {extent_alloc_hook, extent_dalloc_hook,
|
||||
extent_destroy_hook, extent_commit_hook, extent_decommit_hook,
|
||||
extent_purge_lazy_hook, extent_purge_forced_hook, extent_split_hook,
|
||||
extent_merge_hook};
|
||||
|
||||
/* Control whether hook functions pass calls through to default hooks. */
|
||||
static bool try_alloc = true;
|
||||
|
|
@ -72,9 +65,9 @@ static bool did_split;
|
|||
static bool did_merge;
|
||||
|
||||
#if 0
|
||||
# define TRACE_HOOK(fmt, ...) malloc_printf(fmt, __VA_ARGS__)
|
||||
# define TRACE_HOOK(fmt, ...) malloc_printf(fmt, __VA_ARGS__)
|
||||
#else
|
||||
# define TRACE_HOOK(fmt, ...)
|
||||
# define TRACE_HOOK(fmt, ...)
|
||||
#endif
|
||||
|
||||
static void *
|
||||
|
|
@ -82,20 +75,21 @@ extent_alloc_hook(extent_hooks_t *extent_hooks, void *new_addr, size_t size,
|
|||
size_t alignment, bool *zero, bool *commit, unsigned arena_ind) {
|
||||
void *ret;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, new_addr=%p, size=%zu, alignment=%zu, "
|
||||
"*zero=%s, *commit=%s, arena_ind=%u)\n", __func__, extent_hooks,
|
||||
new_addr, size, alignment, *zero ? "true" : "false", *commit ?
|
||||
"true" : "false", arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, new_addr=%p, size=%zu, alignment=%zu, "
|
||||
"*zero=%s, *commit=%s, arena_ind=%u)\n",
|
||||
__func__, extent_hooks, new_addr, size, alignment,
|
||||
*zero ? "true" : "false", *commit ? "true" : "false", arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->alloc, extent_alloc_hook,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->alloc, extent_alloc_hook, "Wrong hook function");
|
||||
called_alloc = true;
|
||||
if (!try_alloc) {
|
||||
return NULL;
|
||||
}
|
||||
ret = default_hooks->alloc(default_hooks, new_addr, size, alignment,
|
||||
zero, commit, 0);
|
||||
ret = default_hooks->alloc(
|
||||
default_hooks, new_addr, size, alignment, zero, commit, 0);
|
||||
did_alloc = (ret != NULL);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -105,13 +99,15 @@ extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
bool committed, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
|
||||
"arena_ind=%u)\n", __func__, extent_hooks, addr, size, committed ?
|
||||
"true" : "false", arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
|
||||
"arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, committed ? "true" : "false",
|
||||
arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->dalloc, extent_dalloc_hook,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->dalloc, extent_dalloc_hook, "Wrong hook function");
|
||||
called_dalloc = true;
|
||||
if (!try_dalloc) {
|
||||
return true;
|
||||
|
|
@ -124,13 +120,15 @@ extent_dalloc_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
static void
|
||||
extent_destroy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
||||
bool committed, unsigned arena_ind) {
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
|
||||
"arena_ind=%u)\n", __func__, extent_hooks, addr, size, committed ?
|
||||
"true" : "false", arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
|
||||
"arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, committed ? "true" : "false",
|
||||
arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->destroy, extent_destroy_hook,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->destroy, extent_destroy_hook, "Wrong hook function");
|
||||
called_destroy = true;
|
||||
if (!try_destroy) {
|
||||
return;
|
||||
|
|
@ -144,19 +142,20 @@ extent_commit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
size_t offset, size_t length, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu, arena_ind=%u)\n", __func__, extent_hooks, addr, size,
|
||||
offset, length, arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu, arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, offset, length, arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->commit, extent_commit_hook,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->commit, extent_commit_hook, "Wrong hook function");
|
||||
called_commit = true;
|
||||
if (!try_commit) {
|
||||
return true;
|
||||
}
|
||||
err = default_hooks->commit(default_hooks, addr, size, offset, length,
|
||||
0);
|
||||
err = default_hooks->commit(
|
||||
default_hooks, addr, size, offset, length, 0);
|
||||
did_commit = !err;
|
||||
return err;
|
||||
}
|
||||
|
|
@ -166,9 +165,10 @@ extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
size_t offset, size_t length, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu, arena_ind=%u)\n", __func__, extent_hooks, addr, size,
|
||||
offset, length, arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu, arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, offset, length, arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->decommit, extent_decommit_hook,
|
||||
|
|
@ -177,8 +177,8 @@ extent_decommit_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
if (!try_decommit) {
|
||||
return true;
|
||||
}
|
||||
err = default_hooks->decommit(default_hooks, addr, size, offset, length,
|
||||
0);
|
||||
err = default_hooks->decommit(
|
||||
default_hooks, addr, size, offset, length, 0);
|
||||
did_decommit = !err;
|
||||
return err;
|
||||
}
|
||||
|
|
@ -188,9 +188,10 @@ extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
size_t offset, size_t length, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu arena_ind=%u)\n", __func__, extent_hooks, addr, size,
|
||||
offset, length, arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, offset, length, arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->purge_lazy, extent_purge_lazy_hook,
|
||||
|
|
@ -199,9 +200,9 @@ extent_purge_lazy_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
if (!try_purge_lazy) {
|
||||
return true;
|
||||
}
|
||||
err = default_hooks->purge_lazy == NULL ||
|
||||
default_hooks->purge_lazy(default_hooks, addr, size, offset, length,
|
||||
0);
|
||||
err = default_hooks->purge_lazy == NULL
|
||||
|| default_hooks->purge_lazy(
|
||||
default_hooks, addr, size, offset, length, 0);
|
||||
did_purge_lazy = !err;
|
||||
return err;
|
||||
}
|
||||
|
|
@ -211,9 +212,10 @@ extent_purge_forced_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
size_t offset, size_t length, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu arena_ind=%u)\n", __func__, extent_hooks, addr, size,
|
||||
offset, length, arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, offset=%zu, "
|
||||
"length=%zu arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, offset, length, arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->purge_forced, extent_purge_forced_hook,
|
||||
|
|
@ -222,9 +224,9 @@ extent_purge_forced_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
if (!try_purge_forced) {
|
||||
return true;
|
||||
}
|
||||
err = default_hooks->purge_forced == NULL ||
|
||||
default_hooks->purge_forced(default_hooks, addr, size, offset,
|
||||
length, 0);
|
||||
err = default_hooks->purge_forced == NULL
|
||||
|| default_hooks->purge_forced(
|
||||
default_hooks, addr, size, offset, length, 0);
|
||||
did_purge_forced = !err;
|
||||
return err;
|
||||
}
|
||||
|
|
@ -234,21 +236,22 @@ extent_split_hook(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
size_t size_a, size_t size_b, bool committed, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, size_a=%zu, "
|
||||
"size_b=%zu, committed=%s, arena_ind=%u)\n", __func__, extent_hooks,
|
||||
addr, size, size_a, size_b, committed ? "true" : "false",
|
||||
arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, size_a=%zu, "
|
||||
"size_b=%zu, committed=%s, arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, size_a, size_b,
|
||||
committed ? "true" : "false", arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->split, extent_split_hook,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->split, extent_split_hook, "Wrong hook function");
|
||||
called_split = true;
|
||||
if (!try_split) {
|
||||
return true;
|
||||
}
|
||||
err = (default_hooks->split == NULL ||
|
||||
default_hooks->split(default_hooks, addr, size, size_a, size_b,
|
||||
committed, 0));
|
||||
err = (default_hooks->split == NULL
|
||||
|| default_hooks->split(
|
||||
default_hooks, addr, size, size_a, size_b, committed, 0));
|
||||
did_split = !err;
|
||||
return err;
|
||||
}
|
||||
|
|
@ -258,23 +261,24 @@ extent_merge_hook(extent_hooks_t *extent_hooks, void *addr_a, size_t size_a,
|
|||
void *addr_b, size_t size_b, bool committed, unsigned arena_ind) {
|
||||
bool err;
|
||||
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr_a=%p, size_a=%zu, addr_b=%p "
|
||||
"size_b=%zu, committed=%s, arena_ind=%u)\n", __func__, extent_hooks,
|
||||
addr_a, size_a, addr_b, size_b, committed ? "true" : "false",
|
||||
arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr_a=%p, size_a=%zu, addr_b=%p "
|
||||
"size_b=%zu, committed=%s, arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr_a, size_a, addr_b, size_b,
|
||||
committed ? "true" : "false", arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->merge, extent_merge_hook,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->merge, extent_merge_hook, "Wrong hook function");
|
||||
expect_ptr_eq((void *)((uintptr_t)addr_a + size_a), addr_b,
|
||||
"Extents not mergeable");
|
||||
called_merge = true;
|
||||
if (!try_merge) {
|
||||
return true;
|
||||
}
|
||||
err = (default_hooks->merge == NULL ||
|
||||
default_hooks->merge(default_hooks, addr_a, size_a, addr_b, size_b,
|
||||
committed, 0));
|
||||
err = (default_hooks->merge == NULL
|
||||
|| default_hooks->merge(
|
||||
default_hooks, addr_a, size_a, addr_b, size_b, committed, 0));
|
||||
did_merge = !err;
|
||||
return err;
|
||||
}
|
||||
|
|
@ -285,5 +289,6 @@ extent_hooks_prep(void) {
|
|||
|
||||
sz = sizeof(default_hooks);
|
||||
expect_d_eq(mallctl("arena.0.extent_hooks", (void *)&default_hooks, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctl() error");
|
||||
NULL, 0),
|
||||
0, "Unexpected mallctl() error");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <sys/wait.h>
|
||||
# include <sys/wait.h>
|
||||
|
||||
static inline void
|
||||
fork_wait_for_child_exit(int pid) {
|
||||
|
|
@ -13,8 +13,10 @@ fork_wait_for_child_exit(int pid) {
|
|||
test_fail("Unexpected waitpid() failure.");
|
||||
}
|
||||
if (WIFSIGNALED(status)) {
|
||||
test_fail("Unexpected child termination due to "
|
||||
"signal %d", WTERMSIG(status));
|
||||
test_fail(
|
||||
"Unexpected child termination due to "
|
||||
"signal %d",
|
||||
WTERMSIG(status));
|
||||
break;
|
||||
}
|
||||
if (WIFEXITED(status)) {
|
||||
|
|
|
|||
|
|
@ -27,9 +27,12 @@ ln_gamma(double x) {
|
|||
|
||||
z = 1.0 / (x * x);
|
||||
|
||||
return f + (x-0.5) * log(x) - x + 0.918938533204673 +
|
||||
(((-0.000595238095238 * z + 0.000793650793651) * z -
|
||||
0.002777777777778) * z + 0.083333333333333) / x;
|
||||
return f + (x - 0.5) * log(x) - x + 0.918938533204673
|
||||
+ (((-0.000595238095238 * z + 0.000793650793651) * z
|
||||
- 0.002777777777778)
|
||||
* z
|
||||
+ 0.083333333333333)
|
||||
/ x;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -43,8 +46,8 @@ ln_gamma(double x) {
|
|||
*/
|
||||
static inline double
|
||||
i_gamma(double x, double p, double ln_gamma_p) {
|
||||
double acu, factor, oflo, gin, term, rn, a, b, an, dif;
|
||||
double pn[6];
|
||||
double acu, factor, oflo, gin, term, rn, a, b, an, dif;
|
||||
double pn[6];
|
||||
unsigned i;
|
||||
|
||||
assert(p > 0.0);
|
||||
|
|
@ -91,7 +94,7 @@ i_gamma(double x, double p, double ln_gamma_p) {
|
|||
term += 1.0;
|
||||
an = a * term;
|
||||
for (i = 0; i < 2; i++) {
|
||||
pn[i+4] = b * pn[i+2] - an * pn[i];
|
||||
pn[i + 4] = b * pn[i + 2] - an * pn[i];
|
||||
}
|
||||
if (pn[5] != 0.0) {
|
||||
rn = pn[4] / pn[5];
|
||||
|
|
@ -103,7 +106,7 @@ i_gamma(double x, double p, double ln_gamma_p) {
|
|||
gin = rn;
|
||||
}
|
||||
for (i = 0; i < 4; i++) {
|
||||
pn[i] = pn[i+2];
|
||||
pn[i] = pn[i + 2];
|
||||
}
|
||||
|
||||
if (fabs(pn[4]) >= oflo) {
|
||||
|
|
@ -135,16 +138,35 @@ pt_norm(double p) {
|
|||
if (fabs(q) <= 0.425) {
|
||||
/* p close to 1/2. */
|
||||
r = 0.180625 - q * q;
|
||||
return q * (((((((2.5090809287301226727e3 * r +
|
||||
3.3430575583588128105e4) * r + 6.7265770927008700853e4) * r
|
||||
+ 4.5921953931549871457e4) * r + 1.3731693765509461125e4) *
|
||||
r + 1.9715909503065514427e3) * r + 1.3314166789178437745e2)
|
||||
* r + 3.3871328727963666080e0) /
|
||||
(((((((5.2264952788528545610e3 * r +
|
||||
2.8729085735721942674e4) * r + 3.9307895800092710610e4) * r
|
||||
+ 2.1213794301586595867e4) * r + 5.3941960214247511077e3) *
|
||||
r + 6.8718700749205790830e2) * r + 4.2313330701600911252e1)
|
||||
* r + 1.0);
|
||||
return q
|
||||
* (((((((2.5090809287301226727e3 * r
|
||||
+ 3.3430575583588128105e4)
|
||||
* r
|
||||
+ 6.7265770927008700853e4)
|
||||
* r
|
||||
+ 4.5921953931549871457e4)
|
||||
* r
|
||||
+ 1.3731693765509461125e4)
|
||||
* r
|
||||
+ 1.9715909503065514427e3)
|
||||
* r
|
||||
+ 1.3314166789178437745e2)
|
||||
* r
|
||||
+ 3.3871328727963666080e0)
|
||||
/ (((((((5.2264952788528545610e3 * r
|
||||
+ 2.8729085735721942674e4)
|
||||
* r
|
||||
+ 3.9307895800092710610e4)
|
||||
* r
|
||||
+ 2.1213794301586595867e4)
|
||||
* r
|
||||
+ 5.3941960214247511077e3)
|
||||
* r
|
||||
+ 6.8718700749205790830e2)
|
||||
* r
|
||||
+ 4.2313330701600911252e1)
|
||||
* r
|
||||
+ 1.0);
|
||||
} else {
|
||||
if (q < 0.0) {
|
||||
r = p;
|
||||
|
|
@ -157,40 +179,65 @@ pt_norm(double p) {
|
|||
if (r <= 5.0) {
|
||||
/* p neither close to 1/2 nor 0 or 1. */
|
||||
r -= 1.6;
|
||||
ret = ((((((((7.74545014278341407640e-4 * r +
|
||||
2.27238449892691845833e-2) * r +
|
||||
2.41780725177450611770e-1) * r +
|
||||
1.27045825245236838258e0) * r +
|
||||
3.64784832476320460504e0) * r +
|
||||
5.76949722146069140550e0) * r +
|
||||
4.63033784615654529590e0) * r +
|
||||
1.42343711074968357734e0) /
|
||||
(((((((1.05075007164441684324e-9 * r +
|
||||
5.47593808499534494600e-4) * r +
|
||||
1.51986665636164571966e-2)
|
||||
* r + 1.48103976427480074590e-1) * r +
|
||||
6.89767334985100004550e-1) * r +
|
||||
1.67638483018380384940e0) * r +
|
||||
2.05319162663775882187e0) * r + 1.0));
|
||||
ret = ((((((((7.74545014278341407640e-4 * r
|
||||
+ 2.27238449892691845833e-2)
|
||||
* r
|
||||
+ 2.41780725177450611770e-1)
|
||||
* r
|
||||
+ 1.27045825245236838258e0)
|
||||
* r
|
||||
+ 3.64784832476320460504e0)
|
||||
* r
|
||||
+ 5.76949722146069140550e0)
|
||||
* r
|
||||
+ 4.63033784615654529590e0)
|
||||
* r
|
||||
+ 1.42343711074968357734e0)
|
||||
/ (((((((1.05075007164441684324e-9 * r
|
||||
+ 5.47593808499534494600e-4)
|
||||
* r
|
||||
+ 1.51986665636164571966e-2)
|
||||
* r
|
||||
+ 1.48103976427480074590e-1)
|
||||
* r
|
||||
+ 6.89767334985100004550e-1)
|
||||
* r
|
||||
+ 1.67638483018380384940e0)
|
||||
* r
|
||||
+ 2.05319162663775882187e0)
|
||||
* r
|
||||
+ 1.0));
|
||||
} else {
|
||||
/* p near 0 or 1. */
|
||||
r -= 5.0;
|
||||
ret = ((((((((2.01033439929228813265e-7 * r +
|
||||
2.71155556874348757815e-5) * r +
|
||||
1.24266094738807843860e-3) * r +
|
||||
2.65321895265761230930e-2) * r +
|
||||
2.96560571828504891230e-1) * r +
|
||||
1.78482653991729133580e0) * r +
|
||||
5.46378491116411436990e0) * r +
|
||||
6.65790464350110377720e0) /
|
||||
(((((((2.04426310338993978564e-15 * r +
|
||||
1.42151175831644588870e-7) * r +
|
||||
1.84631831751005468180e-5) * r +
|
||||
7.86869131145613259100e-4) * r +
|
||||
1.48753612908506148525e-2) * r +
|
||||
1.36929880922735805310e-1) * r +
|
||||
5.99832206555887937690e-1)
|
||||
* r + 1.0));
|
||||
ret = ((((((((2.01033439929228813265e-7 * r
|
||||
+ 2.71155556874348757815e-5)
|
||||
* r
|
||||
+ 1.24266094738807843860e-3)
|
||||
* r
|
||||
+ 2.65321895265761230930e-2)
|
||||
* r
|
||||
+ 2.96560571828504891230e-1)
|
||||
* r
|
||||
+ 1.78482653991729133580e0)
|
||||
* r
|
||||
+ 5.46378491116411436990e0)
|
||||
* r
|
||||
+ 6.65790464350110377720e0)
|
||||
/ (((((((2.04426310338993978564e-15 * r
|
||||
+ 1.42151175831644588870e-7)
|
||||
* r
|
||||
+ 1.84631831751005468180e-5)
|
||||
* r
|
||||
+ 7.86869131145613259100e-4)
|
||||
* r
|
||||
+ 1.48753612908506148525e-2)
|
||||
* r
|
||||
+ 1.36929880922735805310e-1)
|
||||
* r
|
||||
+ 5.99832206555887937690e-1)
|
||||
* r
|
||||
+ 1.0));
|
||||
}
|
||||
if (q < 0.0) {
|
||||
ret = -ret;
|
||||
|
|
@ -244,8 +291,9 @@ pt_chi2(double p, double df, double ln_gamma_df_2) {
|
|||
ch = df * pow(x * sqrt(p1) + 1.0 - p1, 3.0);
|
||||
/* Starting approximation for p tending to 1. */
|
||||
if (ch > 2.2 * df + 6.0) {
|
||||
ch = -2.0 * (log(1.0 - p) - c * log(0.5 * ch) +
|
||||
ln_gamma_df_2);
|
||||
ch = -2.0
|
||||
* (log(1.0 - p) - c * log(0.5 * ch)
|
||||
+ ln_gamma_df_2);
|
||||
}
|
||||
} else {
|
||||
ch = 0.4;
|
||||
|
|
@ -254,10 +302,13 @@ pt_chi2(double p, double df, double ln_gamma_df_2) {
|
|||
q = ch;
|
||||
p1 = 1.0 + ch * (4.67 + ch);
|
||||
p2 = ch * (6.73 + ch * (6.66 + ch));
|
||||
t = -0.5 + (4.67 + 2.0 * ch) / p1 - (6.73 + ch
|
||||
* (13.32 + 3.0 * ch)) / p2;
|
||||
ch -= (1.0 - exp(a + ln_gamma_df_2 + 0.5 * ch +
|
||||
c * aa) * p2 / p1) / t;
|
||||
t = -0.5 + (4.67 + 2.0 * ch) / p1
|
||||
- (6.73 + ch * (13.32 + 3.0 * ch)) / p2;
|
||||
ch -= (1.0
|
||||
- exp(a + ln_gamma_df_2 + 0.5 * ch
|
||||
+ c * aa)
|
||||
* p2 / p1)
|
||||
/ t;
|
||||
if (fabs(q / ch - 1.0) - 0.01 <= 0.0) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -276,17 +327,36 @@ pt_chi2(double p, double df, double ln_gamma_df_2) {
|
|||
t = p2 * exp(xx * aa + ln_gamma_df_2 + p1 - c * log(ch));
|
||||
b = t / ch;
|
||||
a = 0.5 * t - b * c;
|
||||
s1 = (210.0 + a * (140.0 + a * (105.0 + a * (84.0 + a * (70.0 +
|
||||
60.0 * a))))) / 420.0;
|
||||
s2 = (420.0 + a * (735.0 + a * (966.0 + a * (1141.0 + 1278.0 *
|
||||
a)))) / 2520.0;
|
||||
s1 = (210.0
|
||||
+ a
|
||||
* (140.0
|
||||
+ a
|
||||
* (105.0
|
||||
+ a * (84.0 + a * (70.0 + 60.0 * a)))))
|
||||
/ 420.0;
|
||||
s2 =
|
||||
(420.0
|
||||
+ a * (735.0 + a * (966.0 + a * (1141.0 + 1278.0 * a))))
|
||||
/ 2520.0;
|
||||
s3 = (210.0 + a * (462.0 + a * (707.0 + 932.0 * a))) / 2520.0;
|
||||
s4 = (252.0 + a * (672.0 + 1182.0 * a) + c * (294.0 + a *
|
||||
(889.0 + 1740.0 * a))) / 5040.0;
|
||||
s4 = (252.0 + a * (672.0 + 1182.0 * a)
|
||||
+ c * (294.0 + a * (889.0 + 1740.0 * a)))
|
||||
/ 5040.0;
|
||||
s5 = (84.0 + 264.0 * a + c * (175.0 + 606.0 * a)) / 2520.0;
|
||||
s6 = (120.0 + c * (346.0 + 127.0 * c)) / 5040.0;
|
||||
ch += t * (1.0 + 0.5 * t * s1 - b * c * (s1 - b * (s2 - b * (s3
|
||||
- b * (s4 - b * (s5 - b * s6))))));
|
||||
ch += t
|
||||
* (1.0 + 0.5 * t * s1
|
||||
- b * c
|
||||
* (s1
|
||||
- b
|
||||
* (s2
|
||||
- b
|
||||
* (s3
|
||||
- b
|
||||
* (s4
|
||||
- b
|
||||
* (s5
|
||||
- b * s6))))));
|
||||
if (fabs(q / ch - 1.0) <= e) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,82 +26,74 @@
|
|||
* does not perform any cleanup of messages, since it knows nothing of their
|
||||
* payloads.
|
||||
*/
|
||||
#define mq_msg(a_mq_msg_type) ql_elm(a_mq_msg_type)
|
||||
#define mq_msg(a_mq_msg_type) ql_elm(a_mq_msg_type)
|
||||
|
||||
#define mq_gen(a_attr, a_prefix, a_mq_type, a_mq_msg_type, a_field) \
|
||||
typedef struct { \
|
||||
mtx_t lock; \
|
||||
ql_head(a_mq_msg_type) msgs; \
|
||||
unsigned count; \
|
||||
} a_mq_type; \
|
||||
a_attr bool \
|
||||
a_prefix##init(a_mq_type *mq) { \
|
||||
\
|
||||
if (mtx_init(&mq->lock)) { \
|
||||
return true; \
|
||||
} \
|
||||
ql_new(&mq->msgs); \
|
||||
mq->count = 0; \
|
||||
return false; \
|
||||
} \
|
||||
a_attr void \
|
||||
a_prefix##fini(a_mq_type *mq) { \
|
||||
mtx_fini(&mq->lock); \
|
||||
} \
|
||||
a_attr unsigned \
|
||||
a_prefix##count(a_mq_type *mq) { \
|
||||
unsigned count; \
|
||||
\
|
||||
mtx_lock(&mq->lock); \
|
||||
count = mq->count; \
|
||||
mtx_unlock(&mq->lock); \
|
||||
return count; \
|
||||
} \
|
||||
a_attr a_mq_msg_type * \
|
||||
a_prefix##tryget(a_mq_type *mq) { \
|
||||
a_mq_msg_type *msg; \
|
||||
\
|
||||
mtx_lock(&mq->lock); \
|
||||
msg = ql_first(&mq->msgs); \
|
||||
if (msg != NULL) { \
|
||||
ql_head_remove(&mq->msgs, a_mq_msg_type, a_field); \
|
||||
mq->count--; \
|
||||
} \
|
||||
mtx_unlock(&mq->lock); \
|
||||
return msg; \
|
||||
} \
|
||||
a_attr a_mq_msg_type * \
|
||||
a_prefix##get(a_mq_type *mq) { \
|
||||
a_mq_msg_type *msg; \
|
||||
unsigned ns; \
|
||||
\
|
||||
msg = a_prefix##tryget(mq); \
|
||||
if (msg != NULL) { \
|
||||
return msg; \
|
||||
} \
|
||||
\
|
||||
ns = 1; \
|
||||
while (true) { \
|
||||
sleep_ns(ns); \
|
||||
msg = a_prefix##tryget(mq); \
|
||||
if (msg != NULL) { \
|
||||
return msg; \
|
||||
} \
|
||||
if (ns < 1000*1000*1000) { \
|
||||
/* Double sleep time, up to max 1 second. */ \
|
||||
ns <<= 1; \
|
||||
if (ns > 1000*1000*1000) { \
|
||||
ns = 1000*1000*1000; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
a_attr void \
|
||||
a_prefix##put(a_mq_type *mq, a_mq_msg_type *msg) { \
|
||||
\
|
||||
mtx_lock(&mq->lock); \
|
||||
ql_elm_new(msg, a_field); \
|
||||
ql_tail_insert(&mq->msgs, msg, a_field); \
|
||||
mq->count++; \
|
||||
mtx_unlock(&mq->lock); \
|
||||
}
|
||||
#define mq_gen(a_attr, a_prefix, a_mq_type, a_mq_msg_type, a_field) \
|
||||
typedef struct { \
|
||||
mtx_t lock; \
|
||||
ql_head(a_mq_msg_type) msgs; \
|
||||
unsigned count; \
|
||||
} a_mq_type; \
|
||||
a_attr bool a_prefix##init(a_mq_type *mq) { \
|
||||
if (mtx_init(&mq->lock)) { \
|
||||
return true; \
|
||||
} \
|
||||
ql_new(&mq->msgs); \
|
||||
mq->count = 0; \
|
||||
return false; \
|
||||
} \
|
||||
a_attr void a_prefix##fini(a_mq_type *mq) { \
|
||||
mtx_fini(&mq->lock); \
|
||||
} \
|
||||
a_attr unsigned a_prefix##count(a_mq_type *mq) { \
|
||||
unsigned count; \
|
||||
\
|
||||
mtx_lock(&mq->lock); \
|
||||
count = mq->count; \
|
||||
mtx_unlock(&mq->lock); \
|
||||
return count; \
|
||||
} \
|
||||
a_attr a_mq_msg_type *a_prefix##tryget(a_mq_type *mq) { \
|
||||
a_mq_msg_type *msg; \
|
||||
\
|
||||
mtx_lock(&mq->lock); \
|
||||
msg = ql_first(&mq->msgs); \
|
||||
if (msg != NULL) { \
|
||||
ql_head_remove(&mq->msgs, a_mq_msg_type, a_field); \
|
||||
mq->count--; \
|
||||
} \
|
||||
mtx_unlock(&mq->lock); \
|
||||
return msg; \
|
||||
} \
|
||||
a_attr a_mq_msg_type *a_prefix##get(a_mq_type *mq) { \
|
||||
a_mq_msg_type *msg; \
|
||||
unsigned ns; \
|
||||
\
|
||||
msg = a_prefix##tryget(mq); \
|
||||
if (msg != NULL) { \
|
||||
return msg; \
|
||||
} \
|
||||
\
|
||||
ns = 1; \
|
||||
while (true) { \
|
||||
sleep_ns(ns); \
|
||||
msg = a_prefix##tryget(mq); \
|
||||
if (msg != NULL) { \
|
||||
return msg; \
|
||||
} \
|
||||
if (ns < 1000 * 1000 * 1000) { \
|
||||
/* Double sleep time, up to max 1 second. */ \
|
||||
ns <<= 1; \
|
||||
if (ns > 1000 * 1000 * 1000) { \
|
||||
ns = 1000 * 1000 * 1000; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
a_attr void a_prefix##put(a_mq_type *mq, a_mq_msg_type *msg) { \
|
||||
mtx_lock(&mq->lock); \
|
||||
ql_elm_new(msg, a_field); \
|
||||
ql_tail_insert(&mq->msgs, msg, a_field); \
|
||||
mq->count++; \
|
||||
mtx_unlock(&mq->lock); \
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@
|
|||
|
||||
typedef struct {
|
||||
#ifdef _WIN32
|
||||
CRITICAL_SECTION lock;
|
||||
CRITICAL_SECTION lock;
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
os_unfair_lock lock;
|
||||
os_unfair_lock lock;
|
||||
#else
|
||||
pthread_mutex_t lock;
|
||||
pthread_mutex_t lock;
|
||||
#endif
|
||||
} mtx_t;
|
||||
|
||||
bool mtx_init(mtx_t *mtx);
|
||||
void mtx_fini(mtx_t *mtx);
|
||||
void mtx_lock(mtx_t *mtx);
|
||||
void mtx_unlock(mtx_t *mtx);
|
||||
bool mtx_init(mtx_t *mtx);
|
||||
void mtx_fini(mtx_t *mtx);
|
||||
void mtx_lock(mtx_t *mtx);
|
||||
void mtx_unlock(mtx_t *mtx);
|
||||
|
|
|
|||
|
|
@ -3,109 +3,109 @@
|
|||
|
||||
/* Interesting bitmap counts to test. */
|
||||
|
||||
#define NBITS_TAB \
|
||||
NB( 1) \
|
||||
NB( 2) \
|
||||
NB( 3) \
|
||||
NB( 4) \
|
||||
NB( 5) \
|
||||
NB( 6) \
|
||||
NB( 7) \
|
||||
NB( 8) \
|
||||
NB( 9) \
|
||||
NB(10) \
|
||||
NB(11) \
|
||||
NB(12) \
|
||||
NB(13) \
|
||||
NB(14) \
|
||||
NB(15) \
|
||||
NB(16) \
|
||||
NB(17) \
|
||||
NB(18) \
|
||||
NB(19) \
|
||||
NB(20) \
|
||||
NB(21) \
|
||||
NB(22) \
|
||||
NB(23) \
|
||||
NB(24) \
|
||||
NB(25) \
|
||||
NB(26) \
|
||||
NB(27) \
|
||||
NB(28) \
|
||||
NB(29) \
|
||||
NB(30) \
|
||||
NB(31) \
|
||||
NB(32) \
|
||||
\
|
||||
NB(33) \
|
||||
NB(34) \
|
||||
NB(35) \
|
||||
NB(36) \
|
||||
NB(37) \
|
||||
NB(38) \
|
||||
NB(39) \
|
||||
NB(40) \
|
||||
NB(41) \
|
||||
NB(42) \
|
||||
NB(43) \
|
||||
NB(44) \
|
||||
NB(45) \
|
||||
NB(46) \
|
||||
NB(47) \
|
||||
NB(48) \
|
||||
NB(49) \
|
||||
NB(50) \
|
||||
NB(51) \
|
||||
NB(52) \
|
||||
NB(53) \
|
||||
NB(54) \
|
||||
NB(55) \
|
||||
NB(56) \
|
||||
NB(57) \
|
||||
NB(58) \
|
||||
NB(59) \
|
||||
NB(60) \
|
||||
NB(61) \
|
||||
NB(62) \
|
||||
NB(63) \
|
||||
NB(64) \
|
||||
NB(65) \
|
||||
NB(66) \
|
||||
NB(67) \
|
||||
\
|
||||
NB(126) \
|
||||
NB(127) \
|
||||
NB(128) \
|
||||
NB(129) \
|
||||
NB(130) \
|
||||
\
|
||||
NB(254) \
|
||||
NB(255) \
|
||||
NB(256) \
|
||||
NB(257) \
|
||||
NB(258) \
|
||||
\
|
||||
NB(510) \
|
||||
NB(511) \
|
||||
NB(512) \
|
||||
NB(513) \
|
||||
NB(514) \
|
||||
\
|
||||
NB(1022) \
|
||||
NB(1023) \
|
||||
NB(1024) \
|
||||
NB(1025) \
|
||||
NB(1026) \
|
||||
\
|
||||
NB(2048) \
|
||||
\
|
||||
NB(4094) \
|
||||
NB(4095) \
|
||||
NB(4096) \
|
||||
NB(4097) \
|
||||
NB(4098) \
|
||||
\
|
||||
NB(8192) \
|
||||
NB(16384)
|
||||
#define NBITS_TAB \
|
||||
NB(1) \
|
||||
NB(2) \
|
||||
NB(3) \
|
||||
NB(4) \
|
||||
NB(5) \
|
||||
NB(6) \
|
||||
NB(7) \
|
||||
NB(8) \
|
||||
NB(9) \
|
||||
NB(10) \
|
||||
NB(11) \
|
||||
NB(12) \
|
||||
NB(13) \
|
||||
NB(14) \
|
||||
NB(15) \
|
||||
NB(16) \
|
||||
NB(17) \
|
||||
NB(18) \
|
||||
NB(19) \
|
||||
NB(20) \
|
||||
NB(21) \
|
||||
NB(22) \
|
||||
NB(23) \
|
||||
NB(24) \
|
||||
NB(25) \
|
||||
NB(26) \
|
||||
NB(27) \
|
||||
NB(28) \
|
||||
NB(29) \
|
||||
NB(30) \
|
||||
NB(31) \
|
||||
NB(32) \
|
||||
\
|
||||
NB(33) \
|
||||
NB(34) \
|
||||
NB(35) \
|
||||
NB(36) \
|
||||
NB(37) \
|
||||
NB(38) \
|
||||
NB(39) \
|
||||
NB(40) \
|
||||
NB(41) \
|
||||
NB(42) \
|
||||
NB(43) \
|
||||
NB(44) \
|
||||
NB(45) \
|
||||
NB(46) \
|
||||
NB(47) \
|
||||
NB(48) \
|
||||
NB(49) \
|
||||
NB(50) \
|
||||
NB(51) \
|
||||
NB(52) \
|
||||
NB(53) \
|
||||
NB(54) \
|
||||
NB(55) \
|
||||
NB(56) \
|
||||
NB(57) \
|
||||
NB(58) \
|
||||
NB(59) \
|
||||
NB(60) \
|
||||
NB(61) \
|
||||
NB(62) \
|
||||
NB(63) \
|
||||
NB(64) \
|
||||
NB(65) \
|
||||
NB(66) \
|
||||
NB(67) \
|
||||
\
|
||||
NB(126) \
|
||||
NB(127) \
|
||||
NB(128) \
|
||||
NB(129) \
|
||||
NB(130) \
|
||||
\
|
||||
NB(254) \
|
||||
NB(255) \
|
||||
NB(256) \
|
||||
NB(257) \
|
||||
NB(258) \
|
||||
\
|
||||
NB(510) \
|
||||
NB(511) \
|
||||
NB(512) \
|
||||
NB(513) \
|
||||
NB(514) \
|
||||
\
|
||||
NB(1022) \
|
||||
NB(1023) \
|
||||
NB(1024) \
|
||||
NB(1025) \
|
||||
NB(1026) \
|
||||
\
|
||||
NB(2048) \
|
||||
\
|
||||
NB(4094) \
|
||||
NB(4095) \
|
||||
NB(4096) \
|
||||
NB(4097) \
|
||||
NB(4098) \
|
||||
\
|
||||
NB(8192) \
|
||||
NB(16384)
|
||||
|
||||
#endif /* TEST_NBITS_H */
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#if defined(JEMALLOC_UAF_DETECTION) || defined(JEMALLOC_DEBUG)
|
||||
# define TEST_SAN_UAF_ALIGN_ENABLE "lg_san_uaf_align:12"
|
||||
# define TEST_SAN_UAF_ALIGN_DISABLE "lg_san_uaf_align:-1"
|
||||
# define TEST_SAN_UAF_ALIGN_ENABLE "lg_san_uaf_align:12"
|
||||
# define TEST_SAN_UAF_ALIGN_DISABLE "lg_san_uaf_align:-1"
|
||||
#else
|
||||
# define TEST_SAN_UAF_ALIGN_ENABLE ""
|
||||
# define TEST_SAN_UAF_ALIGN_DISABLE ""
|
||||
# define TEST_SAN_UAF_ALIGN_ENABLE ""
|
||||
# define TEST_SAN_UAF_ALIGN_DISABLE ""
|
||||
#endif
|
||||
|
||||
static inline bool
|
||||
|
|
@ -11,4 +11,3 @@ extent_is_guarded(tsdn_t *tsdn, void *ptr) {
|
|||
edata_t *edata = emap_edata_lookup(tsdn, &arena_emap_global, ptr);
|
||||
return edata_guarded_get(edata);
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,7 @@ typedef struct {
|
|||
nstime_t t1;
|
||||
} timedelta_t;
|
||||
|
||||
void timer_start(timedelta_t *timer);
|
||||
void timer_stop(timedelta_t *timer);
|
||||
uint64_t timer_usec(const timedelta_t *timer);
|
||||
void timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen);
|
||||
void timer_start(timedelta_t *timer);
|
||||
void timer_stop(timedelta_t *timer);
|
||||
uint64_t timer_usec(const timedelta_t *timer);
|
||||
void timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen);
|
||||
|
|
|
|||
|
|
@ -6,27 +6,27 @@ void *
|
|||
thd_start(void *arg) {
|
||||
unsigned thread_ind = (unsigned)(uintptr_t)arg;
|
||||
unsigned arena_ind;
|
||||
void *p;
|
||||
size_t sz;
|
||||
void *p;
|
||||
size_t sz;
|
||||
|
||||
sz = sizeof(arena_ind);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0),
|
||||
0, "Error in arenas.create");
|
||||
|
||||
if (thread_ind % 4 != 3) {
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
size_t mib[3];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
const char *dss_precs[] = {"disabled", "primary", "secondary"};
|
||||
unsigned prec_ind = thread_ind %
|
||||
(sizeof(dss_precs)/sizeof(char*));
|
||||
unsigned prec_ind = thread_ind
|
||||
% (sizeof(dss_precs) / sizeof(char *));
|
||||
const char *dss = dss_precs[prec_ind];
|
||||
int expected_err = (have_dss || prec_ind == 0) ? 0 : EFAULT;
|
||||
expect_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0,
|
||||
"Error in mallctlnametomib()");
|
||||
mib[1] = arena_ind;
|
||||
expect_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss,
|
||||
sizeof(const char *)), expected_err,
|
||||
"Error in mallctlbymib()");
|
||||
sizeof(const char *)),
|
||||
expected_err, "Error in mallctlbymib()");
|
||||
}
|
||||
|
||||
p = mallocx(1, MALLOCX_ARENA(arena_ind));
|
||||
|
|
@ -37,12 +37,11 @@ thd_start(void *arg) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_MALLOCX_ARENA) {
|
||||
thd_t thds[NTHREADS];
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
thd_create(&thds[i], thd_start,
|
||||
(void *)(uintptr_t)i);
|
||||
thd_create(&thds[i], thd_start, (void *)(uintptr_t)i);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
|
|
@ -53,6 +52,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_MALLOCX_ARENA);
|
||||
return test(test_MALLOCX_ARENA);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ purge(void) {
|
|||
|
||||
TEST_BEGIN(test_alignment_errors) {
|
||||
size_t alignment;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
alignment = 0;
|
||||
set_errno(0);
|
||||
|
|
@ -24,17 +24,15 @@ TEST_BEGIN(test_alignment_errors) {
|
|||
"Expected error for invalid alignment %zu", alignment);
|
||||
|
||||
for (alignment = sizeof(size_t); alignment < MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
alignment <<= 1) {
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment + 1, 1);
|
||||
expect_false(p != NULL || get_errno() != EINVAL,
|
||||
"Expected error for invalid alignment %zu",
|
||||
alignment + 1);
|
||||
"Expected error for invalid alignment %zu", alignment + 1);
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
/*
|
||||
* GCC "-Walloc-size-larger-than" warning detects when one of the memory
|
||||
* allocation functions is called with a size larger than the maximum size that
|
||||
|
|
@ -47,33 +45,31 @@ JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
|
|||
|
||||
TEST_BEGIN(test_oom_errors) {
|
||||
size_t alignment, size;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x8000000000000000);
|
||||
size = UINT64_C(0x8000000000000000);
|
||||
size = UINT64_C(0x8000000000000000);
|
||||
#else
|
||||
alignment = 0x80000000LU;
|
||||
size = 0x80000000LU;
|
||||
size = 0x80000000LU;
|
||||
#endif
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment, size);
|
||||
expect_false(p != NULL || get_errno() != ENOMEM,
|
||||
"Expected error for aligned_alloc(%zu, %zu)",
|
||||
alignment, size);
|
||||
"Expected error for aligned_alloc(%zu, %zu)", alignment, size);
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x4000000000000000);
|
||||
size = UINT64_C(0xc000000000000001);
|
||||
size = UINT64_C(0xc000000000000001);
|
||||
#else
|
||||
alignment = 0x40000000LU;
|
||||
size = 0xc0000001LU;
|
||||
size = 0xc0000001LU;
|
||||
#endif
|
||||
set_errno(0);
|
||||
p = aligned_alloc(alignment, size);
|
||||
expect_false(p != NULL || get_errno() != ENOMEM,
|
||||
"Expected error for aligned_alloc(%zu, %zu)",
|
||||
alignment, size);
|
||||
"Expected error for aligned_alloc(%zu, %zu)", alignment, size);
|
||||
|
||||
alignment = 0x10LU;
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
|
|
@ -84,8 +80,7 @@ TEST_BEGIN(test_oom_errors) {
|
|||
set_errno(0);
|
||||
p = aligned_alloc(alignment, size);
|
||||
expect_false(p != NULL || get_errno() != ENOMEM,
|
||||
"Expected error for aligned_alloc(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
"Expected error for aligned_alloc(&p, %zu, %zu)", alignment, size);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -94,21 +89,18 @@ JEMALLOC_DIAGNOSTIC_POP
|
|||
|
||||
TEST_BEGIN(test_alignment_and_size) {
|
||||
#define NITER 4
|
||||
size_t alignment, size, total;
|
||||
size_t alignment, size, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = NULL;
|
||||
}
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
for (alignment = 8; alignment <= MAXALIGN; alignment <<= 1) {
|
||||
total = 0;
|
||||
for (size = 1;
|
||||
size < 3 * alignment && size < (1U << 31);
|
||||
size += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (size = 1; size < 3 * alignment && size < (1U << 31);
|
||||
size += (alignment >> (LG_SIZEOF_PTR - 1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = aligned_alloc(alignment, size);
|
||||
if (ps[i] == NULL) {
|
||||
|
|
@ -149,9 +141,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_alignment_errors,
|
||||
test_oom_errors,
|
||||
test_alignment_and_size,
|
||||
test_zero_alloc);
|
||||
return test(test_alignment_errors, test_oom_errors,
|
||||
test_alignment_and_size, test_zero_alloc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,27 +2,27 @@
|
|||
|
||||
void *
|
||||
thd_start(void *arg) {
|
||||
int err;
|
||||
void *p;
|
||||
uint64_t a0, a1, d0, d1;
|
||||
int err;
|
||||
void *p;
|
||||
uint64_t a0, a1, d0, d1;
|
||||
uint64_t *ap0, *ap1, *dp0, *dp1;
|
||||
size_t sz, usize;
|
||||
size_t sz, usize;
|
||||
|
||||
sz = sizeof(a0);
|
||||
if ((err = mallctl("thread.allocated", (void *)&a0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT) {
|
||||
goto label_ENOENT;
|
||||
}
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
test_fail(
|
||||
"%s(): Error in mallctl(): %s", __func__, strerror(err));
|
||||
}
|
||||
sz = sizeof(ap0);
|
||||
if ((err = mallctl("thread.allocatedp", (void *)&ap0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT) {
|
||||
goto label_ENOENT;
|
||||
}
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
test_fail(
|
||||
"%s(): Error in mallctl(): %s", __func__, strerror(err));
|
||||
}
|
||||
expect_u64_eq(*ap0, a0,
|
||||
"\"thread.allocatedp\" should provide a pointer to internal "
|
||||
|
|
@ -33,17 +33,17 @@ thd_start(void *arg) {
|
|||
if (err == ENOENT) {
|
||||
goto label_ENOENT;
|
||||
}
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
test_fail(
|
||||
"%s(): Error in mallctl(): %s", __func__, strerror(err));
|
||||
}
|
||||
sz = sizeof(dp0);
|
||||
if ((err = mallctl("thread.deallocatedp", (void *)&dp0, &sz, NULL,
|
||||
0))) {
|
||||
if ((err = mallctl(
|
||||
"thread.deallocatedp", (void *)&dp0, &sz, NULL, 0))) {
|
||||
if (err == ENOENT) {
|
||||
goto label_ENOENT;
|
||||
}
|
||||
test_fail("%s(): Error in mallctl(): %s", __func__,
|
||||
strerror(err));
|
||||
test_fail(
|
||||
"%s(): Error in mallctl(): %s", __func__, strerror(err));
|
||||
}
|
||||
expect_u64_eq(*dp0, d0,
|
||||
"\"thread.deallocatedp\" should provide a pointer to internal "
|
||||
|
|
@ -107,10 +107,6 @@ TEST_END
|
|||
int
|
||||
main(void) {
|
||||
/* Run tests multiple times to check for bad interactions. */
|
||||
return test(
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread);
|
||||
return test(test_main_thread, test_subthread, test_main_thread,
|
||||
test_subthread, test_main_thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main() {
|
||||
return test(
|
||||
test_basic);
|
||||
return test(test_basic);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_failing_alloc);
|
||||
return test(test_failing_alloc);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
*/
|
||||
typedef void (*abort_hook_t)(const char *message);
|
||||
bool fake_abort_called;
|
||||
void fake_abort(const char *message) {
|
||||
void
|
||||
fake_abort(const char *message) {
|
||||
const char *expected_start = "<jemalloc>: Allocation of size";
|
||||
if (strncmp(message, expected_start, strlen(expected_start)) != 0) {
|
||||
abort();
|
||||
|
|
@ -19,7 +20,7 @@ void fake_abort(const char *message) {
|
|||
static bool
|
||||
own_operator_new(void) {
|
||||
uint64_t before, after;
|
||||
size_t sz = sizeof(before);
|
||||
size_t sz = sizeof(before);
|
||||
|
||||
/* thread.allocated is always available, even w/o config_stats. */
|
||||
expect_d_eq(mallctl("thread.allocated", (void *)&before, &sz, NULL, 0),
|
||||
|
|
@ -35,8 +36,8 @@ own_operator_new(void) {
|
|||
TEST_BEGIN(test_failing_alloc) {
|
||||
abort_hook_t abort_hook = &fake_abort;
|
||||
expect_d_eq(mallctl("experimental.hooks.safety_check_abort", NULL, NULL,
|
||||
(void *)&abort_hook, sizeof(abort_hook)), 0,
|
||||
"Unexpected mallctl failure setting abort hook");
|
||||
(void *)&abort_hook, sizeof(abort_hook)),
|
||||
0, "Unexpected mallctl failure setting abort hook");
|
||||
|
||||
/*
|
||||
* Not owning operator new is only expected to happen on MinGW which
|
||||
|
|
@ -61,6 +62,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_failing_alloc);
|
||||
return test(test_failing_alloc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,26 +6,29 @@
|
|||
|
||||
static void
|
||||
test_extent_body(unsigned arena_ind) {
|
||||
void *p;
|
||||
void *p;
|
||||
size_t large0, large1, large2, sz;
|
||||
size_t purge_mib[3];
|
||||
size_t purge_miblen;
|
||||
int flags;
|
||||
bool xallocx_success_a, xallocx_success_b, xallocx_success_c;
|
||||
int flags;
|
||||
bool xallocx_success_a, xallocx_success_b, xallocx_success_c;
|
||||
|
||||
flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
|
||||
/* Get large size classes. */
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctl("arenas.lextent.0.size", (void *)&large0, &sz, NULL,
|
||||
0), 0, "Unexpected arenas.lextent.0.size failure");
|
||||
expect_d_eq(mallctl("arenas.lextent.1.size", (void *)&large1, &sz, NULL,
|
||||
0), 0, "Unexpected arenas.lextent.1.size failure");
|
||||
expect_d_eq(mallctl("arenas.lextent.2.size", (void *)&large2, &sz, NULL,
|
||||
0), 0, "Unexpected arenas.lextent.2.size failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.0.size", (void *)&large0, &sz, NULL, 0), 0,
|
||||
"Unexpected arenas.lextent.0.size failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.1.size", (void *)&large1, &sz, NULL, 0), 0,
|
||||
"Unexpected arenas.lextent.1.size failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.2.size", (void *)&large2, &sz, NULL, 0), 0,
|
||||
"Unexpected arenas.lextent.2.size failure");
|
||||
|
||||
/* Test dalloc/decommit/purge cascade. */
|
||||
purge_miblen = sizeof(purge_mib)/sizeof(size_t);
|
||||
purge_miblen = sizeof(purge_mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.purge", purge_mib, &purge_miblen),
|
||||
0, "Unexpected mallctlnametomib() failure");
|
||||
purge_mib[1] = (size_t)arena_ind;
|
||||
|
|
@ -47,8 +50,8 @@ test_extent_body(unsigned arena_ind) {
|
|||
if (xallocx_success_a) {
|
||||
expect_true(called_dalloc, "Expected dalloc call");
|
||||
expect_true(called_decommit, "Expected decommit call");
|
||||
expect_true(did_purge_lazy || did_purge_forced,
|
||||
"Expected purge");
|
||||
expect_true(
|
||||
did_purge_lazy || did_purge_forced, "Expected purge");
|
||||
expect_true(called_split, "Expected split call");
|
||||
}
|
||||
dallocx(p, flags);
|
||||
|
|
@ -72,8 +75,8 @@ test_extent_body(unsigned arena_ind) {
|
|||
}
|
||||
xallocx_success_c = (xallocx(p, large0 * 2, 0, flags) == large0 * 2);
|
||||
if (did_split) {
|
||||
expect_b_eq(did_decommit, did_commit,
|
||||
"Expected decommit/commit match");
|
||||
expect_b_eq(
|
||||
did_decommit, did_commit, "Expected decommit/commit match");
|
||||
}
|
||||
if (xallocx_success_b && xallocx_success_c) {
|
||||
expect_true(did_merge, "Expected merge");
|
||||
|
|
@ -90,33 +93,34 @@ test_extent_body(unsigned arena_ind) {
|
|||
|
||||
static void
|
||||
test_manual_hook_auto_arena(void) {
|
||||
unsigned narenas;
|
||||
size_t old_size, new_size, sz;
|
||||
size_t hooks_mib[3];
|
||||
size_t hooks_miblen;
|
||||
unsigned narenas;
|
||||
size_t old_size, new_size, sz;
|
||||
size_t hooks_mib[3];
|
||||
size_t hooks_miblen;
|
||||
extent_hooks_t *new_hooks, *old_hooks;
|
||||
|
||||
extent_hooks_prep();
|
||||
|
||||
sz = sizeof(unsigned);
|
||||
/* Get number of auto arenas. */
|
||||
expect_d_eq(mallctl("opt.narenas", (void *)&narenas, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("opt.narenas", (void *)&narenas, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
if (narenas == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Install custom extent hooks on arena 1 (might not be initialized). */
|
||||
hooks_miblen = sizeof(hooks_mib)/sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.extent_hooks", hooks_mib,
|
||||
&hooks_miblen), 0, "Unexpected mallctlnametomib() failure");
|
||||
hooks_miblen = sizeof(hooks_mib) / sizeof(size_t);
|
||||
expect_d_eq(
|
||||
mallctlnametomib("arena.0.extent_hooks", hooks_mib, &hooks_miblen),
|
||||
0, "Unexpected mallctlnametomib() failure");
|
||||
hooks_mib[1] = 1;
|
||||
old_size = sizeof(extent_hooks_t *);
|
||||
new_hooks = &hooks;
|
||||
new_size = sizeof(extent_hooks_t *);
|
||||
expect_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks,
|
||||
&old_size, (void *)&new_hooks, new_size), 0,
|
||||
"Unexpected extent_hooks error");
|
||||
&old_size, (void *)&new_hooks, new_size),
|
||||
0, "Unexpected extent_hooks error");
|
||||
static bool auto_arena_created = false;
|
||||
if (old_hooks != &hooks) {
|
||||
expect_b_eq(auto_arena_created, false,
|
||||
|
|
@ -127,10 +131,10 @@ test_manual_hook_auto_arena(void) {
|
|||
|
||||
static void
|
||||
test_manual_hook_body(void) {
|
||||
unsigned arena_ind;
|
||||
size_t old_size, new_size, sz;
|
||||
size_t hooks_mib[3];
|
||||
size_t hooks_miblen;
|
||||
unsigned arena_ind;
|
||||
size_t old_size, new_size, sz;
|
||||
size_t hooks_mib[3];
|
||||
size_t hooks_miblen;
|
||||
extent_hooks_t *new_hooks, *old_hooks;
|
||||
|
||||
extent_hooks_prep();
|
||||
|
|
@ -140,16 +144,17 @@ test_manual_hook_body(void) {
|
|||
0, "Unexpected mallctl() failure");
|
||||
|
||||
/* Install custom extent hooks. */
|
||||
hooks_miblen = sizeof(hooks_mib)/sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.extent_hooks", hooks_mib,
|
||||
&hooks_miblen), 0, "Unexpected mallctlnametomib() failure");
|
||||
hooks_miblen = sizeof(hooks_mib) / sizeof(size_t);
|
||||
expect_d_eq(
|
||||
mallctlnametomib("arena.0.extent_hooks", hooks_mib, &hooks_miblen),
|
||||
0, "Unexpected mallctlnametomib() failure");
|
||||
hooks_mib[1] = (size_t)arena_ind;
|
||||
old_size = sizeof(extent_hooks_t *);
|
||||
new_hooks = &hooks;
|
||||
new_size = sizeof(extent_hooks_t *);
|
||||
expect_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks,
|
||||
&old_size, (void *)&new_hooks, new_size), 0,
|
||||
"Unexpected extent_hooks error");
|
||||
&old_size, (void *)&new_hooks, new_size),
|
||||
0, "Unexpected extent_hooks error");
|
||||
expect_ptr_ne(old_hooks->alloc, extent_alloc_hook,
|
||||
"Unexpected extent_hooks error");
|
||||
expect_ptr_ne(old_hooks->dalloc, extent_dalloc_hook,
|
||||
|
|
@ -173,10 +178,13 @@ test_manual_hook_body(void) {
|
|||
|
||||
/* Restore extent hooks. */
|
||||
expect_d_eq(mallctlbymib(hooks_mib, hooks_miblen, NULL, NULL,
|
||||
(void *)&old_hooks, new_size), 0, "Unexpected extent_hooks error");
|
||||
(void *)&old_hooks, new_size),
|
||||
0, "Unexpected extent_hooks error");
|
||||
expect_d_eq(mallctlbymib(hooks_mib, hooks_miblen, (void *)&old_hooks,
|
||||
&old_size, NULL, 0), 0, "Unexpected extent_hooks error");
|
||||
expect_ptr_eq(old_hooks, default_hooks, "Unexpected extent_hooks error");
|
||||
&old_size, NULL, 0),
|
||||
0, "Unexpected extent_hooks error");
|
||||
expect_ptr_eq(
|
||||
old_hooks, default_hooks, "Unexpected extent_hooks error");
|
||||
expect_ptr_eq(old_hooks->alloc, default_hooks->alloc,
|
||||
"Unexpected extent_hooks error");
|
||||
expect_ptr_eq(old_hooks->dalloc, default_hooks->dalloc,
|
||||
|
|
@ -213,8 +221,8 @@ TEST_BEGIN(test_extent_manual_hook) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_extent_auto_hook) {
|
||||
unsigned arena_ind;
|
||||
size_t new_size, sz;
|
||||
unsigned arena_ind;
|
||||
size_t new_size, sz;
|
||||
extent_hooks_t *new_hooks;
|
||||
|
||||
extent_hooks_prep();
|
||||
|
|
@ -223,7 +231,8 @@ TEST_BEGIN(test_extent_auto_hook) {
|
|||
new_hooks = &hooks;
|
||||
new_size = sizeof(extent_hooks_t *);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz,
|
||||
(void *)&new_hooks, new_size), 0, "Unexpected mallctl() failure");
|
||||
(void *)&new_hooks, new_size),
|
||||
0, "Unexpected mallctl() failure");
|
||||
|
||||
test_skip_if(is_background_thread_enabled());
|
||||
test_extent_body(arena_ind);
|
||||
|
|
@ -231,19 +240,18 @@ TEST_BEGIN(test_extent_auto_hook) {
|
|||
TEST_END
|
||||
|
||||
static void
|
||||
test_arenas_create_ext_base(arena_config_t config,
|
||||
bool expect_hook_data, bool expect_hook_metadata)
|
||||
{
|
||||
test_arenas_create_ext_base(
|
||||
arena_config_t config, bool expect_hook_data, bool expect_hook_metadata) {
|
||||
unsigned arena, arena1;
|
||||
void *ptr;
|
||||
size_t sz = sizeof(unsigned);
|
||||
void *ptr;
|
||||
size_t sz = sizeof(unsigned);
|
||||
|
||||
extent_hooks_prep();
|
||||
|
||||
called_alloc = false;
|
||||
expect_d_eq(mallctl("experimental.arenas_create_ext",
|
||||
(void *)&arena, &sz, &config, sizeof(arena_config_t)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("experimental.arenas_create_ext", (void *)&arena,
|
||||
&sz, &config, sizeof(arena_config_t)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_b_eq(called_alloc, expect_hook_metadata,
|
||||
"expected hook metadata alloc mismatch");
|
||||
|
||||
|
|
@ -279,9 +287,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_extent_manual_hook,
|
||||
test_extent_auto_hook,
|
||||
return test(test_extent_manual_hook, test_extent_auto_hook,
|
||||
test_arenas_create_ext_with_ehooks_no_metadata,
|
||||
test_arenas_create_ext_with_ehooks_with_metadata);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_zero_alloc);
|
||||
return test(test_zero_alloc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
static unsigned
|
||||
get_nsizes_impl(const char *cmd) {
|
||||
unsigned ret;
|
||||
size_t z;
|
||||
size_t z;
|
||||
|
||||
z = sizeof(unsigned);
|
||||
expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
|
||||
|
|
@ -25,12 +25,12 @@ get_size_impl(const char *cmd, size_t ind) {
|
|||
size_t miblen = 4;
|
||||
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
mib[2] = ind;
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
|
||||
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -64,36 +64,37 @@ JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
|
|||
TEST_BEGIN(test_overflow) {
|
||||
size_t largemax;
|
||||
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
expect_ptr_null(mallocx(largemax+1, 0),
|
||||
"Expected OOM for mallocx(size=%#zx, 0)", largemax+1);
|
||||
expect_ptr_null(mallocx(largemax + 1, 0),
|
||||
"Expected OOM for mallocx(size=%#zx, 0)", largemax + 1);
|
||||
|
||||
expect_ptr_null(mallocx(ZU(PTRDIFF_MAX)+1, 0),
|
||||
"Expected OOM for mallocx(size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);
|
||||
expect_ptr_null(mallocx(ZU(PTRDIFF_MAX) + 1, 0),
|
||||
"Expected OOM for mallocx(size=%#zx, 0)", ZU(PTRDIFF_MAX) + 1);
|
||||
|
||||
expect_ptr_null(mallocx(SIZE_T_MAX, 0),
|
||||
"Expected OOM for mallocx(size=%#zx, 0)", SIZE_T_MAX);
|
||||
|
||||
expect_ptr_null(mallocx(1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)),
|
||||
expect_ptr_null(mallocx(1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX) + 1)),
|
||||
"Expected OOM for mallocx(size=1, MALLOCX_ALIGN(%#zx))",
|
||||
ZU(PTRDIFF_MAX)+1);
|
||||
ZU(PTRDIFF_MAX) + 1);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
static void *
|
||||
remote_alloc(void *arg) {
|
||||
unsigned arena;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
size_t large_sz;
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctl("arenas.lextent.0.size", (void *)&large_sz, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.0.size", (void *)&large_sz, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl failure");
|
||||
|
||||
void *ptr = mallocx(large_sz, MALLOCX_ARENA(arena)
|
||||
| MALLOCX_TCACHE_NONE);
|
||||
void *ptr = mallocx(
|
||||
large_sz, MALLOCX_ARENA(arena) | MALLOCX_TCACHE_NONE);
|
||||
void **ret = (void **)arg;
|
||||
*ret = ptr;
|
||||
|
||||
|
|
@ -114,16 +115,16 @@ TEST_BEGIN(test_remote_free) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_oom) {
|
||||
size_t largemax;
|
||||
bool oom;
|
||||
void *ptrs[3];
|
||||
size_t largemax;
|
||||
bool oom;
|
||||
void *ptrs[3];
|
||||
unsigned i;
|
||||
|
||||
/*
|
||||
* It should be impossible to allocate three objects that each consume
|
||||
* nearly half the virtual address space.
|
||||
*/
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
oom = false;
|
||||
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
|
||||
ptrs[i] = mallocx(largemax, MALLOCX_ARENA(0));
|
||||
|
|
@ -143,10 +144,10 @@ TEST_BEGIN(test_oom) {
|
|||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
expect_ptr_null(mallocx(0x8000000000000000ULL,
|
||||
MALLOCX_ALIGN(0x8000000000000000ULL)),
|
||||
MALLOCX_ALIGN(0x8000000000000000ULL)),
|
||||
"Expected OOM for mallocx()");
|
||||
expect_ptr_null(mallocx(0x8000000000000000ULL,
|
||||
MALLOCX_ALIGN(0x80000000)),
|
||||
expect_ptr_null(
|
||||
mallocx(0x8000000000000000ULL, MALLOCX_ALIGN(0x80000000)),
|
||||
"Expected OOM for mallocx()");
|
||||
#else
|
||||
expect_ptr_null(mallocx(0x80000000UL, MALLOCX_ALIGN(0x80000000UL)),
|
||||
|
|
@ -164,20 +165,20 @@ TEST_BEGIN(test_basic) {
|
|||
|
||||
for (sz = 1; sz < MAXSZ; sz = nallocx(sz, 0) + 1) {
|
||||
size_t nsz, rsz;
|
||||
void *p;
|
||||
void *p;
|
||||
nsz = nallocx(sz, 0);
|
||||
expect_zu_ne(nsz, 0, "Unexpected nallocx() error");
|
||||
p = mallocx(sz, 0);
|
||||
expect_ptr_not_null(p,
|
||||
"Unexpected mallocx(size=%zx, flags=0) error", sz);
|
||||
expect_ptr_not_null(
|
||||
p, "Unexpected mallocx(size=%zx, flags=0) error", sz);
|
||||
rsz = sallocx(p, 0);
|
||||
expect_zu_ge(rsz, sz, "Real size smaller than expected");
|
||||
expect_zu_eq(nsz, rsz, "nallocx()/sallocx() size mismatch");
|
||||
dallocx(p, 0);
|
||||
|
||||
p = mallocx(sz, 0);
|
||||
expect_ptr_not_null(p,
|
||||
"Unexpected mallocx(size=%zx, flags=0) error", sz);
|
||||
expect_ptr_not_null(
|
||||
p, "Unexpected mallocx(size=%zx, flags=0) error", sz);
|
||||
dallocx(p, 0);
|
||||
|
||||
nsz = nallocx(sz, MALLOCX_ZERO);
|
||||
|
|
@ -197,53 +198,57 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_alignment_and_size) {
|
||||
const char *percpu_arena;
|
||||
size_t sz = sizeof(percpu_arena);
|
||||
size_t sz = sizeof(percpu_arena);
|
||||
|
||||
if(mallctl("opt.percpu_arena", (void *)&percpu_arena, &sz, NULL, 0) ||
|
||||
strcmp(percpu_arena, "disabled") != 0) {
|
||||
test_skip("test_alignment_and_size skipped: "
|
||||
if (mallctl("opt.percpu_arena", (void *)&percpu_arena, &sz, NULL, 0)
|
||||
|| strcmp(percpu_arena, "disabled") != 0) {
|
||||
test_skip(
|
||||
"test_alignment_and_size skipped: "
|
||||
"not working with percpu arena.");
|
||||
};
|
||||
#define MAXALIGN (((size_t)1) << 23)
|
||||
#define NITER 4
|
||||
size_t nsz, rsz, alignment, total;
|
||||
size_t nsz, rsz, alignment, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = NULL;
|
||||
}
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
for (alignment = 8; alignment <= MAXALIGN; alignment <<= 1) {
|
||||
total = 0;
|
||||
for (sz = 1;
|
||||
sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (sz = 1; sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR - 1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO | MALLOCX_ARENA(0));
|
||||
nsz = nallocx(sz,
|
||||
MALLOCX_ALIGN(alignment) | MALLOCX_ZERO
|
||||
| MALLOCX_ARENA(0));
|
||||
expect_zu_ne(nsz, 0,
|
||||
"nallocx() error for alignment=%zu, "
|
||||
"size=%zu (%#zx)", alignment, sz, sz);
|
||||
ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO | MALLOCX_ARENA(0));
|
||||
"size=%zu (%#zx)",
|
||||
alignment, sz, sz);
|
||||
ps[i] = mallocx(sz,
|
||||
MALLOCX_ALIGN(alignment) | MALLOCX_ZERO
|
||||
| MALLOCX_ARENA(0));
|
||||
expect_ptr_not_null(ps[i],
|
||||
"mallocx() error for alignment=%zu, "
|
||||
"size=%zu (%#zx)", alignment, sz, sz);
|
||||
"size=%zu (%#zx)",
|
||||
alignment, sz, sz);
|
||||
rsz = sallocx(ps[i], 0);
|
||||
expect_zu_ge(rsz, sz,
|
||||
"Real size smaller than expected for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
"alignment=%zu, size=%zu",
|
||||
alignment, sz);
|
||||
expect_zu_eq(nsz, rsz,
|
||||
"nallocx()/sallocx() size mismatch for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
expect_ptr_null(
|
||||
(void *)((uintptr_t)ps[i] & (alignment-1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu", ps[i],
|
||||
"alignment=%zu, size=%zu",
|
||||
alignment, sz);
|
||||
expect_ptr_null((void *)((uintptr_t)ps[i]
|
||||
& (alignment - 1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu",
|
||||
ps[i], alignment, sz);
|
||||
total += rsz;
|
||||
if (total >= (MAXALIGN << 1)) {
|
||||
break;
|
||||
|
|
@ -265,10 +270,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_overflow,
|
||||
test_oom,
|
||||
test_remote_free,
|
||||
test_basic,
|
||||
return test(test_overflow, test_oom, test_remote_free, test_basic,
|
||||
test_alignment_and_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
|
|||
|
||||
TEST_BEGIN(test_overflow) {
|
||||
unsigned nlextents;
|
||||
size_t mib[4];
|
||||
size_t sz, miblen, max_size_class;
|
||||
void *p;
|
||||
size_t mib[4];
|
||||
size_t sz, miblen, max_size_class;
|
||||
void *p;
|
||||
|
||||
sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.nlextents", (void *)&nlextents, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.nlextents", (void *)&nlextents, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl() error");
|
||||
|
||||
miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arenas.lextent.0.size", mib, &miblen), 0,
|
||||
|
|
@ -26,8 +27,9 @@ TEST_BEGIN(test_overflow) {
|
|||
mib[2] = nlextents - 1;
|
||||
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&max_size_class, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctlbymib() error");
|
||||
expect_d_eq(
|
||||
mallctlbymib(mib, miblen, (void *)&max_size_class, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib() error");
|
||||
|
||||
expect_ptr_null(malloc(max_size_class + 1),
|
||||
"Expected OOM due to over-sized allocation request");
|
||||
|
|
@ -54,6 +56,5 @@ JEMALLOC_DIAGNOSTIC_POP
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_overflow);
|
||||
return test(test_overflow);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,48 +15,44 @@ purge(void) {
|
|||
|
||||
TEST_BEGIN(test_alignment_errors) {
|
||||
size_t alignment;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
for (alignment = 0; alignment < sizeof(void *); alignment++) {
|
||||
expect_d_eq(posix_memalign(&p, alignment, 1), EINVAL,
|
||||
"Expected error for invalid alignment %zu",
|
||||
alignment);
|
||||
"Expected error for invalid alignment %zu", alignment);
|
||||
}
|
||||
|
||||
for (alignment = sizeof(size_t); alignment < MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
alignment <<= 1) {
|
||||
expect_d_ne(posix_memalign(&p, alignment + 1, 1), 0,
|
||||
"Expected error for invalid alignment %zu",
|
||||
alignment + 1);
|
||||
"Expected error for invalid alignment %zu", alignment + 1);
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_oom_errors) {
|
||||
size_t alignment, size;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x8000000000000000);
|
||||
size = UINT64_C(0x8000000000000000);
|
||||
size = UINT64_C(0x8000000000000000);
|
||||
#else
|
||||
alignment = 0x80000000LU;
|
||||
size = 0x80000000LU;
|
||||
size = 0x80000000LU;
|
||||
#endif
|
||||
expect_d_ne(posix_memalign(&p, alignment, size), 0,
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)", alignment, size);
|
||||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
alignment = UINT64_C(0x4000000000000000);
|
||||
size = UINT64_C(0xc000000000000001);
|
||||
size = UINT64_C(0xc000000000000001);
|
||||
#else
|
||||
alignment = 0x40000000LU;
|
||||
size = 0xc0000001LU;
|
||||
size = 0xc0000001LU;
|
||||
#endif
|
||||
expect_d_ne(posix_memalign(&p, alignment, size), 0,
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)", alignment, size);
|
||||
|
||||
alignment = 0x10LU;
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
|
|
@ -65,33 +61,29 @@ TEST_BEGIN(test_oom_errors) {
|
|||
size = 0xfffffff0LU;
|
||||
#endif
|
||||
expect_d_ne(posix_memalign(&p, alignment, size), 0,
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)",
|
||||
alignment, size);
|
||||
"Expected error for posix_memalign(&p, %zu, %zu)", alignment, size);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size) {
|
||||
#define NITER 4
|
||||
size_t alignment, size, total;
|
||||
size_t alignment, size, total;
|
||||
unsigned i;
|
||||
int err;
|
||||
void *ps[NITER];
|
||||
int err;
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = NULL;
|
||||
}
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
for (alignment = 8; alignment <= MAXALIGN; alignment <<= 1) {
|
||||
total = 0;
|
||||
for (size = 0;
|
||||
size < 3 * alignment && size < (1U << 31);
|
||||
size += ((size == 0) ? 1 :
|
||||
(alignment >> (LG_SIZEOF_PTR-1)) - 1)) {
|
||||
for (size = 0; size < 3 * alignment && size < (1U << 31);
|
||||
size += ((size == 0)
|
||||
? 1
|
||||
: (alignment >> (LG_SIZEOF_PTR - 1)) - 1)) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
err = posix_memalign(&ps[i],
|
||||
alignment, size);
|
||||
err = posix_memalign(&ps[i], alignment, size);
|
||||
if (err) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
|
|
@ -122,7 +114,5 @@ TEST_END
|
|||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_alignment_errors,
|
||||
test_oom_errors,
|
||||
test_alignment_and_size);
|
||||
test_alignment_errors, test_oom_errors, test_alignment_and_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
static unsigned
|
||||
get_nsizes_impl(const char *cmd) {
|
||||
unsigned ret;
|
||||
size_t z;
|
||||
size_t z;
|
||||
|
||||
z = sizeof(unsigned);
|
||||
expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
|
||||
|
|
@ -25,12 +25,12 @@ get_size_impl(const char *cmd, size_t ind) {
|
|||
size_t miblen = 4;
|
||||
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
mib[2] = ind;
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
|
||||
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -58,25 +58,26 @@ TEST_BEGIN(test_grow_and_shrink) {
|
|||
szs[0] = sallocx(p, 0);
|
||||
|
||||
for (i = 0; i < NCYCLES; i++) {
|
||||
for (j = 1; j < NSZS && szs[j-1] < MAXSZ; j++) {
|
||||
q = rallocx(p, szs[j-1]+1, 0);
|
||||
for (j = 1; j < NSZS && szs[j - 1] < MAXSZ; j++) {
|
||||
q = rallocx(p, szs[j - 1] + 1, 0);
|
||||
expect_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for size=%zu-->%zu",
|
||||
szs[j-1], szs[j-1]+1);
|
||||
szs[j - 1], szs[j - 1] + 1);
|
||||
szs[j] = sallocx(q, 0);
|
||||
expect_zu_ne(szs[j], szs[j-1]+1,
|
||||
"Expected size to be at least: %zu", szs[j-1]+1);
|
||||
expect_zu_ne(szs[j], szs[j - 1] + 1,
|
||||
"Expected size to be at least: %zu",
|
||||
szs[j - 1] + 1);
|
||||
p = q;
|
||||
}
|
||||
|
||||
for (j--; j > 0; j--) {
|
||||
q = rallocx(p, szs[j-1], 0);
|
||||
q = rallocx(p, szs[j - 1], 0);
|
||||
expect_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for size=%zu-->%zu",
|
||||
szs[j], szs[j-1]);
|
||||
szs[j], szs[j - 1]);
|
||||
tsz = sallocx(q, 0);
|
||||
expect_zu_eq(tsz, szs[j-1],
|
||||
"Expected size=%zu, got size=%zu", szs[j-1], tsz);
|
||||
expect_zu_eq(tsz, szs[j - 1],
|
||||
"Expected size=%zu, got size=%zu", szs[j - 1], tsz);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
|
@ -99,11 +100,12 @@ validate_fill(void *p, uint8_t c, size_t offset, size_t len) {
|
|||
size_t i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t b = buf[offset+i];
|
||||
uint8_t b = buf[offset + i];
|
||||
if (b != c) {
|
||||
test_fail("Allocation at %p (len=%zu) contains %#x "
|
||||
"rather than %#x at offset %zu", p, len, b, c,
|
||||
offset+i);
|
||||
test_fail(
|
||||
"Allocation at %p (len=%zu) contains %#x "
|
||||
"rather than %#x at offset %zu",
|
||||
p, len, b, c, offset + i);
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -118,35 +120,37 @@ TEST_BEGIN(test_zero) {
|
|||
*/
|
||||
void *volatile p, *volatile q;
|
||||
size_t psz, qsz, i, j;
|
||||
size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024};
|
||||
size_t start_sizes[] = {1, 3 * 1024, 63 * 1024, 4095 * 1024};
|
||||
#define FILL_BYTE 0xaaU
|
||||
#define RANGE 2048
|
||||
|
||||
for (i = 0; i < sizeof(start_sizes)/sizeof(size_t); i++) {
|
||||
for (i = 0; i < sizeof(start_sizes) / sizeof(size_t); i++) {
|
||||
size_t start_size = start_sizes[i];
|
||||
p = mallocx(start_size, MALLOCX_ZERO);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
psz = sallocx(p, 0);
|
||||
|
||||
expect_false(validate_fill(p, 0, 0, psz),
|
||||
"Expected zeroed memory");
|
||||
expect_false(
|
||||
validate_fill(p, 0, 0, psz), "Expected zeroed memory");
|
||||
memset(p, FILL_BYTE, psz);
|
||||
expect_false(validate_fill(p, FILL_BYTE, 0, psz),
|
||||
"Expected filled memory");
|
||||
|
||||
for (j = 1; j < RANGE; j++) {
|
||||
q = rallocx(p, start_size+j, MALLOCX_ZERO);
|
||||
q = rallocx(p, start_size + j, MALLOCX_ZERO);
|
||||
expect_ptr_not_null(q, "Unexpected rallocx() error");
|
||||
qsz = sallocx(q, 0);
|
||||
if (q != p || qsz != psz) {
|
||||
expect_false(validate_fill(q, FILL_BYTE, 0,
|
||||
psz), "Expected filled memory");
|
||||
expect_false(validate_fill(q, 0, psz, qsz-psz),
|
||||
expect_false(
|
||||
validate_fill(q, FILL_BYTE, 0, psz),
|
||||
"Expected filled memory");
|
||||
expect_false(
|
||||
validate_fill(q, 0, psz, qsz - psz),
|
||||
"Expected zeroed memory");
|
||||
}
|
||||
if (psz != qsz) {
|
||||
memset((void *)((uintptr_t)q+psz), FILL_BYTE,
|
||||
qsz-psz);
|
||||
memset((void *)((uintptr_t)q + psz), FILL_BYTE,
|
||||
qsz - psz);
|
||||
psz = qsz;
|
||||
}
|
||||
p = q;
|
||||
|
|
@ -160,7 +164,7 @@ TEST_BEGIN(test_zero) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_align) {
|
||||
void *p, *q;
|
||||
void *p, *q;
|
||||
size_t align;
|
||||
#define MAX_ALIGN (ZU(1) << 25)
|
||||
|
||||
|
|
@ -170,12 +174,10 @@ TEST_BEGIN(test_align) {
|
|||
|
||||
for (align <<= 1; align <= MAX_ALIGN; align <<= 1) {
|
||||
q = rallocx(p, 1, MALLOCX_ALIGN(align));
|
||||
expect_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for align=%zu", align);
|
||||
expect_ptr_null(
|
||||
(void *)((uintptr_t)q & (align-1)),
|
||||
"%p inadequately aligned for align=%zu",
|
||||
q, align);
|
||||
expect_ptr_not_null(
|
||||
q, "Unexpected rallocx() error for align=%zu", align);
|
||||
expect_ptr_null((void *)((uintptr_t)q & (align - 1)),
|
||||
"%p inadequately aligned for align=%zu", q, align);
|
||||
p = q;
|
||||
}
|
||||
dallocx(p, 0);
|
||||
|
|
@ -191,19 +193,19 @@ TEST_BEGIN(test_align_enum) {
|
|||
for (size_t lg_size = LG_MIN; lg_size <= LG_MAX; ++lg_size) {
|
||||
size_t size = 1 << lg_size;
|
||||
for (size_t lg_align_next = LG_MIN;
|
||||
lg_align_next <= LG_MAX; ++lg_align_next) {
|
||||
int flags = MALLOCX_LG_ALIGN(lg_align);
|
||||
lg_align_next <= LG_MAX; ++lg_align_next) {
|
||||
int flags = MALLOCX_LG_ALIGN(lg_align);
|
||||
void *p = mallocx(1, flags);
|
||||
assert_ptr_not_null(p,
|
||||
"Unexpected mallocx() error");
|
||||
assert_ptr_not_null(
|
||||
p, "Unexpected mallocx() error");
|
||||
assert_zu_eq(nallocx(1, flags),
|
||||
TEST_MALLOC_SIZE(p),
|
||||
"Wrong mallocx() usable size");
|
||||
int flags_next =
|
||||
MALLOCX_LG_ALIGN(lg_align_next);
|
||||
int flags_next = MALLOCX_LG_ALIGN(
|
||||
lg_align_next);
|
||||
p = rallocx(p, size, flags_next);
|
||||
assert_ptr_not_null(p,
|
||||
"Unexpected rallocx() error");
|
||||
assert_ptr_not_null(
|
||||
p, "Unexpected rallocx() error");
|
||||
expect_zu_eq(nallocx(size, flags_next),
|
||||
TEST_MALLOC_SIZE(p),
|
||||
"Wrong rallocx() usable size");
|
||||
|
|
@ -223,20 +225,20 @@ TEST_BEGIN(test_lg_align_and_zero) {
|
|||
*/
|
||||
void *volatile p, *volatile q;
|
||||
unsigned lg_align;
|
||||
size_t sz;
|
||||
size_t sz;
|
||||
#define MAX_LG_ALIGN 25
|
||||
#define MAX_VALIDATE (ZU(1) << 22)
|
||||
|
||||
lg_align = 0;
|
||||
p = mallocx(1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
|
||||
p = mallocx(1, MALLOCX_LG_ALIGN(lg_align) | MALLOCX_ZERO);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
||||
for (lg_align++; lg_align <= MAX_LG_ALIGN; lg_align++) {
|
||||
q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align)|MALLOCX_ZERO);
|
||||
expect_ptr_not_null(q,
|
||||
"Unexpected rallocx() error for lg_align=%u", lg_align);
|
||||
q = rallocx(p, 1, MALLOCX_LG_ALIGN(lg_align) | MALLOCX_ZERO);
|
||||
expect_ptr_not_null(
|
||||
q, "Unexpected rallocx() error for lg_align=%u", lg_align);
|
||||
expect_ptr_null(
|
||||
(void *)((uintptr_t)q & ((ZU(1) << lg_align)-1)),
|
||||
(void *)((uintptr_t)q & ((ZU(1) << lg_align) - 1)),
|
||||
"%p inadequately aligned for lg_align=%u", q, lg_align);
|
||||
sz = sallocx(q, 0);
|
||||
if ((sz << 1) <= MAX_VALIDATE) {
|
||||
|
|
@ -245,9 +247,10 @@ TEST_BEGIN(test_lg_align_and_zero) {
|
|||
} else {
|
||||
expect_false(validate_fill(q, 0, 0, MAX_VALIDATE),
|
||||
"Expected zeroed memory");
|
||||
expect_false(validate_fill(
|
||||
(void *)((uintptr_t)q+sz-MAX_VALIDATE),
|
||||
0, 0, MAX_VALIDATE), "Expected zeroed memory");
|
||||
expect_false(validate_fill((void *)((uintptr_t)q + sz
|
||||
- MAX_VALIDATE),
|
||||
0, 0, MAX_VALIDATE),
|
||||
"Expected zeroed memory");
|
||||
}
|
||||
p = q;
|
||||
}
|
||||
|
|
@ -269,25 +272,25 @@ JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
|
|||
|
||||
TEST_BEGIN(test_overflow) {
|
||||
size_t largemax;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
p = mallocx(1, 0);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() failure");
|
||||
|
||||
expect_ptr_null(rallocx(p, largemax+1, 0),
|
||||
"Expected OOM for rallocx(p, size=%#zx, 0)", largemax+1);
|
||||
expect_ptr_null(rallocx(p, largemax + 1, 0),
|
||||
"Expected OOM for rallocx(p, size=%#zx, 0)", largemax + 1);
|
||||
|
||||
expect_ptr_null(rallocx(p, ZU(PTRDIFF_MAX)+1, 0),
|
||||
"Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);
|
||||
expect_ptr_null(rallocx(p, ZU(PTRDIFF_MAX) + 1, 0),
|
||||
"Expected OOM for rallocx(p, size=%#zx, 0)", ZU(PTRDIFF_MAX) + 1);
|
||||
|
||||
expect_ptr_null(rallocx(p, SIZE_T_MAX, 0),
|
||||
"Expected OOM for rallocx(p, size=%#zx, 0)", SIZE_T_MAX);
|
||||
|
||||
expect_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)),
|
||||
expect_ptr_null(rallocx(p, 1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX) + 1)),
|
||||
"Expected OOM for rallocx(p, size=1, MALLOCX_ALIGN(%#zx))",
|
||||
ZU(PTRDIFF_MAX)+1);
|
||||
ZU(PTRDIFF_MAX) + 1);
|
||||
|
||||
dallocx(p, 0);
|
||||
}
|
||||
|
|
@ -298,11 +301,6 @@ JEMALLOC_DIAGNOSTIC_POP
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_grow_and_shrink,
|
||||
test_zero,
|
||||
test_align,
|
||||
test_align_enum,
|
||||
test_lg_align_and_zero,
|
||||
test_overflow);
|
||||
return test(test_grow_and_shrink, test_zero, test_align,
|
||||
test_align_enum, test_lg_align_and_zero, test_overflow);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,26 +10,23 @@ TEST_BEGIN(test_basic) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_alignment_and_size) {
|
||||
size_t nsz, sz, alignment, total;
|
||||
size_t nsz, sz, alignment, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = NULL;
|
||||
}
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
for (alignment = 8; alignment <= MAXALIGN; alignment <<= 1) {
|
||||
total = 0;
|
||||
for (sz = 1;
|
||||
sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (sz = 1; sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR - 1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO);
|
||||
ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO);
|
||||
nsz = nallocx(sz,
|
||||
MALLOCX_ALIGN(alignment) | MALLOCX_ZERO);
|
||||
ps[i] = mallocx(sz,
|
||||
MALLOCX_ALIGN(alignment) | MALLOCX_ZERO);
|
||||
total += nsz;
|
||||
if (total >= (MAXALIGN << 1)) {
|
||||
break;
|
||||
|
|
@ -49,7 +46,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_basic,
|
||||
test_alignment_and_size);
|
||||
return test_no_reentrancy(test_basic, test_alignment_and_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
TEST_BEGIN(test_slab_sizes) {
|
||||
unsigned nbins;
|
||||
size_t page;
|
||||
size_t sizemib[4];
|
||||
size_t slabmib[4];
|
||||
size_t len;
|
||||
size_t page;
|
||||
size_t sizemib[4];
|
||||
size_t slabmib[4];
|
||||
size_t len;
|
||||
|
||||
len = sizeof(nbins);
|
||||
expect_d_eq(mallctl("arenas.nbins", &nbins, &len, NULL, 0), 0,
|
||||
|
|
@ -33,12 +33,14 @@ TEST_BEGIN(test_slab_sizes) {
|
|||
len = sizeof(size_t);
|
||||
sizemib[2] = i;
|
||||
slabmib[2] = i;
|
||||
expect_d_eq(mallctlbymib(sizemib, 4, (void *)&bin_size, &len,
|
||||
NULL, 0), 0, "bin size mallctlbymib failure");
|
||||
expect_d_eq(
|
||||
mallctlbymib(sizemib, 4, (void *)&bin_size, &len, NULL, 0),
|
||||
0, "bin size mallctlbymib failure");
|
||||
|
||||
len = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(slabmib, 4, (void *)&slab_size, &len,
|
||||
NULL, 0), 0, "slab size mallctlbymib failure");
|
||||
expect_d_eq(
|
||||
mallctlbymib(slabmib, 4, (void *)&slab_size, &len, NULL, 0),
|
||||
0, "slab size mallctlbymib failure");
|
||||
|
||||
if (bin_size < 100) {
|
||||
/*
|
||||
|
|
@ -51,8 +53,7 @@ TEST_BEGIN(test_slab_sizes) {
|
|||
expect_zu_ge(slab_size, biggest_slab_seen,
|
||||
"Slab sizes should go up");
|
||||
biggest_slab_seen = slab_size;
|
||||
} else if (
|
||||
(100 <= bin_size && bin_size < 128)
|
||||
} else if ((100 <= bin_size && bin_size < 128)
|
||||
|| (128 < bin_size && bin_size <= 200)) {
|
||||
expect_zu_eq(slab_size, page,
|
||||
"Forced-small slabs should be small");
|
||||
|
|
@ -75,6 +76,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_slab_sizes);
|
||||
return test(test_slab_sizes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,24 @@
|
|||
#define STR(x) STR_HELPER(x)
|
||||
|
||||
#ifndef JEMALLOC_VERSION_GID_IDENT
|
||||
#error "JEMALLOC_VERSION_GID_IDENT not defined"
|
||||
# error "JEMALLOC_VERSION_GID_IDENT not defined"
|
||||
#endif
|
||||
|
||||
#define JOIN(x, y) x ## y
|
||||
#define JOIN(x, y) x##y
|
||||
#define JOIN2(x, y) JOIN(x, y)
|
||||
#define smallocx JOIN2(smallocx_, JEMALLOC_VERSION_GID_IDENT)
|
||||
|
||||
typedef struct {
|
||||
void *ptr;
|
||||
void *ptr;
|
||||
size_t size;
|
||||
} smallocx_return_t;
|
||||
|
||||
extern smallocx_return_t
|
||||
smallocx(size_t size, int flags);
|
||||
extern smallocx_return_t smallocx(size_t size, int flags);
|
||||
|
||||
static unsigned
|
||||
get_nsizes_impl(const char *cmd) {
|
||||
unsigned ret;
|
||||
size_t z;
|
||||
size_t z;
|
||||
|
||||
z = sizeof(unsigned);
|
||||
expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
|
||||
|
|
@ -45,12 +44,12 @@ get_size_impl(const char *cmd, size_t ind) {
|
|||
size_t miblen = 4;
|
||||
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
mib[2] = ind;
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
|
||||
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -84,36 +83,37 @@ JEMALLOC_DIAGNOSTIC_IGNORE_ALLOC_SIZE_LARGER_THAN
|
|||
TEST_BEGIN(test_overflow) {
|
||||
size_t largemax;
|
||||
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
expect_ptr_null(smallocx(largemax+1, 0).ptr,
|
||||
"Expected OOM for smallocx(size=%#zx, 0)", largemax+1);
|
||||
expect_ptr_null(smallocx(largemax + 1, 0).ptr,
|
||||
"Expected OOM for smallocx(size=%#zx, 0)", largemax + 1);
|
||||
|
||||
expect_ptr_null(smallocx(ZU(PTRDIFF_MAX)+1, 0).ptr,
|
||||
"Expected OOM for smallocx(size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);
|
||||
expect_ptr_null(smallocx(ZU(PTRDIFF_MAX) + 1, 0).ptr,
|
||||
"Expected OOM for smallocx(size=%#zx, 0)", ZU(PTRDIFF_MAX) + 1);
|
||||
|
||||
expect_ptr_null(smallocx(SIZE_T_MAX, 0).ptr,
|
||||
"Expected OOM for smallocx(size=%#zx, 0)", SIZE_T_MAX);
|
||||
|
||||
expect_ptr_null(smallocx(1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX)+1)).ptr,
|
||||
expect_ptr_null(smallocx(1, MALLOCX_ALIGN(ZU(PTRDIFF_MAX) + 1)).ptr,
|
||||
"Expected OOM for smallocx(size=1, MALLOCX_ALIGN(%#zx))",
|
||||
ZU(PTRDIFF_MAX)+1);
|
||||
ZU(PTRDIFF_MAX) + 1);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
static void *
|
||||
remote_alloc(void *arg) {
|
||||
unsigned arena;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
size_t large_sz;
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctl("arenas.lextent.0.size", (void *)&large_sz, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.0.size", (void *)&large_sz, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl failure");
|
||||
|
||||
smallocx_return_t r
|
||||
= smallocx(large_sz, MALLOCX_ARENA(arena) | MALLOCX_TCACHE_NONE);
|
||||
smallocx_return_t r = smallocx(
|
||||
large_sz, MALLOCX_ARENA(arena) | MALLOCX_TCACHE_NONE);
|
||||
void *ptr = r.ptr;
|
||||
expect_zu_eq(r.size,
|
||||
nallocx(large_sz, MALLOCX_ARENA(arena) | MALLOCX_TCACHE_NONE),
|
||||
|
|
@ -138,16 +138,16 @@ TEST_BEGIN(test_remote_free) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_oom) {
|
||||
size_t largemax;
|
||||
bool oom;
|
||||
void *ptrs[3];
|
||||
size_t largemax;
|
||||
bool oom;
|
||||
void *ptrs[3];
|
||||
unsigned i;
|
||||
|
||||
/*
|
||||
* It should be impossible to allocate three objects that each consume
|
||||
* nearly half the virtual address space.
|
||||
*/
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
oom = false;
|
||||
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
|
||||
ptrs[i] = smallocx(largemax, 0).ptr;
|
||||
|
|
@ -167,10 +167,11 @@ TEST_BEGIN(test_oom) {
|
|||
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
expect_ptr_null(smallocx(0x8000000000000000ULL,
|
||||
MALLOCX_ALIGN(0x8000000000000000ULL)).ptr,
|
||||
MALLOCX_ALIGN(0x8000000000000000ULL))
|
||||
.ptr,
|
||||
"Expected OOM for smallocx()");
|
||||
expect_ptr_null(smallocx(0x8000000000000000ULL,
|
||||
MALLOCX_ALIGN(0x80000000)).ptr,
|
||||
expect_ptr_null(
|
||||
smallocx(0x8000000000000000ULL, MALLOCX_ALIGN(0x80000000)).ptr,
|
||||
"Expected OOM for smallocx()");
|
||||
#else
|
||||
expect_ptr_null(smallocx(0x80000000UL, MALLOCX_ALIGN(0x80000000UL)).ptr,
|
||||
|
|
@ -188,15 +189,15 @@ TEST_BEGIN(test_basic) {
|
|||
|
||||
for (sz = 1; sz < MAXSZ; sz = nallocx(sz, 0) + 1) {
|
||||
smallocx_return_t ret;
|
||||
size_t nsz, rsz, smz;
|
||||
void *p;
|
||||
size_t nsz, rsz, smz;
|
||||
void *p;
|
||||
nsz = nallocx(sz, 0);
|
||||
expect_zu_ne(nsz, 0, "Unexpected nallocx() error");
|
||||
ret = smallocx(sz, 0);
|
||||
p = ret.ptr;
|
||||
smz = ret.size;
|
||||
expect_ptr_not_null(p,
|
||||
"Unexpected smallocx(size=%zx, flags=0) error", sz);
|
||||
expect_ptr_not_null(
|
||||
p, "Unexpected smallocx(size=%zx, flags=0) error", sz);
|
||||
rsz = sallocx(p, 0);
|
||||
expect_zu_ge(rsz, sz, "Real size smaller than expected");
|
||||
expect_zu_eq(nsz, rsz, "nallocx()/sallocx() size mismatch");
|
||||
|
|
@ -206,8 +207,8 @@ TEST_BEGIN(test_basic) {
|
|||
ret = smallocx(sz, 0);
|
||||
p = ret.ptr;
|
||||
smz = ret.size;
|
||||
expect_ptr_not_null(p,
|
||||
"Unexpected smallocx(size=%zx, flags=0) error", sz);
|
||||
expect_ptr_not_null(
|
||||
p, "Unexpected smallocx(size=%zx, flags=0) error", sz);
|
||||
dallocx(p, 0);
|
||||
|
||||
nsz = nallocx(sz, MALLOCX_ZERO);
|
||||
|
|
@ -230,58 +231,61 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_alignment_and_size) {
|
||||
const char *percpu_arena;
|
||||
size_t sz = sizeof(percpu_arena);
|
||||
size_t sz = sizeof(percpu_arena);
|
||||
|
||||
if(mallctl("opt.percpu_arena", (void *)&percpu_arena, &sz, NULL, 0) ||
|
||||
strcmp(percpu_arena, "disabled") != 0) {
|
||||
test_skip("test_alignment_and_size skipped: "
|
||||
if (mallctl("opt.percpu_arena", (void *)&percpu_arena, &sz, NULL, 0)
|
||||
|| strcmp(percpu_arena, "disabled") != 0) {
|
||||
test_skip(
|
||||
"test_alignment_and_size skipped: "
|
||||
"not working with percpu arena.");
|
||||
};
|
||||
#define MAXALIGN (((size_t)1) << 23)
|
||||
#define NITER 4
|
||||
size_t nsz, rsz, smz, alignment, total;
|
||||
size_t nsz, rsz, smz, alignment, total;
|
||||
unsigned i;
|
||||
void *ps[NITER];
|
||||
void *ps[NITER];
|
||||
|
||||
for (i = 0; i < NITER; i++) {
|
||||
ps[i] = NULL;
|
||||
}
|
||||
|
||||
for (alignment = 8;
|
||||
alignment <= MAXALIGN;
|
||||
alignment <<= 1) {
|
||||
for (alignment = 8; alignment <= MAXALIGN; alignment <<= 1) {
|
||||
total = 0;
|
||||
for (sz = 1;
|
||||
sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) {
|
||||
for (sz = 1; sz < 3 * alignment && sz < (1U << 31);
|
||||
sz += (alignment >> (LG_SIZEOF_PTR - 1)) - 1) {
|
||||
for (i = 0; i < NITER; i++) {
|
||||
nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
|
||||
MALLOCX_ZERO);
|
||||
nsz = nallocx(sz,
|
||||
MALLOCX_ALIGN(alignment) | MALLOCX_ZERO);
|
||||
expect_zu_ne(nsz, 0,
|
||||
"nallocx() error for alignment=%zu, "
|
||||
"size=%zu (%#zx)", alignment, sz, sz);
|
||||
smallocx_return_t ret
|
||||
= smallocx(sz, MALLOCX_ALIGN(alignment) | MALLOCX_ZERO);
|
||||
"size=%zu (%#zx)",
|
||||
alignment, sz, sz);
|
||||
smallocx_return_t ret = smallocx(sz,
|
||||
MALLOCX_ALIGN(alignment) | MALLOCX_ZERO);
|
||||
ps[i] = ret.ptr;
|
||||
expect_ptr_not_null(ps[i],
|
||||
"smallocx() error for alignment=%zu, "
|
||||
"size=%zu (%#zx)", alignment, sz, sz);
|
||||
"size=%zu (%#zx)",
|
||||
alignment, sz, sz);
|
||||
rsz = sallocx(ps[i], 0);
|
||||
smz = ret.size;
|
||||
expect_zu_ge(rsz, sz,
|
||||
"Real size smaller than expected for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
"alignment=%zu, size=%zu",
|
||||
alignment, sz);
|
||||
expect_zu_eq(nsz, rsz,
|
||||
"nallocx()/sallocx() size mismatch for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
"alignment=%zu, size=%zu",
|
||||
alignment, sz);
|
||||
expect_zu_eq(nsz, smz,
|
||||
"nallocx()/smallocx() size mismatch for "
|
||||
"alignment=%zu, size=%zu", alignment, sz);
|
||||
expect_ptr_null(
|
||||
(void *)((uintptr_t)ps[i] & (alignment-1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu", ps[i],
|
||||
"alignment=%zu, size=%zu",
|
||||
alignment, sz);
|
||||
expect_ptr_null((void *)((uintptr_t)ps[i]
|
||||
& (alignment - 1)),
|
||||
"%p inadequately aligned for"
|
||||
" alignment=%zu, size=%zu",
|
||||
ps[i], alignment, sz);
|
||||
total += rsz;
|
||||
if (total >= (MAXALIGN << 1)) {
|
||||
break;
|
||||
|
|
@ -303,10 +307,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_overflow,
|
||||
test_oom,
|
||||
test_remote_free,
|
||||
test_basic,
|
||||
return test(test_overflow, test_oom, test_remote_free, test_basic,
|
||||
test_alignment_and_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@
|
|||
void *
|
||||
thd_start(void *arg) {
|
||||
unsigned main_arena_ind = *(unsigned *)arg;
|
||||
void *p;
|
||||
void *p;
|
||||
unsigned arena_ind;
|
||||
size_t size;
|
||||
int err;
|
||||
size_t size;
|
||||
int err;
|
||||
|
||||
p = malloc(1);
|
||||
expect_ptr_not_null(p, "Error in malloc()");
|
||||
|
|
@ -16,7 +16,7 @@ thd_start(void *arg) {
|
|||
|
||||
size = sizeof(arena_ind);
|
||||
if ((err = mallctl("thread.arena", (void *)&arena_ind, &size,
|
||||
(void *)&main_arena_ind, sizeof(main_arena_ind)))) {
|
||||
(void *)&main_arena_ind, sizeof(main_arena_ind)))) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(err, buf, sizeof(buf));
|
||||
|
|
@ -24,8 +24,8 @@ thd_start(void *arg) {
|
|||
}
|
||||
|
||||
size = sizeof(arena_ind);
|
||||
if ((err = mallctl("thread.arena", (void *)&arena_ind, &size, NULL,
|
||||
0))) {
|
||||
if ((err = mallctl(
|
||||
"thread.arena", (void *)&arena_ind, &size, NULL, 0))) {
|
||||
char buf[BUFERROR_BUF];
|
||||
|
||||
buferror(err, buf, sizeof(buf));
|
||||
|
|
@ -46,28 +46,28 @@ mallctl_failure(int err) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_thread_arena) {
|
||||
void *p;
|
||||
int err;
|
||||
thd_t thds[NTHREADS];
|
||||
void *p;
|
||||
int err;
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned i;
|
||||
|
||||
p = malloc(1);
|
||||
expect_ptr_not_null(p, "Error in malloc()");
|
||||
|
||||
unsigned arena_ind, old_arena_ind;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0),
|
||||
0, "Arena creation failure");
|
||||
|
||||
size_t size = sizeof(arena_ind);
|
||||
if ((err = mallctl("thread.arena", (void *)&old_arena_ind, &size,
|
||||
(void *)&arena_ind, sizeof(arena_ind))) != 0) {
|
||||
(void *)&arena_ind, sizeof(arena_ind)))
|
||||
!= 0) {
|
||||
mallctl_failure(err);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
thd_create(&thds[i], thd_start,
|
||||
(void *)&arena_ind);
|
||||
thd_create(&thds[i], thd_start, (void *)&arena_ind);
|
||||
}
|
||||
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
|
|
@ -81,6 +81,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_thread_arena);
|
||||
return test(test_thread_arena);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,60 +2,69 @@
|
|||
|
||||
void *
|
||||
thd_start(void *arg) {
|
||||
bool e0, e1;
|
||||
bool e0, e1;
|
||||
size_t sz = sizeof(bool);
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl failure");
|
||||
|
||||
if (e0) {
|
||||
e1 = false;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
(void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_true(e0, "tcache should be enabled");
|
||||
}
|
||||
|
||||
e1 = true;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_false(e0, "tcache should be disabled");
|
||||
|
||||
e1 = true;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_true(e0, "tcache should be enabled");
|
||||
|
||||
e1 = false;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_true(e0, "tcache should be enabled");
|
||||
|
||||
e1 = false;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_false(e0, "tcache should be disabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = true;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_false(e0, "tcache should be disabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = true;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_true(e0, "tcache should be enabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = false;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_true(e0, "tcache should be enabled");
|
||||
|
||||
free(malloc(1));
|
||||
e1 = false;
|
||||
expect_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
|
||||
(void *)&e1, sz), 0, "Unexpected mallctl() error");
|
||||
expect_d_eq(
|
||||
mallctl("thread.tcache.enabled", (void *)&e0, &sz, (void *)&e1, sz),
|
||||
0, "Unexpected mallctl() error");
|
||||
expect_false(e0, "tcache should be disabled");
|
||||
|
||||
free(malloc(1));
|
||||
|
|
@ -78,10 +87,6 @@ TEST_END
|
|||
int
|
||||
main(void) {
|
||||
/* Run tests multiple times to check for bad interactions. */
|
||||
return test(
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread,
|
||||
test_subthread,
|
||||
test_main_thread);
|
||||
return test(test_main_thread, test_subthread, test_main_thread,
|
||||
test_subthread, test_main_thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,15 +11,16 @@ arena_ind(void) {
|
|||
|
||||
if (ind == 0) {
|
||||
size_t sz = sizeof(ind);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&ind, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl failure creating arena");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.create", (void *)&ind, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl failure creating arena");
|
||||
}
|
||||
|
||||
return ind;
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_same_size) {
|
||||
void *p;
|
||||
void *p;
|
||||
size_t sz, tsz;
|
||||
|
||||
p = mallocx(42, 0);
|
||||
|
|
@ -34,14 +35,14 @@ TEST_BEGIN(test_same_size) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_extra_no_move) {
|
||||
void *p;
|
||||
void *p;
|
||||
size_t sz, tsz;
|
||||
|
||||
p = mallocx(42, 0);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
sz = sallocx(p, 0);
|
||||
|
||||
tsz = xallocx(p, sz, sz-42, 0);
|
||||
tsz = xallocx(p, sz, sz - 42, 0);
|
||||
expect_zu_eq(tsz, sz, "Unexpected size change: %zu --> %zu", sz, tsz);
|
||||
|
||||
dallocx(p, 0);
|
||||
|
|
@ -49,7 +50,7 @@ TEST_BEGIN(test_extra_no_move) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_no_move_fail) {
|
||||
void *p;
|
||||
void *p;
|
||||
size_t sz, tsz;
|
||||
|
||||
p = mallocx(42, 0);
|
||||
|
|
@ -66,7 +67,7 @@ TEST_END
|
|||
static unsigned
|
||||
get_nsizes_impl(const char *cmd) {
|
||||
unsigned ret;
|
||||
size_t z;
|
||||
size_t z;
|
||||
|
||||
z = sizeof(unsigned);
|
||||
expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
|
||||
|
|
@ -93,12 +94,12 @@ get_size_impl(const char *cmd, size_t ind) {
|
|||
size_t miblen = 4;
|
||||
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
mib[2] = ind;
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
|
||||
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -115,25 +116,25 @@ get_large_size(size_t ind) {
|
|||
|
||||
TEST_BEGIN(test_size) {
|
||||
size_t small0, largemax;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
/* Get size classes. */
|
||||
small0 = get_small_size(0);
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
p = mallocx(small0, 0);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
||||
/* Test smallest supported size. */
|
||||
expect_zu_eq(xallocx(p, 1, 0, 0), small0,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_eq(
|
||||
xallocx(p, 1, 0, 0), small0, "Unexpected xallocx() behavior");
|
||||
|
||||
/* Test largest supported size. */
|
||||
expect_zu_le(xallocx(p, largemax, 0, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
|
||||
/* Test size overflow. */
|
||||
expect_zu_le(xallocx(p, largemax+1, 0, 0), largemax,
|
||||
expect_zu_le(xallocx(p, largemax + 1, 0, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_le(xallocx(p, SIZE_T_MAX, 0, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
|
|
@ -144,29 +145,29 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_size_extra_overflow) {
|
||||
size_t small0, largemax;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
/* Get size classes. */
|
||||
small0 = get_small_size(0);
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
p = mallocx(small0, 0);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
||||
/* Test overflows that can be resolved by clamping extra. */
|
||||
expect_zu_le(xallocx(p, largemax-1, 2, 0), largemax,
|
||||
expect_zu_le(xallocx(p, largemax - 1, 2, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_le(xallocx(p, largemax, 1, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
|
||||
/* Test overflow such that largemax-size underflows. */
|
||||
expect_zu_le(xallocx(p, largemax+1, 2, 0), largemax,
|
||||
expect_zu_le(xallocx(p, largemax + 1, 2, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_le(xallocx(p, largemax+2, 3, 0), largemax,
|
||||
expect_zu_le(xallocx(p, largemax + 2, 3, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_le(xallocx(p, SIZE_T_MAX-2, 2, 0), largemax,
|
||||
expect_zu_le(xallocx(p, SIZE_T_MAX - 2, 2, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_le(xallocx(p, SIZE_T_MAX-1, 1, 0), largemax,
|
||||
expect_zu_le(xallocx(p, SIZE_T_MAX - 1, 1, 0), largemax,
|
||||
"Unexpected xallocx() behavior");
|
||||
|
||||
dallocx(p, 0);
|
||||
|
|
@ -175,21 +176,21 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_extra_small) {
|
||||
size_t small0, small1, largemax;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
/* Get size classes. */
|
||||
small0 = get_small_size(0);
|
||||
small1 = get_small_size(1);
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
p = mallocx(small0, 0);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
||||
expect_zu_eq(xallocx(p, small1, 0, 0), small0,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_eq(
|
||||
xallocx(p, small1, 0, 0), small0, "Unexpected xallocx() behavior");
|
||||
|
||||
expect_zu_eq(xallocx(p, small1, 0, 0), small0,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_eq(
|
||||
xallocx(p, small1, 0, 0), small0, "Unexpected xallocx() behavior");
|
||||
|
||||
expect_zu_eq(xallocx(p, small0, small1 - small0, 0), small0,
|
||||
"Unexpected xallocx() behavior");
|
||||
|
|
@ -205,16 +206,16 @@ TEST_BEGIN(test_extra_small) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_extra_large) {
|
||||
int flags = MALLOCX_ARENA(arena_ind());
|
||||
int flags = MALLOCX_ARENA(arena_ind());
|
||||
size_t smallmax, large1, large2, large3, largemax;
|
||||
void *p;
|
||||
void *p;
|
||||
|
||||
/* Get size classes. */
|
||||
smallmax = get_small_size(get_nsmall()-1);
|
||||
smallmax = get_small_size(get_nsmall() - 1);
|
||||
large1 = get_large_size(1);
|
||||
large2 = get_large_size(2);
|
||||
large3 = get_large_size(3);
|
||||
largemax = get_large_size(get_nlarge()-1);
|
||||
largemax = get_large_size(get_nlarge() - 1);
|
||||
|
||||
p = mallocx(large3, flags);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
|
|
@ -246,7 +247,7 @@ TEST_BEGIN(test_extra_large) {
|
|||
/* Test size increase with zero extra. */
|
||||
expect_zu_le(xallocx(p, large3, 0, flags), large3,
|
||||
"Unexpected xallocx() behavior");
|
||||
expect_zu_le(xallocx(p, largemax+1, 0, flags), large3,
|
||||
expect_zu_le(xallocx(p, largemax + 1, 0, flags), large3,
|
||||
"Unexpected xallocx() behavior");
|
||||
|
||||
expect_zu_ge(xallocx(p, large1, 0, flags), large1,
|
||||
|
|
@ -276,8 +277,8 @@ TEST_END
|
|||
static void
|
||||
print_filled_extents(const void *p, uint8_t c, size_t len) {
|
||||
const uint8_t *pc = (const uint8_t *)p;
|
||||
size_t i, range0;
|
||||
uint8_t c0;
|
||||
size_t i, range0;
|
||||
uint8_t c0;
|
||||
|
||||
malloc_printf(" p=%p, c=%#x, len=%zu:", p, c, len);
|
||||
range0 = 0;
|
||||
|
|
@ -295,10 +296,10 @@ print_filled_extents(const void *p, uint8_t c, size_t len) {
|
|||
static bool
|
||||
validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
|
||||
const uint8_t *pc = (const uint8_t *)p;
|
||||
bool err;
|
||||
size_t i;
|
||||
bool err;
|
||||
size_t i;
|
||||
|
||||
for (i = offset, err = false; i < offset+len; i++) {
|
||||
for (i = offset, err = false; i < offset + len; i++) {
|
||||
if (pc[i] != c) {
|
||||
err = true;
|
||||
}
|
||||
|
|
@ -313,16 +314,16 @@ validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
|
|||
|
||||
static void
|
||||
test_zero(size_t szmin, size_t szmax) {
|
||||
int flags = MALLOCX_ARENA(arena_ind()) | MALLOCX_ZERO;
|
||||
int flags = MALLOCX_ARENA(arena_ind()) | MALLOCX_ZERO;
|
||||
size_t sz, nsz;
|
||||
void *p;
|
||||
void *p;
|
||||
#define FILL_BYTE 0x7aU
|
||||
|
||||
sz = szmax;
|
||||
p = mallocx(sz, flags);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() error");
|
||||
expect_false(validate_fill(p, 0x00, 0, sz), "Memory not filled: sz=%zu",
|
||||
sz);
|
||||
expect_false(
|
||||
validate_fill(p, 0x00, 0, sz), "Memory not filled: sz=%zu", sz);
|
||||
|
||||
/*
|
||||
* Fill with non-zero so that non-debug builds are more likely to detect
|
||||
|
|
@ -342,16 +343,16 @@ test_zero(size_t szmin, size_t szmax) {
|
|||
"Memory not filled: sz=%zu", sz);
|
||||
|
||||
for (sz = szmin; sz < szmax; sz = nsz) {
|
||||
nsz = nallocx(sz+1, flags);
|
||||
if (xallocx(p, sz+1, 0, flags) != nsz) {
|
||||
p = rallocx(p, sz+1, flags);
|
||||
nsz = nallocx(sz + 1, flags);
|
||||
if (xallocx(p, sz + 1, 0, flags) != nsz) {
|
||||
p = rallocx(p, sz + 1, flags);
|
||||
expect_ptr_not_null(p, "Unexpected rallocx() failure");
|
||||
}
|
||||
expect_false(validate_fill(p, FILL_BYTE, 0, sz),
|
||||
"Memory not filled: sz=%zu", sz);
|
||||
expect_false(validate_fill(p, 0x00, sz, nsz-sz),
|
||||
"Memory not filled: sz=%zu, nsz-sz=%zu", sz, nsz-sz);
|
||||
memset((void *)((uintptr_t)p + sz), FILL_BYTE, nsz-sz);
|
||||
expect_false(validate_fill(p, 0x00, sz, nsz - sz),
|
||||
"Memory not filled: sz=%zu, nsz-sz=%zu", sz, nsz - sz);
|
||||
memset((void *)((uintptr_t)p + sz), FILL_BYTE, nsz - sz);
|
||||
expect_false(validate_fill(p, FILL_BYTE, 0, nsz),
|
||||
"Memory not filled: nsz=%zu", nsz);
|
||||
}
|
||||
|
|
@ -372,13 +373,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_same_size,
|
||||
test_extra_no_move,
|
||||
test_no_move_fail,
|
||||
test_size,
|
||||
test_size_extra_overflow,
|
||||
test_extra_small,
|
||||
test_extra_large,
|
||||
test_zero_large);
|
||||
return test(test_same_size, test_extra_no_move, test_no_move_fail,
|
||||
test_size, test_size_extra_overflow, test_extra_small,
|
||||
test_extra_large, test_zero_large);
|
||||
}
|
||||
|
|
|
|||
739
test/src/SFMT.c
739
test/src/SFMT.c
|
|
@ -50,19 +50,19 @@
|
|||
#include "test/SFMT-params.h"
|
||||
|
||||
#if defined(JEMALLOC_BIG_ENDIAN) && !defined(BIG_ENDIAN64)
|
||||
#define BIG_ENDIAN64 1
|
||||
# define BIG_ENDIAN64 1
|
||||
#endif
|
||||
#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
|
||||
#define BIG_ENDIAN64 1
|
||||
# define BIG_ENDIAN64 1
|
||||
#endif
|
||||
#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
|
||||
#define BIG_ENDIAN64 1
|
||||
# define BIG_ENDIAN64 1
|
||||
#endif
|
||||
#if defined(ONLY64) && !defined(BIG_ENDIAN64)
|
||||
#if defined(__GNUC__)
|
||||
#error "-DONLY64 must be specified with -DBIG_ENDIAN64"
|
||||
#endif
|
||||
#undef ONLY64
|
||||
# if defined(__GNUC__)
|
||||
# error "-DONLY64 must be specified with -DBIG_ENDIAN64"
|
||||
# endif
|
||||
# undef ONLY64
|
||||
#endif
|
||||
/*------------------------------------------------------
|
||||
128-bit SIMD data type for Altivec, SSE2 or standard C
|
||||
|
|
@ -70,8 +70,8 @@
|
|||
#if defined(HAVE_ALTIVEC)
|
||||
/** 128-bit data structure */
|
||||
union W128_T {
|
||||
vector unsigned int s;
|
||||
uint32_t u[4];
|
||||
vector unsigned int s;
|
||||
uint32_t u[4];
|
||||
};
|
||||
/** 128-bit data type */
|
||||
typedef union W128_T w128_t;
|
||||
|
|
@ -79,8 +79,8 @@ typedef union W128_T w128_t;
|
|||
#elif defined(HAVE_SSE2)
|
||||
/** 128-bit data structure */
|
||||
union W128_T {
|
||||
__m128i si;
|
||||
uint32_t u[4];
|
||||
__m128i si;
|
||||
uint32_t u[4];
|
||||
};
|
||||
/** 128-bit data type */
|
||||
typedef union W128_T w128_t;
|
||||
|
|
@ -89,7 +89,7 @@ typedef union W128_T w128_t;
|
|||
|
||||
/** 128-bit data structure */
|
||||
struct W128_T {
|
||||
uint32_t u[4];
|
||||
uint32_t u[4];
|
||||
};
|
||||
/** 128-bit data type */
|
||||
typedef struct W128_T w128_t;
|
||||
|
|
@ -97,13 +97,13 @@ typedef struct W128_T w128_t;
|
|||
#endif
|
||||
|
||||
struct sfmt_s {
|
||||
/** the 128-bit internal state array */
|
||||
w128_t sfmt[N];
|
||||
/** index counter to the 32-bit internal state array */
|
||||
int idx;
|
||||
/** a flag: it is 0 if and only if the internal state is not yet
|
||||
/** the 128-bit internal state array */
|
||||
w128_t sfmt[N];
|
||||
/** index counter to the 32-bit internal state array */
|
||||
int idx;
|
||||
/** a flag: it is 0 if and only if the internal state is not yet
|
||||
* initialized. */
|
||||
int initialized;
|
||||
int initialized;
|
||||
};
|
||||
|
||||
/*--------------------------------------
|
||||
|
|
@ -119,22 +119,22 @@ static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
|
|||
----------------*/
|
||||
static inline int idxof(int i);
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift);
|
||||
#endif
|
||||
static inline void gen_rand_all(sfmt_t *ctx);
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size);
|
||||
static inline void gen_rand_all(sfmt_t *ctx);
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size);
|
||||
static inline uint32_t func1(uint32_t x);
|
||||
static inline uint32_t func2(uint32_t x);
|
||||
static void period_certification(sfmt_t *ctx);
|
||||
static void period_certification(sfmt_t *ctx);
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
static inline void swap(w128_t *array, int size);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ALTIVEC)
|
||||
#include "test/SFMT-alti.h"
|
||||
# include "test/SFMT-alti.h"
|
||||
#elif defined(HAVE_SSE2)
|
||||
#include "test/SFMT-sse2.h"
|
||||
# include "test/SFMT-sse2.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -142,12 +142,14 @@ static inline void swap(w128_t *array, int size);
|
|||
* in BIG ENDIAN machine.
|
||||
*/
|
||||
#ifdef ONLY64
|
||||
static inline int idxof(int i) {
|
||||
return i ^ 1;
|
||||
static inline int
|
||||
idxof(int i) {
|
||||
return i ^ 1;
|
||||
}
|
||||
#else
|
||||
static inline int idxof(int i) {
|
||||
return i;
|
||||
static inline int
|
||||
idxof(int i) {
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
|
|
@ -159,37 +161,39 @@ static inline int idxof(int i) {
|
|||
* @param shift the shift value
|
||||
*/
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
#ifdef ONLY64
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# ifdef ONLY64
|
||||
static inline void
|
||||
rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
}
|
||||
#else
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# else
|
||||
static inline void
|
||||
rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
/**
|
||||
* This function simulates SIMD 128-bit left shift by the standard C.
|
||||
* The 128-bit integer given in in is shifted by (shift * 8) bits.
|
||||
|
|
@ -198,37 +202,39 @@ static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
|||
* @param in the 128-bit data to be shifted
|
||||
* @param shift the shift value
|
||||
*/
|
||||
#ifdef ONLY64
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# ifdef ONLY64
|
||||
static inline void
|
||||
lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
}
|
||||
#else
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# else
|
||||
static inline void
|
||||
lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -240,41 +246,41 @@ static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
|||
* @param d a 128-bit part of the internal state array
|
||||
*/
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
#ifdef ONLY64
|
||||
static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
# ifdef ONLY64
|
||||
static inline void
|
||||
do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
}
|
||||
#else
|
||||
static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
# else
|
||||
static inline void
|
||||
do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
|
|
@ -282,24 +288,25 @@ static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
|||
* This function fills the internal state array with pseudorandom
|
||||
* integers.
|
||||
*/
|
||||
static inline void gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
w128_t *r1, *r2;
|
||||
static inline void
|
||||
gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
w128_t *r1, *r2;
|
||||
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(&ctx->sfmt[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1,
|
||||
r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(&ctx->sfmt[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1 - N], r1,
|
||||
r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(
|
||||
&ctx->sfmt[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(&ctx->sfmt[i], &ctx->sfmt[i],
|
||||
&ctx->sfmt[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,52 +316,58 @@ static inline void gen_rand_all(sfmt_t *ctx) {
|
|||
* @param array an 128-bit array to be filled by pseudorandom numbers.
|
||||
* @param size number of 128-bit pseudorandom numbers to be generated.
|
||||
*/
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
w128_t *r1, *r2;
|
||||
static inline void
|
||||
gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
w128_t *r1, *r2;
|
||||
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(&array[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(&array[i], &ctx->sfmt[i], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < size - N; i++) {
|
||||
do_recursion(&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
ctx->sfmt[j] = array[j + size - N];
|
||||
}
|
||||
for (; i < size; i++, j++) {
|
||||
do_recursion(&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
ctx->sfmt[j] = array[i];
|
||||
}
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(
|
||||
&array[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(
|
||||
&array[i], &ctx->sfmt[i], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < size - N; i++) {
|
||||
do_recursion(
|
||||
&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
ctx->sfmt[j] = array[j + size - N];
|
||||
}
|
||||
for (; i < size; i++, j++) {
|
||||
do_recursion(
|
||||
&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
ctx->sfmt[j] = array[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
|
||||
static inline void swap(w128_t *array, int size) {
|
||||
int i;
|
||||
uint32_t x, y;
|
||||
static inline void
|
||||
swap(w128_t *array, int size) {
|
||||
int i;
|
||||
uint32_t x, y;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
x = array[i].u[0];
|
||||
y = array[i].u[2];
|
||||
array[i].u[0] = array[i].u[1];
|
||||
array[i].u[2] = array[i].u[3];
|
||||
array[i].u[1] = x;
|
||||
array[i].u[3] = y;
|
||||
}
|
||||
for (i = 0; i < size; i++) {
|
||||
x = array[i].u[0];
|
||||
y = array[i].u[2];
|
||||
array[i].u[0] = array[i].u[1];
|
||||
array[i].u[2] = array[i].u[3];
|
||||
array[i].u[1] = x;
|
||||
array[i].u[3] = y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
|
|
@ -363,8 +376,9 @@ static inline void swap(w128_t *array, int size) {
|
|||
* @param x 32-bit integer
|
||||
* @return 32-bit integer
|
||||
*/
|
||||
static uint32_t func1(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1664525UL;
|
||||
static uint32_t
|
||||
func1(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1664525UL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -373,39 +387,41 @@ static uint32_t func1(uint32_t x) {
|
|||
* @param x 32-bit integer
|
||||
* @return 32-bit integer
|
||||
*/
|
||||
static uint32_t func2(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
|
||||
static uint32_t
|
||||
func2(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function certificate the period of 2^{MEXP}
|
||||
*/
|
||||
static void period_certification(sfmt_t *ctx) {
|
||||
int inner = 0;
|
||||
int i, j;
|
||||
uint32_t work;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
static void
|
||||
period_certification(sfmt_t *ctx) {
|
||||
int inner = 0;
|
||||
int i, j;
|
||||
uint32_t work;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
inner ^= psfmt32[idxof(i)] & parity[i];
|
||||
for (i = 16; i > 0; i >>= 1)
|
||||
inner ^= inner >> i;
|
||||
inner &= 1;
|
||||
/* check OK */
|
||||
if (inner == 1) {
|
||||
return;
|
||||
}
|
||||
/* check NG, and modification */
|
||||
for (i = 0; i < 4; i++) {
|
||||
work = 1;
|
||||
for (j = 0; j < 32; j++) {
|
||||
if ((work & parity[i]) != 0) {
|
||||
psfmt32[idxof(i)] ^= work;
|
||||
for (i = 0; i < 4; i++)
|
||||
inner ^= psfmt32[idxof(i)] & parity[i];
|
||||
for (i = 16; i > 0; i >>= 1)
|
||||
inner ^= inner >> i;
|
||||
inner &= 1;
|
||||
/* check OK */
|
||||
if (inner == 1) {
|
||||
return;
|
||||
}
|
||||
work = work << 1;
|
||||
}
|
||||
}
|
||||
/* check NG, and modification */
|
||||
for (i = 0; i < 4; i++) {
|
||||
work = 1;
|
||||
for (j = 0; j < 32; j++) {
|
||||
if ((work & parity[i]) != 0) {
|
||||
psfmt32[idxof(i)] ^= work;
|
||||
return;
|
||||
}
|
||||
work = work << 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------
|
||||
|
|
@ -416,8 +432,9 @@ static void period_certification(sfmt_t *ctx) {
|
|||
* The string shows the word size, the Mersenne exponent,
|
||||
* and all parameters of this generator.
|
||||
*/
|
||||
const char *get_idstring(void) {
|
||||
return IDSTR;
|
||||
const char *
|
||||
get_idstring(void) {
|
||||
return IDSTR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -425,8 +442,9 @@ const char *get_idstring(void) {
|
|||
* fill_array32() function.
|
||||
* @return minimum size of array used for fill_array32() function.
|
||||
*/
|
||||
int get_min_array_size32(void) {
|
||||
return N32;
|
||||
int
|
||||
get_min_array_size32(void) {
|
||||
return N32;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -434,8 +452,9 @@ int get_min_array_size32(void) {
|
|||
* fill_array64() function.
|
||||
* @return minimum size of array used for fill_array64() function.
|
||||
*/
|
||||
int get_min_array_size64(void) {
|
||||
return N64;
|
||||
int
|
||||
get_min_array_size64(void) {
|
||||
return N64;
|
||||
}
|
||||
|
||||
#ifndef ONLY64
|
||||
|
|
@ -444,32 +463,34 @@ int get_min_array_size64(void) {
|
|||
* init_gen_rand or init_by_array must be called before this function.
|
||||
* @return 32-bit pseudorandom number
|
||||
*/
|
||||
uint32_t gen_rand32(sfmt_t *ctx) {
|
||||
uint32_t r;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
uint32_t
|
||||
gen_rand32(sfmt_t *ctx) {
|
||||
uint32_t r;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
assert(ctx->initialized);
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
r = psfmt32[ctx->idx++];
|
||||
return r;
|
||||
assert(ctx->initialized);
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
r = psfmt32[ctx->idx++];
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Generate a random integer in [0..limit). */
|
||||
uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
||||
uint32_t ret, above;
|
||||
uint32_t
|
||||
gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
||||
uint32_t ret, above;
|
||||
|
||||
above = 0xffffffffU - (0xffffffffU % limit);
|
||||
while (1) {
|
||||
ret = gen_rand32(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
above = 0xffffffffU - (0xffffffffU % limit);
|
||||
while (1) {
|
||||
ret = gen_rand32(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
|
|
@ -479,47 +500,49 @@ uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
|||
* unless an initialization is again executed.
|
||||
* @return 64-bit pseudorandom number
|
||||
*/
|
||||
uint64_t gen_rand64(sfmt_t *ctx) {
|
||||
uint64_t
|
||||
gen_rand64(sfmt_t *ctx) {
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
uint32_t r1, r2;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
uint32_t r1, r2;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
#else
|
||||
uint64_t r;
|
||||
uint64_t *psfmt64 = (uint64_t *)&ctx->sfmt[0].u[0];
|
||||
uint64_t r;
|
||||
uint64_t *psfmt64 = (uint64_t *)&ctx->sfmt[0].u[0];
|
||||
#endif
|
||||
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx % 2 == 0);
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx % 2 == 0);
|
||||
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
r1 = psfmt32[ctx->idx];
|
||||
r2 = psfmt32[ctx->idx + 1];
|
||||
ctx->idx += 2;
|
||||
return ((uint64_t)r2 << 32) | r1;
|
||||
r1 = psfmt32[ctx->idx];
|
||||
r2 = psfmt32[ctx->idx + 1];
|
||||
ctx->idx += 2;
|
||||
return ((uint64_t)r2 << 32) | r1;
|
||||
#else
|
||||
r = psfmt64[ctx->idx / 2];
|
||||
ctx->idx += 2;
|
||||
return r;
|
||||
r = psfmt64[ctx->idx / 2];
|
||||
ctx->idx += 2;
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Generate a random integer in [0..limit). */
|
||||
uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit) {
|
||||
uint64_t ret, above;
|
||||
uint64_t
|
||||
gen_rand64_range(sfmt_t *ctx, uint64_t limit) {
|
||||
uint64_t ret, above;
|
||||
|
||||
above = KQU(0xffffffffffffffff) - (KQU(0xffffffffffffffff) % limit);
|
||||
while (1) {
|
||||
ret = gen_rand64(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
above = KQU(0xffffffffffffffff) - (KQU(0xffffffffffffffff) % limit);
|
||||
while (1) {
|
||||
ret = gen_rand64(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef ONLY64
|
||||
|
|
@ -548,14 +571,15 @@ uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit) {
|
|||
* memory. Mac OSX doesn't have these functions, but \b malloc of OSX
|
||||
* returns the pointer to the aligned memory block.
|
||||
*/
|
||||
void fill_array32(sfmt_t *ctx, uint32_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 4 == 0);
|
||||
assert(size >= N32);
|
||||
void
|
||||
fill_array32(sfmt_t *ctx, uint32_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 4 == 0);
|
||||
assert(size >= N32);
|
||||
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 4);
|
||||
ctx->idx = N32;
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 4);
|
||||
ctx->idx = N32;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -584,17 +608,18 @@ void fill_array32(sfmt_t *ctx, uint32_t *array, int size) {
|
|||
* memory. Mac OSX doesn't have these functions, but \b malloc of OSX
|
||||
* returns the pointer to the aligned memory block.
|
||||
*/
|
||||
void fill_array64(sfmt_t *ctx, uint64_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 2 == 0);
|
||||
assert(size >= N64);
|
||||
void
|
||||
fill_array64(sfmt_t *ctx, uint64_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 2 == 0);
|
||||
assert(size >= N64);
|
||||
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 2);
|
||||
ctx->idx = N32;
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 2);
|
||||
ctx->idx = N32;
|
||||
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
swap((w128_t *)array, size /2);
|
||||
swap((w128_t *)array, size / 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -604,29 +629,31 @@ void fill_array64(sfmt_t *ctx, uint64_t *array, int size) {
|
|||
*
|
||||
* @param seed a 32-bit integer used as the seed.
|
||||
*/
|
||||
sfmt_t *init_gen_rand(uint32_t seed) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i;
|
||||
uint32_t *psfmt32;
|
||||
sfmt_t *
|
||||
init_gen_rand(uint32_t seed) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i;
|
||||
uint32_t *psfmt32;
|
||||
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
psfmt32[idxof(0)] = seed;
|
||||
for (i = 1; i < N32; i++) {
|
||||
psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)]
|
||||
^ (psfmt32[idxof(i - 1)] >> 30))
|
||||
+ i;
|
||||
}
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
psfmt32[idxof(0)] = seed;
|
||||
for (i = 1; i < N32; i++) {
|
||||
psfmt32[idxof(i)] = 1812433253UL
|
||||
* (psfmt32[idxof(i - 1)]
|
||||
^ (psfmt32[idxof(i - 1)] >> 30))
|
||||
+ i;
|
||||
}
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
|
||||
return ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -635,85 +662,87 @@ sfmt_t *init_gen_rand(uint32_t seed) {
|
|||
* @param init_key the array of 32-bit integers, used as a seed.
|
||||
* @param key_length the length of init_key.
|
||||
*/
|
||||
sfmt_t *init_by_array(uint32_t *init_key, int key_length) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i, j, count;
|
||||
uint32_t r;
|
||||
int lag;
|
||||
int mid;
|
||||
int size = N * 4;
|
||||
uint32_t *psfmt32;
|
||||
sfmt_t *
|
||||
init_by_array(uint32_t *init_key, int key_length) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i, j, count;
|
||||
uint32_t r;
|
||||
int lag;
|
||||
int mid;
|
||||
int size = N * 4;
|
||||
uint32_t *psfmt32;
|
||||
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
if (size >= 623) {
|
||||
lag = 11;
|
||||
} else if (size >= 68) {
|
||||
lag = 7;
|
||||
} else if (size >= 39) {
|
||||
lag = 5;
|
||||
} else {
|
||||
lag = 3;
|
||||
}
|
||||
mid = (size - lag) / 2;
|
||||
if (size >= 623) {
|
||||
lag = 11;
|
||||
} else if (size >= 68) {
|
||||
lag = 7;
|
||||
} else if (size >= 39) {
|
||||
lag = 5;
|
||||
} else {
|
||||
lag = 3;
|
||||
}
|
||||
mid = (size - lag) / 2;
|
||||
|
||||
memset(ctx->sfmt, 0x8b, sizeof(ctx->sfmt));
|
||||
if (key_length + 1 > N32) {
|
||||
count = key_length + 1;
|
||||
} else {
|
||||
count = N32;
|
||||
}
|
||||
r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)]
|
||||
^ psfmt32[idxof(N32 - 1)]);
|
||||
psfmt32[idxof(mid)] += r;
|
||||
r += key_length;
|
||||
psfmt32[idxof(mid + lag)] += r;
|
||||
psfmt32[idxof(0)] = r;
|
||||
memset(ctx->sfmt, 0x8b, sizeof(ctx->sfmt));
|
||||
if (key_length + 1 > N32) {
|
||||
count = key_length + 1;
|
||||
} else {
|
||||
count = N32;
|
||||
}
|
||||
r = func1(
|
||||
psfmt32[idxof(0)] ^ psfmt32[idxof(mid)] ^ psfmt32[idxof(N32 - 1)]);
|
||||
psfmt32[idxof(mid)] += r;
|
||||
r += key_length;
|
||||
psfmt32[idxof(mid + lag)] += r;
|
||||
psfmt32[idxof(0)] = r;
|
||||
|
||||
count--;
|
||||
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += init_key[j] + i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (; j < count; j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (j = 0; j < N32; j++) {
|
||||
r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)]
|
||||
+ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] ^= r;
|
||||
r -= i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] ^= r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
count--;
|
||||
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += init_key[j] + i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (; j < count; j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (j = 0; j < N32; j++) {
|
||||
r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)]
|
||||
+ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] ^= r;
|
||||
r -= i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] ^= r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
|
||||
return ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void fini_gen_rand(sfmt_t *ctx) {
|
||||
assert(ctx != NULL);
|
||||
void
|
||||
fini_gen_rand(sfmt_t *ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
ctx->initialized = 0;
|
||||
free(ctx);
|
||||
ctx->initialized = 0;
|
||||
free(ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(_CRT_SPINCOUNT)
|
||||
#define _CRT_SPINCOUNT 4000
|
||||
# define _CRT_SPINCOUNT 4000
|
||||
#endif
|
||||
|
||||
bool
|
||||
mtx_init(mtx_t *mtx) {
|
||||
#ifdef _WIN32
|
||||
if (!InitializeCriticalSectionAndSpinCount(&mtx->lock,
|
||||
_CRT_SPINCOUNT)) {
|
||||
if (!InitializeCriticalSectionAndSpinCount(
|
||||
&mtx->lock, _CRT_SPINCOUNT)) {
|
||||
return true;
|
||||
}
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
void
|
||||
sleep_ns(unsigned ns) {
|
||||
assert(ns <= 1000*1000*1000);
|
||||
assert(ns <= 1000 * 1000 * 1000);
|
||||
|
||||
#ifdef _WIN32
|
||||
Sleep(ns / 1000 / 1000);
|
||||
|
|
@ -14,7 +14,7 @@ sleep_ns(unsigned ns) {
|
|||
{
|
||||
struct timespec timeout;
|
||||
|
||||
if (ns < 1000*1000*1000) {
|
||||
if (ns < 1000 * 1000 * 1000) {
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_nsec = ns;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
/* Test status state. */
|
||||
|
||||
static unsigned test_count = 0;
|
||||
static test_status_t test_counts[test_status_count] = {0, 0, 0};
|
||||
static test_status_t test_status = test_status_pass;
|
||||
static const char * test_name = "";
|
||||
static unsigned test_count = 0;
|
||||
static test_status_t test_counts[test_status_count] = {0, 0, 0};
|
||||
static test_status_t test_status = test_status_pass;
|
||||
static const char *test_name = "";
|
||||
|
||||
/* Reentrancy testing helpers. */
|
||||
|
||||
|
|
@ -89,10 +89,14 @@ test_fail(const char *format, ...) {
|
|||
static const char *
|
||||
test_status_string(test_status_t current_status) {
|
||||
switch (current_status) {
|
||||
case test_status_pass: return "pass";
|
||||
case test_status_skip: return "skip";
|
||||
case test_status_fail: return "fail";
|
||||
default: not_reached();
|
||||
case test_status_pass:
|
||||
return "pass";
|
||||
case test_status_skip:
|
||||
return "skip";
|
||||
case test_status_fail:
|
||||
return "fail";
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,19 +177,16 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||
}
|
||||
}
|
||||
|
||||
bool colored = test_counts[test_status_fail] != 0 &&
|
||||
isatty(STDERR_FILENO);
|
||||
bool colored = test_counts[test_status_fail] != 0
|
||||
&& isatty(STDERR_FILENO);
|
||||
const char *color_start = colored ? "\033[1;31m" : "";
|
||||
const char *color_end = colored ? "\033[0m" : "";
|
||||
malloc_printf("%s--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n%s",
|
||||
color_start,
|
||||
test_status_string(test_status_pass),
|
||||
color_start, test_status_string(test_status_pass),
|
||||
test_counts[test_status_pass], test_count,
|
||||
test_status_string(test_status_skip),
|
||||
test_counts[test_status_skip], test_count,
|
||||
test_status_string(test_status_fail),
|
||||
test_counts[test_status_fail], test_count,
|
||||
color_end);
|
||||
test_status_string(test_status_skip), test_counts[test_status_skip],
|
||||
test_count, test_status_string(test_status_fail),
|
||||
test_counts[test_status_fail], test_count, color_end);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -193,7 +194,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||
test_status_t
|
||||
p_test(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
|
|
@ -206,7 +207,7 @@ p_test(test_t *t, ...) {
|
|||
test_status_t
|
||||
p_test_no_reentrancy(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
|
|
@ -219,7 +220,7 @@ p_test_no_reentrancy(test_t *t, ...) {
|
|||
test_status_t
|
||||
p_test_no_malloc_init(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
|
|
@ -235,12 +236,12 @@ p_test_no_malloc_init(test_t *t, ...) {
|
|||
|
||||
void
|
||||
p_test_fail(bool may_abort, const char *prefix, const char *message) {
|
||||
bool colored = test_counts[test_status_fail] != 0 &&
|
||||
isatty(STDERR_FILENO);
|
||||
bool colored = test_counts[test_status_fail] != 0
|
||||
&& isatty(STDERR_FILENO);
|
||||
const char *color_start = colored ? "\033[1;31m" : "";
|
||||
const char *color_end = colored ? "\033[0m" : "";
|
||||
malloc_cprintf(NULL, NULL, "%s%s%s\n%s", color_start, prefix, message,
|
||||
color_end);
|
||||
malloc_cprintf(
|
||||
NULL, NULL, "%s%s%s\n%s", color_start, prefix, message, color_end);
|
||||
test_status = test_status_fail;
|
||||
if (may_abort) {
|
||||
abort();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ void
|
|||
thd_join(thd_t thd, void **ret) {
|
||||
if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) {
|
||||
DWORD exit_code;
|
||||
GetExitCodeThread(thd, (LPDWORD) &exit_code);
|
||||
GetExitCodeThread(thd, (LPDWORD)&exit_code);
|
||||
*ret = (void *)(uintptr_t)exit_code;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,8 @@ thd_setname(const char *name) {
|
|||
|
||||
bool
|
||||
thd_has_setname(void) {
|
||||
#if defined(JEMALLOC_HAVE_PTHREAD_SETNAME_NP) || defined(JEMALLOC_HAVE_PTHREAD_SET_NAME_NP)
|
||||
#if defined(JEMALLOC_HAVE_PTHREAD_SETNAME_NP) \
|
||||
|| defined(JEMALLOC_HAVE_PTHREAD_SET_NAME_NP)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
|||
uint64_t t0 = timer_usec(a);
|
||||
uint64_t t1 = timer_usec(b);
|
||||
uint64_t mult;
|
||||
size_t i = 0;
|
||||
size_t j, n;
|
||||
size_t i = 0;
|
||||
size_t j, n;
|
||||
|
||||
/*
|
||||
* The time difference could be 0 if the two clock readings are
|
||||
|
|
@ -36,11 +36,11 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
|||
* Thus, bump t1 if it is 0 to avoid dividing 0.
|
||||
*/
|
||||
if (t1 == 0) {
|
||||
t1 = 1;
|
||||
t1 = 1;
|
||||
}
|
||||
|
||||
/* Whole. */
|
||||
n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1);
|
||||
n = malloc_snprintf(&buf[i], buflen - i, "%" FMTu64, t0 / t1);
|
||||
i += n;
|
||||
if (i >= buflen) {
|
||||
return;
|
||||
|
|
@ -51,15 +51,17 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
|||
}
|
||||
|
||||
/* Decimal. */
|
||||
n = malloc_snprintf(&buf[i], buflen-i, ".");
|
||||
n = malloc_snprintf(&buf[i], buflen - i, ".");
|
||||
i += n;
|
||||
|
||||
/* Fraction. */
|
||||
while (i < buflen-1) {
|
||||
uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10
|
||||
>= 5)) ? 1 : 0;
|
||||
n = malloc_snprintf(&buf[i], buflen-i,
|
||||
"%"FMTu64, (t0 * mult / t1) % 10 + round);
|
||||
while (i < buflen - 1) {
|
||||
uint64_t round = (i + 1 == buflen - 1
|
||||
&& ((t0 * mult * 10 / t1) % 10 >= 5))
|
||||
? 1
|
||||
: 0;
|
||||
n = malloc_snprintf(&buf[i], buflen - i, "%" FMTu64,
|
||||
(t0 * mult / t1) % 10 + round);
|
||||
i += n;
|
||||
mult *= 10;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ static size_t miblen = MIBLEN;
|
|||
#define HUGE_BATCH (1000 * 1000)
|
||||
#define HUGE_BATCH_ITER 100
|
||||
#define LEN (100 * 1000 * 1000)
|
||||
static void *batch_ptrs[LEN];
|
||||
static void *batch_ptrs[LEN];
|
||||
static size_t batch_ptrs_next = 0;
|
||||
static void *item_ptrs[LEN];
|
||||
static void *item_ptrs[LEN];
|
||||
static size_t item_ptrs_next = 0;
|
||||
|
||||
#define SIZE 7
|
||||
|
|
@ -22,17 +22,18 @@ struct batch_alloc_packet_s {
|
|||
void **ptrs;
|
||||
size_t num;
|
||||
size_t size;
|
||||
int flags;
|
||||
int flags;
|
||||
};
|
||||
|
||||
static void
|
||||
batch_alloc_wrapper(size_t batch) {
|
||||
batch_alloc_packet_t batch_alloc_packet =
|
||||
{batch_ptrs + batch_ptrs_next, batch, SIZE, 0};
|
||||
batch_alloc_packet_t batch_alloc_packet = {
|
||||
batch_ptrs + batch_ptrs_next, batch, SIZE, 0};
|
||||
size_t filled;
|
||||
size_t len = sizeof(size_t);
|
||||
assert_d_eq(mallctlbymib(mib, miblen, &filled, &len,
|
||||
&batch_alloc_packet, sizeof(batch_alloc_packet)), 0, "");
|
||||
&batch_alloc_packet, sizeof(batch_alloc_packet)),
|
||||
0, "");
|
||||
assert_zu_eq(filled, batch, "");
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +95,9 @@ compare_without_free(size_t batch, size_t iter,
|
|||
batch_ptrs_next = 0;
|
||||
release_and_clear(item_ptrs, item_ptrs_next);
|
||||
item_ptrs_next = 0;
|
||||
compare_funcs(0, iter,
|
||||
"batch allocation", batch_alloc_without_free_func,
|
||||
"item allocation", item_alloc_without_free_func);
|
||||
compare_funcs(0, iter, "batch allocation",
|
||||
batch_alloc_without_free_func, "item allocation",
|
||||
item_alloc_without_free_func);
|
||||
release_and_clear(batch_ptrs, batch_ptrs_next);
|
||||
batch_ptrs_next = 0;
|
||||
release_and_clear(item_ptrs, item_ptrs_next);
|
||||
|
|
@ -116,8 +117,7 @@ compare_with_free(size_t batch, size_t iter,
|
|||
}
|
||||
batch_ptrs_next = 0;
|
||||
item_ptrs_next = 0;
|
||||
compare_funcs(0, iter,
|
||||
"batch allocation", batch_alloc_with_free_func,
|
||||
compare_funcs(0, iter, "batch allocation", batch_alloc_with_free_func,
|
||||
"item allocation", item_alloc_with_free_func);
|
||||
batch_ptrs_next = 0;
|
||||
item_ptrs_next = 0;
|
||||
|
|
@ -187,12 +187,11 @@ TEST_BEGIN(test_huge_batch_with_free) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
int main(void) {
|
||||
assert_d_eq(mallctlnametomib("experimental.batch_alloc", mib, &miblen),
|
||||
0, "");
|
||||
return test_no_reentrancy(
|
||||
test_tiny_batch_without_free,
|
||||
test_tiny_batch_with_free,
|
||||
test_huge_batch_without_free,
|
||||
int
|
||||
main(void) {
|
||||
assert_d_eq(
|
||||
mallctlnametomib("experimental.batch_alloc", mib, &miblen), 0, "");
|
||||
return test_no_reentrancy(test_tiny_batch_without_free,
|
||||
test_tiny_batch_with_free, test_huge_batch_without_free,
|
||||
test_huge_batch_with_free);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
static void
|
||||
malloc_free(void) {
|
||||
void* p = malloc(1);
|
||||
void *p = malloc(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected malloc failure");
|
||||
p = no_opt_ptr(p);
|
||||
free((void *)p);
|
||||
|
|
@ -11,7 +11,7 @@ malloc_free(void) {
|
|||
|
||||
static void
|
||||
new_delete(void) {
|
||||
void* p = ::operator new(1);
|
||||
void *p = ::operator new(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected new failure");
|
||||
p = no_opt_ptr(p);
|
||||
::operator delete((void *)p);
|
||||
|
|
@ -19,7 +19,7 @@ new_delete(void) {
|
|||
|
||||
static void
|
||||
malloc_free_array(void) {
|
||||
void* p = malloc(sizeof(int)*8);
|
||||
void *p = malloc(sizeof(int) * 8);
|
||||
expect_ptr_not_null((void *)p, "Unexpected malloc failure");
|
||||
p = no_opt_ptr(p);
|
||||
free((void *)p);
|
||||
|
|
@ -27,7 +27,7 @@ malloc_free_array(void) {
|
|||
|
||||
static void
|
||||
new_delete_array(void) {
|
||||
int* p = new int[8];
|
||||
int *p = new int[8];
|
||||
expect_ptr_not_null((void *)p, "Unexpected new[] failure");
|
||||
p = (int *)no_opt_ptr((void *)p);
|
||||
delete[] (int *)p;
|
||||
|
|
@ -36,7 +36,7 @@ new_delete_array(void) {
|
|||
#if __cpp_sized_deallocation >= 201309
|
||||
static void
|
||||
new_sized_delete(void) {
|
||||
void* p = ::operator new(1);
|
||||
void *p = ::operator new(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected new failure");
|
||||
p = no_opt_ptr(p);
|
||||
::operator delete((void *)p, 1);
|
||||
|
|
@ -44,45 +44,41 @@ new_sized_delete(void) {
|
|||
|
||||
static void
|
||||
malloc_sdallocx(void) {
|
||||
void* p = malloc(1);
|
||||
void *p = malloc(1);
|
||||
expect_ptr_not_null((void *)p, "Unexpected malloc failure");
|
||||
p = no_opt_ptr(p);
|
||||
sdallocx((void *)p, 1, 0);
|
||||
sdallocx((void *)p, 1, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_BEGIN(test_free_vs_delete) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000,
|
||||
"malloc_free", (void *)malloc_free,
|
||||
"new_delete", (void *)new_delete);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc_free",
|
||||
(void *)malloc_free, "new_delete", (void *)new_delete);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_free_array_vs_delete_array) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000,
|
||||
"malloc_free_array", (void *)malloc_free_array,
|
||||
"delete_array", (void *)new_delete_array);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc_free_array",
|
||||
(void *)malloc_free_array, "delete_array",
|
||||
(void *)new_delete_array);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST_BEGIN(test_sized_delete_vs_sdallocx) {
|
||||
#if __cpp_sized_deallocation >= 201309
|
||||
compare_funcs(10*1000*1000, 100*1000*1000,
|
||||
"new_size_delete", (void *)new_sized_delete,
|
||||
"malloc_sdallocx", (void *)malloc_sdallocx);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "new_size_delete",
|
||||
(void *)new_sized_delete, "malloc_sdallocx",
|
||||
(void *)malloc_sdallocx);
|
||||
#else
|
||||
malloc_printf("Skipping test_sized_delete_vs_sdallocx since \
|
||||
malloc_printf(
|
||||
"Skipping test_sized_delete_vs_sdallocx since \
|
||||
sized deallocation is not enabled.\n");
|
||||
#endif
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
int
|
||||
main() {
|
||||
return test_no_reentrancy(
|
||||
test_free_vs_delete,
|
||||
test_free_array_vs_delete_array,
|
||||
test_sized_delete_vs_sdallocx);
|
||||
return test_no_reentrancy(test_free_vs_delete,
|
||||
test_free_array_vs_delete_array, test_sized_delete_vs_sdallocx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ item_alloc_dalloc_small(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_array_vs_item_small) {
|
||||
compare_funcs(1 * 1000, 10 * 1000,
|
||||
"array of small allocations", array_alloc_dalloc_small,
|
||||
"small item allocation", item_alloc_dalloc_small);
|
||||
compare_funcs(1 * 1000, 10 * 1000, "array of small allocations",
|
||||
array_alloc_dalloc_small, "small item allocation",
|
||||
item_alloc_dalloc_small);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -64,14 +64,14 @@ item_alloc_dalloc_large(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_array_vs_item_large) {
|
||||
compare_funcs(100, 1000,
|
||||
"array of large allocations", array_alloc_dalloc_large,
|
||||
"large item allocation", item_alloc_dalloc_large);
|
||||
compare_funcs(100, 1000, "array of large allocations",
|
||||
array_alloc_dalloc_large, "large item allocation",
|
||||
item_alloc_dalloc_large);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int main(void) {
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_array_vs_item_small,
|
||||
test_array_vs_item_large);
|
||||
test_array_vs_item_small, test_array_vs_item_large);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,19 +2,16 @@
|
|||
|
||||
static void
|
||||
noop_alloc_hook(void *extra, hook_alloc_t type, void *result,
|
||||
uintptr_t result_raw, uintptr_t args_raw[3]) {
|
||||
}
|
||||
uintptr_t result_raw, uintptr_t args_raw[3]) {}
|
||||
|
||||
static void
|
||||
noop_dalloc_hook(void *extra, hook_dalloc_t type, void *address,
|
||||
uintptr_t args_raw[3]) {
|
||||
}
|
||||
noop_dalloc_hook(
|
||||
void *extra, hook_dalloc_t type, void *address, uintptr_t args_raw[3]) {}
|
||||
|
||||
static void
|
||||
noop_expand_hook(void *extra, hook_expand_t type, void *address,
|
||||
size_t old_usize, size_t new_usize, uintptr_t result_raw,
|
||||
uintptr_t args_raw[4]) {
|
||||
}
|
||||
uintptr_t args_raw[4]) {}
|
||||
|
||||
static void
|
||||
malloc_free_loop(int iters) {
|
||||
|
|
@ -26,23 +23,23 @@ malloc_free_loop(int iters) {
|
|||
|
||||
static void
|
||||
test_hooked(int iters) {
|
||||
hooks_t hooks = {&noop_alloc_hook, &noop_dalloc_hook, &noop_expand_hook,
|
||||
NULL};
|
||||
hooks_t hooks = {
|
||||
&noop_alloc_hook, &noop_dalloc_hook, &noop_expand_hook, NULL};
|
||||
|
||||
int err;
|
||||
void *handles[HOOK_MAX];
|
||||
int err;
|
||||
void *handles[HOOK_MAX];
|
||||
size_t sz = sizeof(handles[0]);
|
||||
|
||||
for (int i = 0; i < HOOK_MAX; i++) {
|
||||
err = mallctl("experimental.hooks.install", &handles[i],
|
||||
&sz, &hooks, sizeof(hooks));
|
||||
err = mallctl("experimental.hooks.install", &handles[i], &sz,
|
||||
&hooks, sizeof(hooks));
|
||||
assert(err == 0);
|
||||
|
||||
timedelta_t timer;
|
||||
timer_start(&timer);
|
||||
malloc_free_loop(iters);
|
||||
timer_stop(&timer);
|
||||
malloc_printf("With %d hook%s: %"FMTu64"us\n", i + 1,
|
||||
malloc_printf("With %d hook%s: %" FMTu64 "us\n", i + 1,
|
||||
i + 1 == 1 ? "" : "s", timer_usec(&timer));
|
||||
}
|
||||
for (int i = 0; i < HOOK_MAX; i++) {
|
||||
|
|
@ -59,7 +56,7 @@ test_unhooked(int iters) {
|
|||
malloc_free_loop(iters);
|
||||
timer_stop(&timer);
|
||||
|
||||
malloc_printf("Without hooks: %"FMTu64"us\n", timer_usec(&timer));
|
||||
malloc_printf("Without hooks: %" FMTu64 "us\n", timer_usec(&timer));
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
|
|
@ -22,14 +22,12 @@ small_mallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_large_vs_small) {
|
||||
compare_funcs(100*1000, 1*1000*1000, "large mallocx",
|
||||
compare_funcs(100 * 1000, 1 * 1000 * 1000, "large mallocx",
|
||||
large_mallocx_free, "small mallocx", small_mallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_large_vs_small);
|
||||
return test_no_reentrancy(test_large_vs_small);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
static void
|
||||
mallctl_short(void) {
|
||||
const char *version;
|
||||
size_t sz = sizeof(version);
|
||||
int err = mallctl("version", &version, &sz, NULL, 0);
|
||||
size_t sz = sizeof(version);
|
||||
int err = mallctl("version", &version, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctl failure");
|
||||
}
|
||||
|
||||
|
|
@ -13,19 +13,19 @@ size_t mib_short[1];
|
|||
|
||||
static void
|
||||
mallctlbymib_short(void) {
|
||||
size_t miblen = sizeof(mib_short)/sizeof(mib_short[0]);
|
||||
size_t miblen = sizeof(mib_short) / sizeof(mib_short[0]);
|
||||
const char *version;
|
||||
size_t sz = sizeof(version);
|
||||
size_t sz = sizeof(version);
|
||||
int err = mallctlbymib(mib_short, miblen, &version, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctlbymib failure");
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_mallctl_vs_mallctlbymib_short) {
|
||||
size_t miblen = sizeof(mib_short)/sizeof(mib_short[0]);
|
||||
size_t miblen = sizeof(mib_short) / sizeof(mib_short[0]);
|
||||
|
||||
int err = mallctlnametomib("version", mib_short, &miblen);
|
||||
assert_d_eq(err, 0, "mallctlnametomib failure");
|
||||
compare_funcs(10*1000*1000, 10*1000*1000, "mallctl_short",
|
||||
compare_funcs(10 * 1000 * 1000, 10 * 1000 * 1000, "mallctl_short",
|
||||
mallctl_short, "mallctlbymib_short", mallctlbymib_short);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -33,9 +33,9 @@ TEST_END
|
|||
static void
|
||||
mallctl_long(void) {
|
||||
uint64_t nmalloc;
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctl("stats.arenas.0.bins.0.nmalloc", &nmalloc, &sz, NULL,
|
||||
0);
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctl(
|
||||
"stats.arenas.0.bins.0.nmalloc", &nmalloc, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctl failure");
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +43,10 @@ size_t mib_long[6];
|
|||
|
||||
static void
|
||||
mallctlbymib_long(void) {
|
||||
size_t miblen = sizeof(mib_long)/sizeof(mib_long[0]);
|
||||
size_t miblen = sizeof(mib_long) / sizeof(mib_long[0]);
|
||||
uint64_t nmalloc;
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctlbymib(mib_long, miblen, &nmalloc, &sz, NULL, 0);
|
||||
size_t sz = sizeof(nmalloc);
|
||||
int err = mallctlbymib(mib_long, miblen, &nmalloc, &sz, NULL, 0);
|
||||
assert_d_eq(err, 0, "mallctlbymib failure");
|
||||
}
|
||||
|
||||
|
|
@ -57,18 +57,17 @@ TEST_BEGIN(test_mallctl_vs_mallctlbymib_long) {
|
|||
*/
|
||||
test_skip_if(!config_stats);
|
||||
|
||||
size_t miblen = sizeof(mib_long)/sizeof(mib_long[0]);
|
||||
int err = mallctlnametomib("stats.arenas.0.bins.0.nmalloc", mib_long,
|
||||
&miblen);
|
||||
size_t miblen = sizeof(mib_long) / sizeof(mib_long[0]);
|
||||
int err = mallctlnametomib(
|
||||
"stats.arenas.0.bins.0.nmalloc", mib_long, &miblen);
|
||||
assert_d_eq(err, 0, "mallctlnametomib failure");
|
||||
compare_funcs(10*1000*1000, 10*1000*1000, "mallctl_long",
|
||||
compare_funcs(10 * 1000 * 1000, 10 * 1000 * 1000, "mallctl_long",
|
||||
mallctl_long, "mallctlbymib_long", mallctlbymib_long);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_mallctl_vs_mallctlbymib_short,
|
||||
return test_no_reentrancy(test_mallctl_vs_mallctlbymib_short,
|
||||
test_mallctl_vs_mallctlbymib_long);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ mallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_malloc_vs_mallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "malloc",
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc",
|
||||
malloc_free, "mallocx", mallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -53,14 +53,14 @@ malloc_sdallocx(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_free_vs_dallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "free", malloc_free,
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "free", malloc_free,
|
||||
"dallocx", malloc_dallocx);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_dallocx_vs_sdallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "dallocx", malloc_dallocx,
|
||||
"sdallocx", malloc_sdallocx);
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "dallocx",
|
||||
malloc_dallocx, "sdallocx", malloc_sdallocx);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ malloc_sallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_mus_vs_sallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "malloc_usable_size",
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "malloc_usable_size",
|
||||
malloc_mus_free, "sallocx", malloc_sallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -116,17 +116,14 @@ malloc_nallocx_free(void) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_sallocx_vs_nallocx) {
|
||||
compare_funcs(10*1000*1000, 100*1000*1000, "sallocx",
|
||||
compare_funcs(10 * 1000 * 1000, 100 * 1000 * 1000, "sallocx",
|
||||
malloc_sallocx_free, "nallocx", malloc_nallocx_free);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_malloc_vs_mallocx,
|
||||
test_free_vs_dallocx,
|
||||
test_dallocx_vs_sdallocx,
|
||||
test_mus_vs_sallocx,
|
||||
return test_no_reentrancy(test_malloc_vs_mallocx, test_free_vs_dallocx,
|
||||
test_dallocx_vs_sdallocx, test_mus_vs_sallocx,
|
||||
test_sallocx_vs_nallocx);
|
||||
}
|
||||
|
|
|
|||
2779
test/unit/SFMT.c
2779
test/unit/SFMT.c
File diff suppressed because it is too large
Load diff
|
|
@ -11,6 +11,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_malloc_init(
|
||||
test_a0);
|
||||
return test_no_malloc_init(test_a0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
#include "jemalloc/internal/ticker.h"
|
||||
|
||||
static nstime_monotonic_t *nstime_monotonic_orig;
|
||||
static nstime_update_t *nstime_update_orig;
|
||||
static nstime_update_t *nstime_update_orig;
|
||||
|
||||
static unsigned nupdates_mock;
|
||||
static nstime_t time_mock;
|
||||
static bool monotonic_mock;
|
||||
static bool monotonic_mock;
|
||||
|
||||
static bool
|
||||
nstime_monotonic_mock(void) {
|
||||
|
|
@ -28,26 +28,27 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
test_skip_if(opt_hpa);
|
||||
|
||||
ticker_geom_t *decay_ticker;
|
||||
unsigned tick0, tick1, arena_ind;
|
||||
size_t sz, large0;
|
||||
void *p;
|
||||
unsigned tick0, tick1, arena_ind;
|
||||
size_t sz, large0;
|
||||
void *p;
|
||||
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctl("arenas.lextent.0.size", (void *)&large0, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.0.size", (void *)&large0, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl failure");
|
||||
|
||||
/* Set up a manually managed arena for test. */
|
||||
arena_ind = do_arena_create(0, 0);
|
||||
|
||||
/* Migrate to the new arena, and get the ticker. */
|
||||
unsigned old_arena_ind;
|
||||
size_t sz_arena_ind = sizeof(old_arena_ind);
|
||||
size_t sz_arena_ind = sizeof(old_arena_ind);
|
||||
expect_d_eq(mallctl("thread.arena", (void *)&old_arena_ind,
|
||||
&sz_arena_ind, (void *)&arena_ind, sizeof(arena_ind)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
&sz_arena_ind, (void *)&arena_ind, sizeof(arena_ind)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
decay_ticker = tsd_arena_decay_tickerp_get(tsd_fetch());
|
||||
expect_ptr_not_null(decay_ticker,
|
||||
"Unexpected failure getting decay ticker");
|
||||
expect_ptr_not_null(
|
||||
decay_ticker, "Unexpected failure getting decay ticker");
|
||||
|
||||
/*
|
||||
* Test the standard APIs using a large size class, since we can't
|
||||
|
|
@ -80,8 +81,8 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
expect_d_eq(posix_memalign(&p, sizeof(size_t), large0), 0,
|
||||
"Unexpected posix_memalign() failure");
|
||||
tick1 = ticker_geom_read(decay_ticker);
|
||||
expect_u32_ne(tick1, tick0,
|
||||
"Expected ticker to tick during posix_memalign()");
|
||||
expect_u32_ne(
|
||||
tick1, tick0, "Expected ticker to tick during posix_memalign()");
|
||||
free(p);
|
||||
|
||||
/* aligned_alloc(). */
|
||||
|
|
@ -89,8 +90,8 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
p = aligned_alloc(sizeof(size_t), large0);
|
||||
expect_ptr_not_null(p, "Unexpected aligned_alloc() failure");
|
||||
tick1 = ticker_geom_read(decay_ticker);
|
||||
expect_u32_ne(tick1, tick0,
|
||||
"Expected ticker to tick during aligned_alloc()");
|
||||
expect_u32_ne(
|
||||
tick1, tick0, "Expected ticker to tick during aligned_alloc()");
|
||||
free(p);
|
||||
|
||||
/* realloc(). */
|
||||
|
|
@ -118,7 +119,7 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
*/
|
||||
{
|
||||
unsigned i;
|
||||
size_t allocx_sizes[2];
|
||||
size_t allocx_sizes[2];
|
||||
allocx_sizes[0] = large0;
|
||||
allocx_sizes[1] = 1;
|
||||
|
||||
|
|
@ -163,7 +164,8 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
tick1 = ticker_geom_read(decay_ticker);
|
||||
expect_u32_ne(tick1, tick0,
|
||||
"Expected ticker to tick during sdallocx() "
|
||||
"(sz=%zu)", sz);
|
||||
"(sz=%zu)",
|
||||
sz);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,18 +174,19 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
* using an explicit tcache.
|
||||
*/
|
||||
unsigned tcache_ind, i;
|
||||
size_t tcache_sizes[2];
|
||||
size_t tcache_sizes[2];
|
||||
tcache_sizes[0] = large0;
|
||||
tcache_sizes[1] = 1;
|
||||
|
||||
size_t tcache_max, sz_tcache_max;
|
||||
sz_tcache_max = sizeof(tcache_max);
|
||||
expect_d_eq(mallctl("arenas.tcache_max", (void *)&tcache_max,
|
||||
&sz_tcache_max, NULL, 0), 0, "Unexpected mallctl() failure");
|
||||
&sz_tcache_max, NULL, 0),
|
||||
0, "Unexpected mallctl() failure");
|
||||
|
||||
sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("tcache.create", (void *)&tcache_ind, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(mallctl("tcache.create", (void *)&tcache_ind, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl failure");
|
||||
|
||||
for (i = 0; i < sizeof(tcache_sizes) / sizeof(size_t); i++) {
|
||||
sz = tcache_sizes[i];
|
||||
|
|
@ -195,13 +198,14 @@ TEST_BEGIN(test_decay_ticks) {
|
|||
tick1 = ticker_geom_read(decay_ticker);
|
||||
expect_u32_ne(tick1, tick0,
|
||||
"Expected ticker to tick during tcache fill "
|
||||
"(sz=%zu)", sz);
|
||||
"(sz=%zu)",
|
||||
sz);
|
||||
/* tcache flush. */
|
||||
dallocx(p, MALLOCX_TCACHE(tcache_ind));
|
||||
tick0 = ticker_geom_read(decay_ticker);
|
||||
expect_d_eq(mallctl("tcache.flush", NULL, NULL,
|
||||
(void *)&tcache_ind, sizeof(unsigned)), 0,
|
||||
"Unexpected mallctl failure");
|
||||
(void *)&tcache_ind, sizeof(unsigned)),
|
||||
0, "Unexpected mallctl failure");
|
||||
tick1 = ticker_geom_read(decay_ticker);
|
||||
|
||||
/* Will only tick if it's in tcache. */
|
||||
|
|
@ -231,11 +235,11 @@ decay_ticker_helper(unsigned arena_ind, int flags, bool dirty, ssize_t dt,
|
|||
* cached slab were to repeatedly come and go during looping, it could
|
||||
* prevent the decay backlog ever becoming empty.
|
||||
*/
|
||||
void *p = do_mallocx(1, flags);
|
||||
void *p = do_mallocx(1, flags);
|
||||
uint64_t dirty_npurge1, muzzy_npurge1;
|
||||
do {
|
||||
for (unsigned i = 0; i < ARENA_DECAY_NTICKS_PER_UPDATE / 2;
|
||||
i++) {
|
||||
i++) {
|
||||
void *q = do_mallocx(1, flags);
|
||||
dallocx(q, flags);
|
||||
}
|
||||
|
|
@ -244,14 +248,15 @@ decay_ticker_helper(unsigned arena_ind, int flags, bool dirty, ssize_t dt,
|
|||
|
||||
nstime_add(&time_mock, &update_interval);
|
||||
nstime_update(&time);
|
||||
} while (nstime_compare(&time, &deadline) <= 0 && ((dirty_npurge1 ==
|
||||
dirty_npurge0 && muzzy_npurge1 == muzzy_npurge0) ||
|
||||
!terminate_asap));
|
||||
} while (nstime_compare(&time, &deadline) <= 0
|
||||
&& ((dirty_npurge1 == dirty_npurge0
|
||||
&& muzzy_npurge1 == muzzy_npurge0)
|
||||
|| !terminate_asap));
|
||||
dallocx(p, flags);
|
||||
|
||||
if (config_stats) {
|
||||
expect_u64_gt(dirty_npurge1 + muzzy_npurge1, dirty_npurge0 +
|
||||
muzzy_npurge0, "Expected purging to occur");
|
||||
expect_u64_gt(dirty_npurge1 + muzzy_npurge1,
|
||||
dirty_npurge0 + muzzy_npurge0, "Expected purging to occur");
|
||||
}
|
||||
#undef NINTERVALS
|
||||
}
|
||||
|
|
@ -260,11 +265,11 @@ TEST_BEGIN(test_decay_ticker) {
|
|||
test_skip_if(is_background_thread_enabled());
|
||||
test_skip_if(opt_hpa);
|
||||
#define NPS 2048
|
||||
ssize_t ddt = opt_dirty_decay_ms;
|
||||
ssize_t mdt = opt_muzzy_decay_ms;
|
||||
ssize_t ddt = opt_dirty_decay_ms;
|
||||
ssize_t mdt = opt_muzzy_decay_ms;
|
||||
unsigned arena_ind = do_arena_create(ddt, mdt);
|
||||
int flags = (MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE);
|
||||
void *ps[NPS];
|
||||
int flags = (MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE);
|
||||
void *ps[NPS];
|
||||
|
||||
/*
|
||||
* Allocate a bunch of large objects, pause the clock, deallocate every
|
||||
|
|
@ -274,8 +279,9 @@ TEST_BEGIN(test_decay_ticker) {
|
|||
*/
|
||||
size_t large;
|
||||
size_t sz = sizeof(size_t);
|
||||
expect_d_eq(mallctl("arenas.lextent.0.size", (void *)&large, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.0.size", (void *)&large, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl failure");
|
||||
|
||||
do_purge(arena_ind);
|
||||
uint64_t dirty_npurge0 = get_arena_dirty_npurge(arena_ind);
|
||||
|
|
@ -302,9 +308,9 @@ TEST_BEGIN(test_decay_ticker) {
|
|||
"Expected nstime_update() to be called");
|
||||
}
|
||||
|
||||
decay_ticker_helper(arena_ind, flags, true, ddt, dirty_npurge0,
|
||||
muzzy_npurge0, true);
|
||||
decay_ticker_helper(arena_ind, flags, false, ddt+mdt, dirty_npurge0,
|
||||
decay_ticker_helper(
|
||||
arena_ind, flags, true, ddt, dirty_npurge0, muzzy_npurge0, true);
|
||||
decay_ticker_helper(arena_ind, flags, false, ddt + mdt, dirty_npurge0,
|
||||
muzzy_npurge0, false);
|
||||
|
||||
do_arena_destroy(arena_ind);
|
||||
|
|
@ -319,16 +325,17 @@ TEST_BEGIN(test_decay_nonmonotonic) {
|
|||
test_skip_if(is_background_thread_enabled());
|
||||
test_skip_if(opt_hpa);
|
||||
#define NPS (SMOOTHSTEP_NSTEPS + 1)
|
||||
int flags = (MALLOCX_ARENA(0) | MALLOCX_TCACHE_NONE);
|
||||
void *ps[NPS];
|
||||
int flags = (MALLOCX_ARENA(0) | MALLOCX_TCACHE_NONE);
|
||||
void *ps[NPS];
|
||||
uint64_t npurge0 = 0;
|
||||
uint64_t npurge1 = 0;
|
||||
size_t sz, large0;
|
||||
size_t sz, large0;
|
||||
unsigned i, nupdates0;
|
||||
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctl("arenas.lextent.0.size", (void *)&large0, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lextent.0.size", (void *)&large0, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl failure");
|
||||
|
||||
expect_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
|
||||
"Unexpected mallctl failure");
|
||||
|
|
@ -380,15 +387,15 @@ TEST_BEGIN(test_decay_now) {
|
|||
unsigned arena_ind = do_arena_create(0, 0);
|
||||
expect_zu_eq(get_arena_pdirty(arena_ind), 0, "Unexpected dirty pages");
|
||||
expect_zu_eq(get_arena_pmuzzy(arena_ind), 0, "Unexpected muzzy pages");
|
||||
size_t sizes[] = {16, PAGE<<2, HUGEPAGE<<2};
|
||||
size_t sizes[] = {16, PAGE << 2, HUGEPAGE << 2};
|
||||
/* Verify that dirty/muzzy pages never linger after deallocation. */
|
||||
for (unsigned i = 0; i < sizeof(sizes)/sizeof(size_t); i++) {
|
||||
for (unsigned i = 0; i < sizeof(sizes) / sizeof(size_t); i++) {
|
||||
size_t size = sizes[i];
|
||||
generate_dirty(arena_ind, size);
|
||||
expect_zu_eq(get_arena_pdirty(arena_ind), 0,
|
||||
"Unexpected dirty pages");
|
||||
expect_zu_eq(get_arena_pmuzzy(arena_ind), 0,
|
||||
"Unexpected muzzy pages");
|
||||
expect_zu_eq(
|
||||
get_arena_pdirty(arena_ind), 0, "Unexpected dirty pages");
|
||||
expect_zu_eq(
|
||||
get_arena_pmuzzy(arena_ind), 0, "Unexpected muzzy pages");
|
||||
}
|
||||
do_arena_destroy(arena_ind);
|
||||
}
|
||||
|
|
@ -399,12 +406,12 @@ TEST_BEGIN(test_decay_never) {
|
|||
test_skip_if(opt_hpa);
|
||||
|
||||
unsigned arena_ind = do_arena_create(-1, -1);
|
||||
int flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
int flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
expect_zu_eq(get_arena_pdirty(arena_ind), 0, "Unexpected dirty pages");
|
||||
expect_zu_eq(get_arena_pmuzzy(arena_ind), 0, "Unexpected muzzy pages");
|
||||
size_t sizes[] = {16, PAGE<<2, HUGEPAGE<<2};
|
||||
void *ptrs[sizeof(sizes)/sizeof(size_t)];
|
||||
for (unsigned i = 0; i < sizeof(sizes)/sizeof(size_t); i++) {
|
||||
size_t sizes[] = {16, PAGE << 2, HUGEPAGE << 2};
|
||||
void *ptrs[sizeof(sizes) / sizeof(size_t)];
|
||||
for (unsigned i = 0; i < sizeof(sizes) / sizeof(size_t); i++) {
|
||||
ptrs[i] = do_mallocx(sizes[i], flags);
|
||||
}
|
||||
/* Verify that each deallocation generates additional dirty pages. */
|
||||
|
|
@ -419,7 +426,7 @@ TEST_BEGIN(test_decay_never) {
|
|||
expect_zu_eq(pdirty_prev, 0, "Unexpected dirty pages");
|
||||
}
|
||||
expect_zu_eq(pmuzzy_prev, 0, "Unexpected muzzy pages");
|
||||
for (unsigned i = 0; i < sizeof(sizes)/sizeof(size_t); i++) {
|
||||
for (unsigned i = 0; i < sizeof(sizes) / sizeof(size_t); i++) {
|
||||
dallocx(ptrs[i], flags);
|
||||
size_t pdirty = get_arena_pdirty(arena_ind);
|
||||
size_t pmuzzy = get_arena_pmuzzy(arena_ind);
|
||||
|
|
@ -434,10 +441,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_decay_ticks,
|
||||
test_decay_ticker,
|
||||
test_decay_nonmonotonic,
|
||||
test_decay_now,
|
||||
test_decay_never);
|
||||
return test(test_decay_ticks, test_decay_ticker,
|
||||
test_decay_nonmonotonic, test_decay_now, test_decay_never);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef ARENA_RESET_PROF_C_
|
||||
#include "test/jemalloc_test.h"
|
||||
# include "test/jemalloc_test.h"
|
||||
#endif
|
||||
|
||||
#include "jemalloc/internal/extent_mmap.h"
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
static unsigned
|
||||
get_nsizes_impl(const char *cmd) {
|
||||
unsigned ret;
|
||||
size_t z;
|
||||
size_t z;
|
||||
|
||||
z = sizeof(unsigned);
|
||||
expect_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
|
||||
|
|
@ -37,12 +37,12 @@ get_size_impl(const char *cmd, size_t ind) {
|
|||
size_t miblen = 4;
|
||||
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen),
|
||||
0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
expect_d_eq(mallctlnametomib(cmd, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
|
||||
mib[2] = ind;
|
||||
z = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
|
||||
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -61,8 +61,8 @@ get_large_size(size_t ind) {
|
|||
static size_t
|
||||
vsalloc(tsdn_t *tsdn, const void *ptr) {
|
||||
emap_full_alloc_ctx_t full_alloc_ctx;
|
||||
bool missing = emap_full_alloc_ctx_try_lookup(tsdn, &arena_emap_global,
|
||||
ptr, &full_alloc_ctx);
|
||||
bool missing = emap_full_alloc_ctx_try_lookup(
|
||||
tsdn, &arena_emap_global, ptr, &full_alloc_ctx);
|
||||
if (missing) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -84,20 +84,21 @@ vsalloc(tsdn_t *tsdn, const void *ptr) {
|
|||
static unsigned
|
||||
do_arena_create(extent_hooks_t *h) {
|
||||
unsigned arena_ind;
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz,
|
||||
(void *)(h != NULL ? &h : NULL), (h != NULL ? sizeof(h) : 0)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(
|
||||
mallctl("arenas.create", (void *)&arena_ind, &sz,
|
||||
(void *)(h != NULL ? &h : NULL), (h != NULL ? sizeof(h) : 0)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
return arena_ind;
|
||||
}
|
||||
|
||||
static void
|
||||
do_arena_reset_pre(unsigned arena_ind, void ***ptrs, unsigned *nptrs) {
|
||||
#define NLARGE 32
|
||||
#define NLARGE 32
|
||||
unsigned nsmall, nlarge, i;
|
||||
size_t sz;
|
||||
int flags;
|
||||
tsdn_t *tsdn;
|
||||
size_t sz;
|
||||
int flags;
|
||||
tsdn_t *tsdn;
|
||||
|
||||
flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
|
||||
|
||||
|
|
@ -132,14 +133,14 @@ do_arena_reset_pre(unsigned arena_ind, void ***ptrs, unsigned *nptrs) {
|
|||
|
||||
static void
|
||||
do_arena_reset_post(void **ptrs, unsigned nptrs, unsigned arena_ind) {
|
||||
tsdn_t *tsdn;
|
||||
tsdn_t *tsdn;
|
||||
unsigned i;
|
||||
|
||||
tsdn = tsdn_fetch();
|
||||
|
||||
if (have_background_thread) {
|
||||
malloc_mutex_lock(tsdn,
|
||||
&background_thread_info_get(arena_ind)->mtx);
|
||||
malloc_mutex_lock(
|
||||
tsdn, &background_thread_info_get(arena_ind)->mtx);
|
||||
}
|
||||
/* Verify allocations no longer exist. */
|
||||
for (i = 0; i < nptrs; i++) {
|
||||
|
|
@ -147,8 +148,8 @@ do_arena_reset_post(void **ptrs, unsigned nptrs, unsigned arena_ind) {
|
|||
"Allocation should no longer exist");
|
||||
}
|
||||
if (have_background_thread) {
|
||||
malloc_mutex_unlock(tsdn,
|
||||
&background_thread_info_get(arena_ind)->mtx);
|
||||
malloc_mutex_unlock(
|
||||
tsdn, &background_thread_info_get(arena_ind)->mtx);
|
||||
}
|
||||
|
||||
free(ptrs);
|
||||
|
|
@ -159,7 +160,7 @@ do_arena_reset_destroy(const char *name, unsigned arena_ind) {
|
|||
size_t mib[3];
|
||||
size_t miblen;
|
||||
|
||||
miblen = sizeof(mib)/sizeof(size_t);
|
||||
miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib(name, mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
|
|
@ -179,7 +180,7 @@ do_arena_destroy(unsigned arena_ind) {
|
|||
|
||||
TEST_BEGIN(test_arena_reset) {
|
||||
unsigned arena_ind;
|
||||
void **ptrs;
|
||||
void **ptrs;
|
||||
unsigned nptrs;
|
||||
|
||||
arena_ind = do_arena_create(NULL);
|
||||
|
|
@ -191,23 +192,25 @@ TEST_END
|
|||
|
||||
static bool
|
||||
arena_i_initialized(unsigned arena_ind, bool refresh) {
|
||||
bool initialized;
|
||||
bool initialized;
|
||||
size_t mib[3];
|
||||
size_t miblen, sz;
|
||||
|
||||
if (refresh) {
|
||||
uint64_t epoch = 1;
|
||||
expect_d_eq(mallctl("epoch", NULL, NULL, (void *)&epoch,
|
||||
sizeof(epoch)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(
|
||||
mallctl("epoch", NULL, NULL, (void *)&epoch, sizeof(epoch)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
}
|
||||
|
||||
miblen = sizeof(mib)/sizeof(size_t);
|
||||
miblen = sizeof(mib) / sizeof(size_t);
|
||||
expect_d_eq(mallctlnametomib("arena.0.initialized", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib() failure");
|
||||
mib[1] = (size_t)arena_ind;
|
||||
sz = sizeof(initialized);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&initialized, &sz, NULL,
|
||||
0), 0, "Unexpected mallctlbymib() failure");
|
||||
expect_d_eq(
|
||||
mallctlbymib(mib, miblen, (void *)&initialized, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctlbymib() failure");
|
||||
|
||||
return initialized;
|
||||
}
|
||||
|
|
@ -220,7 +223,7 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_arena_destroy_hooks_default) {
|
||||
unsigned arena_ind, arena_ind_another, arena_ind_prev;
|
||||
void **ptrs;
|
||||
void **ptrs;
|
||||
unsigned nptrs;
|
||||
|
||||
arena_ind = do_arena_create(NULL);
|
||||
|
|
@ -249,26 +252,27 @@ TEST_BEGIN(test_arena_destroy_hooks_default) {
|
|||
arena_ind_prev = arena_ind;
|
||||
arena_ind = do_arena_create(NULL);
|
||||
do_arena_reset_pre(arena_ind, &ptrs, &nptrs);
|
||||
expect_u_eq(arena_ind, arena_ind_prev,
|
||||
"Arena index should have been recycled");
|
||||
expect_u_eq(
|
||||
arena_ind, arena_ind_prev, "Arena index should have been recycled");
|
||||
do_arena_destroy(arena_ind);
|
||||
do_arena_reset_post(ptrs, nptrs, arena_ind);
|
||||
|
||||
do_arena_destroy(arena_ind_another);
|
||||
|
||||
/* Try arena.create with custom hooks. */
|
||||
size_t sz = sizeof(extent_hooks_t *);
|
||||
size_t sz = sizeof(extent_hooks_t *);
|
||||
extent_hooks_t *a0_default_hooks;
|
||||
expect_d_eq(mallctl("arena.0.extent_hooks", (void *)&a0_default_hooks,
|
||||
&sz, NULL, 0), 0, "Unexpected mallctlnametomib() failure");
|
||||
&sz, NULL, 0),
|
||||
0, "Unexpected mallctlnametomib() failure");
|
||||
|
||||
/* Default impl; but wrapped as "customized". */
|
||||
extent_hooks_t new_hooks = *a0_default_hooks;
|
||||
extent_hooks_t new_hooks = *a0_default_hooks;
|
||||
extent_hooks_t *hook = &new_hooks;
|
||||
sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz,
|
||||
(void *)&hook, sizeof(void *)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
(void *)&hook, sizeof(void *)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
do_arena_destroy(arena_ind);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -280,13 +284,15 @@ TEST_END
|
|||
static bool
|
||||
extent_dalloc_unmap(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
||||
bool committed, unsigned arena_ind) {
|
||||
TRACE_HOOK("%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
|
||||
"arena_ind=%u)\n", __func__, extent_hooks, addr, size, committed ?
|
||||
"true" : "false", arena_ind);
|
||||
TRACE_HOOK(
|
||||
"%s(extent_hooks=%p, addr=%p, size=%zu, committed=%s, "
|
||||
"arena_ind=%u)\n",
|
||||
__func__, extent_hooks, addr, size, committed ? "true" : "false",
|
||||
arena_ind);
|
||||
expect_ptr_eq(extent_hooks, &hooks,
|
||||
"extent_hooks should be same as pointer used to set hooks");
|
||||
expect_ptr_eq(extent_hooks->dalloc, extent_dalloc_unmap,
|
||||
"Wrong hook function");
|
||||
expect_ptr_eq(
|
||||
extent_hooks->dalloc, extent_dalloc_unmap, "Wrong hook function");
|
||||
called_dalloc = true;
|
||||
if (!try_dalloc) {
|
||||
return true;
|
||||
|
|
@ -301,21 +307,15 @@ extent_dalloc_unmap(extent_hooks_t *extent_hooks, void *addr, size_t size,
|
|||
|
||||
static extent_hooks_t hooks_orig;
|
||||
|
||||
static extent_hooks_t hooks_unmap = {
|
||||
extent_alloc_hook,
|
||||
extent_dalloc_unmap, /* dalloc */
|
||||
extent_destroy_hook,
|
||||
extent_commit_hook,
|
||||
extent_decommit_hook,
|
||||
extent_purge_lazy_hook,
|
||||
extent_purge_forced_hook,
|
||||
extent_split_hook,
|
||||
extent_merge_hook
|
||||
};
|
||||
static extent_hooks_t hooks_unmap = {extent_alloc_hook,
|
||||
extent_dalloc_unmap, /* dalloc */
|
||||
extent_destroy_hook, extent_commit_hook, extent_decommit_hook,
|
||||
extent_purge_lazy_hook, extent_purge_forced_hook, extent_split_hook,
|
||||
extent_merge_hook};
|
||||
|
||||
TEST_BEGIN(test_arena_destroy_hooks_unmap) {
|
||||
unsigned arena_ind;
|
||||
void **ptrs;
|
||||
void **ptrs;
|
||||
unsigned nptrs;
|
||||
|
||||
extent_hooks_prep();
|
||||
|
|
@ -353,9 +353,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_arena_reset,
|
||||
test_arena_destroy_initial,
|
||||
test_arena_destroy_hooks_default,
|
||||
test_arena_destroy_hooks_unmap);
|
||||
return test(test_arena_reset, test_arena_destroy_initial,
|
||||
test_arena_destroy_hooks_default, test_arena_destroy_hooks_unmap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,7 +187,6 @@ TEST_BEGIN(test_atomic_u64) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST_STRUCT(uint32_t, u32);
|
||||
TEST_BEGIN(test_atomic_u32) {
|
||||
INTEGER_TEST_BODY(uint32_t, u32);
|
||||
|
|
@ -212,7 +211,6 @@ TEST_BEGIN(test_atomic_zd) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST_STRUCT(unsigned, u);
|
||||
TEST_BEGIN(test_atomic_u) {
|
||||
INTEGER_TEST_BODY(unsigned, u);
|
||||
|
|
@ -221,11 +219,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_atomic_u64,
|
||||
test_atomic_u32,
|
||||
test_atomic_p,
|
||||
test_atomic_zu,
|
||||
test_atomic_zd,
|
||||
test_atomic_u);
|
||||
return test(test_atomic_u64, test_atomic_u32, test_atomic_p,
|
||||
test_atomic_zu, test_atomic_zd, test_atomic_u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,13 @@
|
|||
|
||||
static void
|
||||
test_switch_background_thread_ctl(bool new_val) {
|
||||
bool e0, e1;
|
||||
bool e0, e1;
|
||||
size_t sz = sizeof(bool);
|
||||
|
||||
e1 = new_val;
|
||||
expect_d_eq(mallctl("background_thread", (void *)&e0, &sz,
|
||||
&e1, sz), 0, "Unexpected mallctl() failure");
|
||||
expect_b_eq(e0, !e1,
|
||||
"background_thread should be %d before.\n", !e1);
|
||||
expect_d_eq(mallctl("background_thread", (void *)&e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
expect_b_eq(e0, !e1, "background_thread should be %d before.\n", !e1);
|
||||
if (e1) {
|
||||
expect_zu_gt(n_background_threads, 0,
|
||||
"Number of background threads should be non zero.\n");
|
||||
|
|
@ -23,14 +22,13 @@ test_switch_background_thread_ctl(bool new_val) {
|
|||
|
||||
static void
|
||||
test_repeat_background_thread_ctl(bool before) {
|
||||
bool e0, e1;
|
||||
bool e0, e1;
|
||||
size_t sz = sizeof(bool);
|
||||
|
||||
e1 = before;
|
||||
expect_d_eq(mallctl("background_thread", (void *)&e0, &sz,
|
||||
&e1, sz), 0, "Unexpected mallctl() failure");
|
||||
expect_b_eq(e0, before,
|
||||
"background_thread should be %d.\n", before);
|
||||
expect_d_eq(mallctl("background_thread", (void *)&e0, &sz, &e1, sz), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
expect_b_eq(e0, before, "background_thread should be %d.\n", before);
|
||||
if (e1) {
|
||||
expect_zu_gt(n_background_threads, 0,
|
||||
"Number of background threads should be non zero.\n");
|
||||
|
|
@ -43,15 +41,15 @@ test_repeat_background_thread_ctl(bool before) {
|
|||
TEST_BEGIN(test_background_thread_ctl) {
|
||||
test_skip_if(!have_background_thread);
|
||||
|
||||
bool e0, e1;
|
||||
bool e0, e1;
|
||||
size_t sz = sizeof(bool);
|
||||
|
||||
expect_d_eq(mallctl("opt.background_thread", (void *)&e0, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("background_thread", (void *)&e1, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctl() failure");
|
||||
expect_b_eq(e0, e1,
|
||||
"Default and opt.background_thread does not match.\n");
|
||||
expect_d_eq(mallctl("opt.background_thread", (void *)&e0, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("background_thread", (void *)&e1, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
expect_b_eq(
|
||||
e0, e1, "Default and opt.background_thread does not match.\n");
|
||||
if (e0) {
|
||||
test_switch_background_thread_ctl(false);
|
||||
}
|
||||
|
|
@ -75,7 +73,7 @@ TEST_BEGIN(test_background_thread_running) {
|
|||
test_skip_if(!config_stats);
|
||||
|
||||
#if defined(JEMALLOC_BACKGROUND_THREAD)
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
background_thread_info_t *info = &background_thread_info[0];
|
||||
|
||||
test_repeat_background_thread_ctl(false);
|
||||
|
|
@ -113,6 +111,5 @@ int
|
|||
main(void) {
|
||||
/* Background_thread creation tests reentrancy naturally. */
|
||||
return test_no_reentrancy(
|
||||
test_background_thread_ctl,
|
||||
test_background_thread_running);
|
||||
test_background_thread_ctl, test_background_thread_running);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
const char *malloc_conf = "background_thread:false,narenas:1,max_background_threads:8";
|
||||
const char *malloc_conf =
|
||||
"background_thread:false,narenas:1,max_background_threads:8";
|
||||
|
||||
static unsigned
|
||||
max_test_narenas(void) {
|
||||
|
|
@ -21,14 +22,14 @@ TEST_BEGIN(test_deferred) {
|
|||
test_skip_if(!have_background_thread);
|
||||
|
||||
unsigned id;
|
||||
size_t sz_u = sizeof(unsigned);
|
||||
size_t sz_u = sizeof(unsigned);
|
||||
|
||||
for (unsigned i = 0; i < max_test_narenas(); i++) {
|
||||
expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
|
||||
"Failed to create arena");
|
||||
}
|
||||
|
||||
bool enable = true;
|
||||
bool enable = true;
|
||||
size_t sz_b = sizeof(bool);
|
||||
expect_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
|
||||
"Failed to enable background threads");
|
||||
|
|
@ -44,29 +45,32 @@ TEST_BEGIN(test_max_background_threads) {
|
|||
size_t max_n_thds;
|
||||
size_t opt_max_n_thds;
|
||||
size_t sz_m = sizeof(max_n_thds);
|
||||
expect_d_eq(mallctl("opt.max_background_threads",
|
||||
&opt_max_n_thds, &sz_m, NULL, 0), 0,
|
||||
"Failed to get opt.max_background_threads");
|
||||
expect_d_eq(mallctl("max_background_threads", &max_n_thds, &sz_m, NULL,
|
||||
0), 0, "Failed to get max background threads");
|
||||
expect_d_eq(mallctl("opt.max_background_threads", &opt_max_n_thds,
|
||||
&sz_m, NULL, 0),
|
||||
0, "Failed to get opt.max_background_threads");
|
||||
expect_d_eq(
|
||||
mallctl("max_background_threads", &max_n_thds, &sz_m, NULL, 0), 0,
|
||||
"Failed to get max background threads");
|
||||
expect_zu_eq(opt_max_n_thds, max_n_thds,
|
||||
"max_background_threads and "
|
||||
"opt.max_background_threads should match");
|
||||
expect_d_eq(mallctl("max_background_threads", NULL, NULL, &max_n_thds,
|
||||
sz_m), 0, "Failed to set max background threads");
|
||||
expect_d_eq(
|
||||
mallctl("max_background_threads", NULL, NULL, &max_n_thds, sz_m), 0,
|
||||
"Failed to set max background threads");
|
||||
size_t size_zero = 0;
|
||||
expect_d_ne(mallctl("max_background_threads", NULL, NULL, &size_zero,
|
||||
sz_m), 0, "Should not allow zero background threads");
|
||||
expect_d_ne(
|
||||
mallctl("max_background_threads", NULL, NULL, &size_zero, sz_m), 0,
|
||||
"Should not allow zero background threads");
|
||||
|
||||
unsigned id;
|
||||
size_t sz_u = sizeof(unsigned);
|
||||
size_t sz_u = sizeof(unsigned);
|
||||
|
||||
for (unsigned i = 0; i < max_test_narenas(); i++) {
|
||||
expect_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0,
|
||||
"Failed to create arena");
|
||||
}
|
||||
|
||||
bool enable = true;
|
||||
bool enable = true;
|
||||
size_t sz_b = sizeof(bool);
|
||||
expect_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0,
|
||||
"Failed to enable background threads");
|
||||
|
|
@ -75,16 +79,18 @@ TEST_BEGIN(test_max_background_threads) {
|
|||
size_t new_max_thds = max_n_thds - 1;
|
||||
if (new_max_thds > 0) {
|
||||
expect_d_eq(mallctl("max_background_threads", NULL, NULL,
|
||||
&new_max_thds, sz_m), 0,
|
||||
"Failed to set max background threads");
|
||||
&new_max_thds, sz_m),
|
||||
0, "Failed to set max background threads");
|
||||
expect_zu_eq(n_background_threads, new_max_thds,
|
||||
"Number of background threads should decrease by 1.\n");
|
||||
}
|
||||
new_max_thds = 1;
|
||||
expect_d_eq(mallctl("max_background_threads", NULL, NULL, &new_max_thds,
|
||||
sz_m), 0, "Failed to set max background threads");
|
||||
expect_d_ne(mallctl("max_background_threads", NULL, NULL, &size_zero,
|
||||
sz_m), 0, "Should not allow zero background threads");
|
||||
expect_d_eq(
|
||||
mallctl("max_background_threads", NULL, NULL, &new_max_thds, sz_m),
|
||||
0, "Failed to set max background threads");
|
||||
expect_d_ne(
|
||||
mallctl("max_background_threads", NULL, NULL, &size_zero, sz_m), 0,
|
||||
"Should not allow zero background threads");
|
||||
expect_zu_eq(n_background_threads, new_max_thds,
|
||||
"Number of background threads should be 1.\n");
|
||||
}
|
||||
|
|
@ -92,7 +98,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_deferred,
|
||||
test_max_background_threads);
|
||||
return test_no_reentrancy(test_deferred, test_max_background_threads);
|
||||
}
|
||||
|
|
|
|||
125
test/unit/base.c
125
test/unit/base.c
|
|
@ -3,37 +3,31 @@
|
|||
#include "test/extent_hooks.h"
|
||||
|
||||
static extent_hooks_t hooks_null = {
|
||||
extent_alloc_hook,
|
||||
NULL, /* dalloc */
|
||||
NULL, /* destroy */
|
||||
NULL, /* commit */
|
||||
NULL, /* decommit */
|
||||
NULL, /* purge_lazy */
|
||||
NULL, /* purge_forced */
|
||||
NULL, /* split */
|
||||
NULL /* merge */
|
||||
extent_alloc_hook, NULL, /* dalloc */
|
||||
NULL, /* destroy */
|
||||
NULL, /* commit */
|
||||
NULL, /* decommit */
|
||||
NULL, /* purge_lazy */
|
||||
NULL, /* purge_forced */
|
||||
NULL, /* split */
|
||||
NULL /* merge */
|
||||
};
|
||||
|
||||
static extent_hooks_t hooks_not_null = {
|
||||
extent_alloc_hook,
|
||||
extent_dalloc_hook,
|
||||
extent_destroy_hook,
|
||||
NULL, /* commit */
|
||||
extent_decommit_hook,
|
||||
extent_purge_lazy_hook,
|
||||
extent_purge_forced_hook,
|
||||
NULL, /* split */
|
||||
NULL /* merge */
|
||||
extent_alloc_hook, extent_dalloc_hook, extent_destroy_hook,
|
||||
NULL, /* commit */
|
||||
extent_decommit_hook, extent_purge_lazy_hook, extent_purge_forced_hook,
|
||||
NULL, /* split */
|
||||
NULL /* merge */
|
||||
};
|
||||
|
||||
TEST_BEGIN(test_base_hooks_default) {
|
||||
base_t *base;
|
||||
size_t allocated0, allocated1, edata_allocated,
|
||||
rtree_allocated, resident, mapped, n_thp;
|
||||
size_t allocated0, allocated1, edata_allocated, rtree_allocated,
|
||||
resident, mapped, n_thp;
|
||||
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
base = base_new(tsdn, 0,
|
||||
(extent_hooks_t *)&ehooks_default_extent_hooks,
|
||||
base = base_new(tsdn, 0, (extent_hooks_t *)&ehooks_default_extent_hooks,
|
||||
/* metadata_use_hooks */ true);
|
||||
|
||||
if (config_stats) {
|
||||
|
|
@ -42,13 +36,13 @@ TEST_BEGIN(test_base_hooks_default) {
|
|||
expect_zu_ge(allocated0, sizeof(base_t),
|
||||
"Base header should count as allocated");
|
||||
if (opt_metadata_thp == metadata_thp_always) {
|
||||
expect_zu_gt(n_thp, 0,
|
||||
"Base should have 1 THP at least.");
|
||||
expect_zu_gt(
|
||||
n_thp, 0, "Base should have 1 THP at least.");
|
||||
}
|
||||
}
|
||||
|
||||
expect_ptr_not_null(base_alloc(tsdn, base, 42, 1),
|
||||
"Unexpected base_alloc() failure");
|
||||
expect_ptr_not_null(
|
||||
base_alloc(tsdn, base, 42, 1), "Unexpected base_alloc() failure");
|
||||
|
||||
if (config_stats) {
|
||||
base_stats_get(tsdn, base, &allocated1, &edata_allocated,
|
||||
|
|
@ -63,9 +57,9 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_base_hooks_null) {
|
||||
extent_hooks_t hooks_orig;
|
||||
base_t *base;
|
||||
size_t allocated0, allocated1, edata_allocated,
|
||||
rtree_allocated, resident, mapped, n_thp;
|
||||
base_t *base;
|
||||
size_t allocated0, allocated1, edata_allocated, rtree_allocated,
|
||||
resident, mapped, n_thp;
|
||||
|
||||
extent_hooks_prep();
|
||||
try_dalloc = false;
|
||||
|
|
@ -86,13 +80,13 @@ TEST_BEGIN(test_base_hooks_null) {
|
|||
expect_zu_ge(allocated0, sizeof(base_t),
|
||||
"Base header should count as allocated");
|
||||
if (opt_metadata_thp == metadata_thp_always) {
|
||||
expect_zu_gt(n_thp, 0,
|
||||
"Base should have 1 THP at least.");
|
||||
expect_zu_gt(
|
||||
n_thp, 0, "Base should have 1 THP at least.");
|
||||
}
|
||||
}
|
||||
|
||||
expect_ptr_not_null(base_alloc(tsdn, base, 42, 1),
|
||||
"Unexpected base_alloc() failure");
|
||||
expect_ptr_not_null(
|
||||
base_alloc(tsdn, base, 42, 1), "Unexpected base_alloc() failure");
|
||||
|
||||
if (config_stats) {
|
||||
base_stats_get(tsdn, base, &allocated1, &edata_allocated,
|
||||
|
|
@ -109,8 +103,8 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_base_hooks_not_null) {
|
||||
extent_hooks_t hooks_orig;
|
||||
base_t *base;
|
||||
void *p, *q, *r, *r_exp;
|
||||
base_t *base;
|
||||
void *p, *q, *r, *r_exp;
|
||||
|
||||
extent_hooks_prep();
|
||||
try_dalloc = false;
|
||||
|
|
@ -133,33 +127,34 @@ TEST_BEGIN(test_base_hooks_not_null) {
|
|||
*/
|
||||
{
|
||||
const size_t alignments[] = {
|
||||
1,
|
||||
QUANTUM,
|
||||
QUANTUM << 1,
|
||||
CACHELINE,
|
||||
CACHELINE << 1,
|
||||
1,
|
||||
QUANTUM,
|
||||
QUANTUM << 1,
|
||||
CACHELINE,
|
||||
CACHELINE << 1,
|
||||
};
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sizeof(alignments) / sizeof(size_t); i++) {
|
||||
size_t alignment = alignments[i];
|
||||
size_t align_ceil = ALIGNMENT_CEILING(alignment,
|
||||
QUANTUM);
|
||||
size_t align_ceil = ALIGNMENT_CEILING(
|
||||
alignment, QUANTUM);
|
||||
p = base_alloc(tsdn, base, 1, alignment);
|
||||
expect_ptr_not_null(p,
|
||||
"Unexpected base_alloc() failure");
|
||||
expect_ptr_not_null(
|
||||
p, "Unexpected base_alloc() failure");
|
||||
expect_ptr_eq(p,
|
||||
(void *)(ALIGNMENT_CEILING((uintptr_t)p,
|
||||
alignment)), "Expected quantum alignment");
|
||||
(void *)(ALIGNMENT_CEILING(
|
||||
(uintptr_t)p, alignment)),
|
||||
"Expected quantum alignment");
|
||||
q = base_alloc(tsdn, base, alignment, alignment);
|
||||
expect_ptr_not_null(q,
|
||||
"Unexpected base_alloc() failure");
|
||||
expect_ptr_not_null(
|
||||
q, "Unexpected base_alloc() failure");
|
||||
expect_ptr_eq((void *)((uintptr_t)p + align_ceil), q,
|
||||
"Minimal allocation should take up %zu bytes",
|
||||
align_ceil);
|
||||
r = base_alloc(tsdn, base, 1, alignment);
|
||||
expect_ptr_not_null(r,
|
||||
"Unexpected base_alloc() failure");
|
||||
expect_ptr_not_null(
|
||||
r, "Unexpected base_alloc() failure");
|
||||
expect_ptr_eq((void *)((uintptr_t)q + align_ceil), r,
|
||||
"Minimal allocation should take up %zu bytes",
|
||||
align_ceil);
|
||||
|
|
@ -193,21 +188,18 @@ TEST_BEGIN(test_base_hooks_not_null) {
|
|||
* Check for proper alignment support when normal blocks are too small.
|
||||
*/
|
||||
{
|
||||
const size_t alignments[] = {
|
||||
HUGEPAGE,
|
||||
HUGEPAGE << 1
|
||||
};
|
||||
unsigned i;
|
||||
const size_t alignments[] = {HUGEPAGE, HUGEPAGE << 1};
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sizeof(alignments) / sizeof(size_t); i++) {
|
||||
size_t alignment = alignments[i];
|
||||
p = base_alloc(tsdn, base, QUANTUM, alignment);
|
||||
expect_ptr_not_null(p,
|
||||
"Unexpected base_alloc() failure");
|
||||
expect_ptr_not_null(
|
||||
p, "Unexpected base_alloc() failure");
|
||||
expect_ptr_eq(p,
|
||||
(void *)(ALIGNMENT_CEILING((uintptr_t)p,
|
||||
alignment)), "Expected %zu-byte alignment",
|
||||
alignment);
|
||||
(void *)(ALIGNMENT_CEILING(
|
||||
(uintptr_t)p, alignment)),
|
||||
"Expected %zu-byte alignment", alignment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -237,12 +229,11 @@ TEST_BEGIN(test_base_ehooks_get_for_metadata_default_hook) {
|
|||
base = base_new(tsdn, 0, &hooks, /* metadata_use_hooks */ false);
|
||||
ehooks_t *ehooks = base_ehooks_get_for_metadata(base);
|
||||
expect_true(ehooks_are_default(ehooks),
|
||||
"Expected default extent hook functions pointer");
|
||||
"Expected default extent hook functions pointer");
|
||||
base_delete(tsdn, base);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
||||
TEST_BEGIN(test_base_ehooks_get_for_metadata_custom_hook) {
|
||||
extent_hooks_prep();
|
||||
memcpy(&hooks, &hooks_not_null, sizeof(extent_hooks_t));
|
||||
|
|
@ -251,17 +242,15 @@ TEST_BEGIN(test_base_ehooks_get_for_metadata_custom_hook) {
|
|||
base = base_new(tsdn, 0, &hooks, /* metadata_use_hooks */ true);
|
||||
ehooks_t *ehooks = base_ehooks_get_for_metadata(base);
|
||||
expect_ptr_eq(&hooks, ehooks_get_extent_hooks_ptr(ehooks),
|
||||
"Expected user-specified extend hook functions pointer");
|
||||
"Expected user-specified extend hook functions pointer");
|
||||
base_delete(tsdn, base);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_base_hooks_default,
|
||||
test_base_hooks_null,
|
||||
return test(test_base_hooks_default, test_base_hooks_null,
|
||||
test_base_hooks_not_null,
|
||||
test_base_ehooks_get_for_metadata_default_hook,
|
||||
test_base_ehooks_get_for_metadata_custom_hook);
|
||||
test_base_ehooks_get_for_metadata_default_hook,
|
||||
test_base_ehooks_get_for_metadata_custom_hook);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ static void *global_ptrs[BATCH_MAX];
|
|||
#define PAGE_ALIGNED(ptr) (((uintptr_t)ptr & PAGE_MASK) == 0)
|
||||
|
||||
static void
|
||||
verify_batch_basic(tsd_t *tsd, void **ptrs, size_t batch, size_t usize,
|
||||
bool zero) {
|
||||
verify_batch_basic(
|
||||
tsd_t *tsd, void **ptrs, size_t batch, size_t usize, bool zero) {
|
||||
for (size_t i = 0; i < batch; ++i) {
|
||||
void *p = ptrs[i];
|
||||
expect_zu_eq(isalloc(tsd_tsdn(tsd), p), usize, "");
|
||||
|
|
@ -46,7 +46,8 @@ verify_batch_locality(tsd_t *tsd, void **ptrs, size_t batch, size_t usize,
|
|||
assert(i > 0);
|
||||
void *q = ptrs[i - 1];
|
||||
expect_true((uintptr_t)p > (uintptr_t)q
|
||||
&& (size_t)((uintptr_t)p - (uintptr_t)q) == usize, "");
|
||||
&& (size_t)((uintptr_t)p - (uintptr_t)q) == usize,
|
||||
"");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,16 +63,17 @@ struct batch_alloc_packet_s {
|
|||
void **ptrs;
|
||||
size_t num;
|
||||
size_t size;
|
||||
int flags;
|
||||
int flags;
|
||||
};
|
||||
|
||||
static size_t
|
||||
batch_alloc_wrapper(void **ptrs, size_t num, size_t size, int flags) {
|
||||
batch_alloc_packet_t batch_alloc_packet = {ptrs, num, size, flags};
|
||||
size_t filled;
|
||||
size_t len = sizeof(size_t);
|
||||
size_t filled;
|
||||
size_t len = sizeof(size_t);
|
||||
assert_d_eq(mallctl("experimental.batch_alloc", &filled, &len,
|
||||
&batch_alloc_packet, sizeof(batch_alloc_packet)), 0, "");
|
||||
&batch_alloc_packet, sizeof(batch_alloc_packet)),
|
||||
0, "");
|
||||
return filled;
|
||||
}
|
||||
|
||||
|
|
@ -79,16 +81,16 @@ static void
|
|||
test_wrapper(size_t size, size_t alignment, bool zero, unsigned arena_flag) {
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
assert(tsd != NULL);
|
||||
const size_t usize =
|
||||
(alignment != 0 ? sz_sa2u(size, alignment) : sz_s2u(size));
|
||||
const szind_t ind = sz_size2index(usize);
|
||||
const size_t usize = (alignment != 0 ? sz_sa2u(size, alignment)
|
||||
: sz_s2u(size));
|
||||
const szind_t ind = sz_size2index(usize);
|
||||
const bin_info_t *bin_info = &bin_infos[ind];
|
||||
const unsigned nregs = bin_info->nregs;
|
||||
const unsigned nregs = bin_info->nregs;
|
||||
assert(nregs > 0);
|
||||
arena_t *arena;
|
||||
if (arena_flag != 0) {
|
||||
arena = arena_get(tsd_tsdn(tsd), MALLOCX_ARENA_GET(arena_flag),
|
||||
false);
|
||||
arena = arena_get(
|
||||
tsd_tsdn(tsd), MALLOCX_ARENA_GET(arena_flag), false);
|
||||
} else {
|
||||
arena = arena_choose(tsd, NULL);
|
||||
}
|
||||
|
|
@ -122,13 +124,13 @@ test_wrapper(size_t size, size_t alignment, bool zero, unsigned arena_flag) {
|
|||
}
|
||||
size_t batch = base + (size_t)j;
|
||||
assert(batch < BATCH_MAX);
|
||||
size_t filled = batch_alloc_wrapper(global_ptrs, batch,
|
||||
size, flags);
|
||||
size_t filled = batch_alloc_wrapper(
|
||||
global_ptrs, batch, size, flags);
|
||||
assert_zu_eq(filled, batch, "");
|
||||
verify_batch_basic(tsd, global_ptrs, batch, usize,
|
||||
zero);
|
||||
verify_batch_locality(tsd, global_ptrs, batch, usize,
|
||||
arena, nregs);
|
||||
verify_batch_basic(
|
||||
tsd, global_ptrs, batch, usize, zero);
|
||||
verify_batch_locality(
|
||||
tsd, global_ptrs, batch, usize, arena, nregs);
|
||||
release_batch(global_ptrs, batch, usize);
|
||||
}
|
||||
}
|
||||
|
|
@ -153,9 +155,10 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_batch_alloc_manual_arena) {
|
||||
unsigned arena_ind;
|
||||
size_t len_unsigned = sizeof(unsigned);
|
||||
assert_d_eq(mallctl("arenas.create", &arena_ind, &len_unsigned, NULL,
|
||||
0), 0, "");
|
||||
size_t len_unsigned = sizeof(unsigned);
|
||||
assert_d_eq(
|
||||
mallctl("arenas.create", &arena_ind, &len_unsigned, NULL, 0), 0,
|
||||
"");
|
||||
test_wrapper(11, 0, false, MALLOCX_ARENA(arena_ind));
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -180,10 +183,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_batch_alloc,
|
||||
test_batch_alloc_zero,
|
||||
test_batch_alloc_aligned,
|
||||
test_batch_alloc_manual_arena,
|
||||
return test(test_batch_alloc, test_batch_alloc_zero,
|
||||
test_batch_alloc_aligned, test_batch_alloc_manual_arena,
|
||||
test_batch_alloc_large);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
TEST_BEGIN(test_simple) {
|
||||
enum { NELEMS_MAX = 10, DATA_BASE_VAL = 100, NRUNS = 5 };
|
||||
batcher_t batcher;
|
||||
size_t data[NELEMS_MAX];
|
||||
size_t data[NELEMS_MAX];
|
||||
for (size_t nelems = 0; nelems < NELEMS_MAX; nelems++) {
|
||||
batcher_init(&batcher, nelems);
|
||||
for (int run = 0; run < NRUNS; run++) {
|
||||
|
|
@ -13,8 +13,8 @@ TEST_BEGIN(test_simple) {
|
|||
data[i] = (size_t)-1;
|
||||
}
|
||||
for (size_t i = 0; i < nelems; i++) {
|
||||
size_t idx = batcher_push_begin(TSDN_NULL,
|
||||
&batcher, 1);
|
||||
size_t idx = batcher_push_begin(
|
||||
TSDN_NULL, &batcher, 1);
|
||||
assert_zu_eq(i, idx, "Wrong index");
|
||||
assert_zu_eq((size_t)-1, data[idx],
|
||||
"Expected uninitialized slot");
|
||||
|
|
@ -22,8 +22,8 @@ TEST_BEGIN(test_simple) {
|
|||
batcher_push_end(TSDN_NULL, &batcher);
|
||||
}
|
||||
if (nelems > 0) {
|
||||
size_t idx = batcher_push_begin(TSDN_NULL,
|
||||
&batcher, 1);
|
||||
size_t idx = batcher_push_begin(
|
||||
TSDN_NULL, &batcher, 1);
|
||||
assert_zu_eq(BATCHER_NO_IDX, idx,
|
||||
"Shouldn't be able to push into a full "
|
||||
"batcher");
|
||||
|
|
@ -51,7 +51,7 @@ TEST_BEGIN(test_simple) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_multi_push) {
|
||||
size_t idx, nelems;
|
||||
size_t idx, nelems;
|
||||
batcher_t batcher;
|
||||
batcher_init(&batcher, 11);
|
||||
/* Push two at a time, 5 times, for 10 total. */
|
||||
|
|
@ -82,13 +82,13 @@ enum {
|
|||
|
||||
typedef struct stress_test_data_s stress_test_data_t;
|
||||
struct stress_test_data_s {
|
||||
batcher_t batcher;
|
||||
mtx_t pop_mtx;
|
||||
batcher_t batcher;
|
||||
mtx_t pop_mtx;
|
||||
atomic_u32_t thread_id;
|
||||
|
||||
uint32_t elems_data[STRESS_TEST_ELEMS];
|
||||
size_t push_count[STRESS_TEST_ELEMS];
|
||||
size_t pop_count[STRESS_TEST_ELEMS];
|
||||
uint32_t elems_data[STRESS_TEST_ELEMS];
|
||||
size_t push_count[STRESS_TEST_ELEMS];
|
||||
size_t pop_count[STRESS_TEST_ELEMS];
|
||||
atomic_zu_t atomic_push_count[STRESS_TEST_ELEMS];
|
||||
atomic_zu_t atomic_pop_count[STRESS_TEST_ELEMS];
|
||||
};
|
||||
|
|
@ -108,7 +108,8 @@ get_nth_set(bool elems_owned[STRESS_TEST_ELEMS], size_t n) {
|
|||
return i;
|
||||
}
|
||||
}
|
||||
assert_not_reached("Asked for the %zu'th set element when < %zu are "
|
||||
assert_not_reached(
|
||||
"Asked for the %zu'th set element when < %zu are "
|
||||
"set",
|
||||
n, n);
|
||||
/* Just to silence a compiler warning. */
|
||||
|
|
@ -118,20 +119,19 @@ get_nth_set(bool elems_owned[STRESS_TEST_ELEMS], size_t n) {
|
|||
static void *
|
||||
stress_test_thd(void *arg) {
|
||||
stress_test_data_t *data = arg;
|
||||
size_t prng = atomic_fetch_add_u32(&data->thread_id, 1,
|
||||
ATOMIC_RELAXED);
|
||||
size_t prng = atomic_fetch_add_u32(&data->thread_id, 1, ATOMIC_RELAXED);
|
||||
|
||||
size_t nelems_owned = 0;
|
||||
bool elems_owned[STRESS_TEST_ELEMS] = {0};
|
||||
bool elems_owned[STRESS_TEST_ELEMS] = {0};
|
||||
size_t local_push_count[STRESS_TEST_ELEMS] = {0};
|
||||
size_t local_pop_count[STRESS_TEST_ELEMS] = {0};
|
||||
|
||||
for (int i = 0; i < STRESS_TEST_OPS; i++) {
|
||||
size_t rnd = prng_range_zu(&prng,
|
||||
STRESS_TEST_PUSH_TO_POP_RATIO);
|
||||
size_t rnd = prng_range_zu(
|
||||
&prng, STRESS_TEST_PUSH_TO_POP_RATIO);
|
||||
if (rnd == 0 || nelems_owned == 0) {
|
||||
size_t nelems = batcher_pop_begin(TSDN_NULL,
|
||||
&data->batcher);
|
||||
size_t nelems = batcher_pop_begin(
|
||||
TSDN_NULL, &data->batcher);
|
||||
if (nelems == BATCHER_NO_IDX) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -147,19 +147,18 @@ stress_test_thd(void *arg) {
|
|||
}
|
||||
batcher_pop_end(TSDN_NULL, &data->batcher);
|
||||
} else {
|
||||
size_t elem_to_push_idx = prng_range_zu(&prng,
|
||||
nelems_owned);
|
||||
size_t elem = get_nth_set(elems_owned,
|
||||
elem_to_push_idx);
|
||||
assert_true(
|
||||
elems_owned[elem],
|
||||
size_t elem_to_push_idx = prng_range_zu(
|
||||
&prng, nelems_owned);
|
||||
size_t elem = get_nth_set(
|
||||
elems_owned, elem_to_push_idx);
|
||||
assert_true(elems_owned[elem],
|
||||
"Should own element we're about to pop");
|
||||
elems_owned[elem] = false;
|
||||
local_push_count[elem]++;
|
||||
data->push_count[elem]++;
|
||||
nelems_owned--;
|
||||
size_t idx = batcher_push_begin(TSDN_NULL,
|
||||
&data->batcher, 1);
|
||||
size_t idx = batcher_push_begin(
|
||||
TSDN_NULL, &data->batcher, 1);
|
||||
assert_zu_ne(idx, BATCHER_NO_IDX,
|
||||
"Batcher can't be full -- we have one of its "
|
||||
"elems!");
|
||||
|
|
@ -171,10 +170,10 @@ stress_test_thd(void *arg) {
|
|||
/* Push all local elems back, flush local counts to the shared ones. */
|
||||
size_t push_idx = 0;
|
||||
if (nelems_owned != 0) {
|
||||
push_idx = batcher_push_begin(TSDN_NULL, &data->batcher,
|
||||
nelems_owned);
|
||||
assert_zu_ne(BATCHER_NO_IDX, push_idx,
|
||||
"Should be space to push");
|
||||
push_idx = batcher_push_begin(
|
||||
TSDN_NULL, &data->batcher, nelems_owned);
|
||||
assert_zu_ne(
|
||||
BATCHER_NO_IDX, push_idx, "Should be space to push");
|
||||
}
|
||||
for (size_t i = 0; i < STRESS_TEST_ELEMS; i++) {
|
||||
if (elems_owned[i]) {
|
||||
|
|
@ -183,12 +182,10 @@ stress_test_thd(void *arg) {
|
|||
local_push_count[i]++;
|
||||
data->push_count[i]++;
|
||||
}
|
||||
atomic_fetch_add_zu(
|
||||
&data->atomic_push_count[i], local_push_count[i],
|
||||
ATOMIC_RELAXED);
|
||||
atomic_fetch_add_zu(
|
||||
&data->atomic_pop_count[i], local_pop_count[i],
|
||||
ATOMIC_RELAXED);
|
||||
atomic_fetch_add_zu(&data->atomic_push_count[i],
|
||||
local_push_count[i], ATOMIC_RELAXED);
|
||||
atomic_fetch_add_zu(&data->atomic_pop_count[i],
|
||||
local_pop_count[i], ATOMIC_RELAXED);
|
||||
}
|
||||
if (nelems_owned != 0) {
|
||||
batcher_push_end(TSDN_NULL, &data->batcher);
|
||||
|
|
@ -223,8 +220,8 @@ TEST_BEGIN(test_stress) {
|
|||
thd_join(threads[i], NULL);
|
||||
}
|
||||
for (int i = 0; i < STRESS_TEST_ELEMS; i++) {
|
||||
assert_zu_ne(0, data.push_count[i],
|
||||
"Should have done something!");
|
||||
assert_zu_ne(
|
||||
0, data.push_count[i], "Should have done something!");
|
||||
assert_zu_eq(data.push_count[i], data.pop_count[i],
|
||||
"every element should be pushed and popped an equal number "
|
||||
"of times");
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ enum {
|
|||
|
||||
typedef struct stress_thread_data_s stress_thread_data_t;
|
||||
struct stress_thread_data_s {
|
||||
unsigned thd_id;
|
||||
unsigned thd_id;
|
||||
atomic_zu_t *ready_thds;
|
||||
atomic_zu_t *done_thds;
|
||||
void **to_dalloc;
|
||||
void **to_dalloc;
|
||||
};
|
||||
|
||||
static atomic_zu_t push_failure_count;
|
||||
|
|
@ -68,19 +68,19 @@ increment_pop_attempt(size_t elems_to_pop) {
|
|||
static void
|
||||
increment_slab_dalloc_count(unsigned slab_dalloc_count, bool list_empty) {
|
||||
if (slab_dalloc_count > 0) {
|
||||
atomic_fetch_add_zu(&dalloc_nonzero_slab_count, 1,
|
||||
ATOMIC_RELAXED);
|
||||
atomic_fetch_add_zu(
|
||||
&dalloc_nonzero_slab_count, 1, ATOMIC_RELAXED);
|
||||
} else {
|
||||
atomic_fetch_add_zu(&dalloc_zero_slab_count, 1,
|
||||
ATOMIC_RELAXED);
|
||||
atomic_fetch_add_zu(&dalloc_zero_slab_count, 1, ATOMIC_RELAXED);
|
||||
}
|
||||
if (!list_empty) {
|
||||
atomic_fetch_add_zu(&dalloc_nonempty_list_count, 1,
|
||||
ATOMIC_RELAXED);
|
||||
atomic_fetch_add_zu(
|
||||
&dalloc_nonempty_list_count, 1, ATOMIC_RELAXED);
|
||||
}
|
||||
}
|
||||
|
||||
static void flush_tcache() {
|
||||
static void
|
||||
flush_tcache() {
|
||||
assert_d_eq(0, mallctl("thread.tcache.flush", NULL, NULL, NULL, 0),
|
||||
"Unexpected mallctl failure");
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ static void flush_tcache() {
|
|||
static void *
|
||||
stress_thread(void *arg) {
|
||||
stress_thread_data_t *data = arg;
|
||||
uint64_t prng_state = data->thd_id;
|
||||
uint64_t prng_state = data->thd_id;
|
||||
atomic_fetch_add_zu(data->ready_thds, 1, ATOMIC_RELAXED);
|
||||
while (atomic_load_zu(data->ready_thds, ATOMIC_RELAXED)
|
||||
!= STRESS_THREADS) {
|
||||
|
|
@ -99,7 +99,6 @@ stress_thread(void *arg) {
|
|||
if (prng_range_u64(&prng_state, 3) == 0) {
|
||||
flush_tcache();
|
||||
}
|
||||
|
||||
}
|
||||
flush_tcache();
|
||||
atomic_fetch_add_zu(data->done_thds, 1, ATOMIC_RELAXED);
|
||||
|
|
@ -125,9 +124,9 @@ stress_run(void (*main_thread_fn)(), int nruns) {
|
|||
atomic_store_zu(&dalloc_nonempty_list_count, 0, ATOMIC_RELAXED);
|
||||
|
||||
for (int run = 0; run < nruns; run++) {
|
||||
thd_t thds[STRESS_THREADS];
|
||||
thd_t thds[STRESS_THREADS];
|
||||
stress_thread_data_t thd_datas[STRESS_THREADS];
|
||||
atomic_zu_t ready_thds;
|
||||
atomic_zu_t ready_thds;
|
||||
atomic_store_zu(&ready_thds, 0, ATOMIC_RELAXED);
|
||||
atomic_zu_t done_thds;
|
||||
atomic_store_zu(&done_thds, 0, ATOMIC_RELAXED);
|
||||
|
|
@ -164,7 +163,7 @@ stress_run(void (*main_thread_fn)(), int nruns) {
|
|||
|
||||
static void
|
||||
do_allocs_frees() {
|
||||
enum {NALLOCS = 32};
|
||||
enum { NALLOCS = 32 };
|
||||
flush_tcache();
|
||||
void *ptrs[NALLOCS];
|
||||
for (int i = 0; i < NALLOCS; i++) {
|
||||
|
|
@ -182,7 +181,7 @@ test_arena_reset_main_fn() {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_arena_reset) {
|
||||
int err;
|
||||
int err;
|
||||
unsigned arena;
|
||||
unsigned old_arena;
|
||||
|
||||
|
|
@ -256,17 +255,16 @@ TEST_BEGIN(test_races) {
|
|||
"Should have seen some pop successes");
|
||||
assert_zu_lt(0, atomic_load_zu(&dalloc_zero_slab_count, ATOMIC_RELAXED),
|
||||
"Expected some frees that didn't empty a slab");
|
||||
assert_zu_lt(0, atomic_load_zu(&dalloc_nonzero_slab_count,
|
||||
ATOMIC_RELAXED), "expected some frees that emptied a slab");
|
||||
assert_zu_lt(0, atomic_load_zu(&dalloc_nonempty_list_count,
|
||||
ATOMIC_RELAXED), "expected some frees that used the empty list");
|
||||
assert_zu_lt(0,
|
||||
atomic_load_zu(&dalloc_nonzero_slab_count, ATOMIC_RELAXED),
|
||||
"expected some frees that emptied a slab");
|
||||
assert_zu_lt(0,
|
||||
atomic_load_zu(&dalloc_nonempty_list_count, ATOMIC_RELAXED),
|
||||
"expected some frees that used the empty list");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_arena_reset,
|
||||
test_races,
|
||||
test_fork);
|
||||
return test_no_reentrancy(test_arena_reset, test_races, test_fork);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
static void *
|
||||
thd_producer(void *varg) {
|
||||
void **mem = varg;
|
||||
void **mem = varg;
|
||||
unsigned arena, i;
|
||||
size_t sz;
|
||||
size_t sz;
|
||||
|
||||
sz = sizeof(arena);
|
||||
/* Remote arena. */
|
||||
|
|
@ -28,8 +28,8 @@ thd_producer(void *varg) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_producer_consumer) {
|
||||
thd_t thds[NTHREADS];
|
||||
void *mem[NTHREADS][REMOTE_NALLOC];
|
||||
thd_t thds[NTHREADS];
|
||||
void *mem[NTHREADS][REMOTE_NALLOC];
|
||||
unsigned i;
|
||||
|
||||
/* Create producer threads to allocate. */
|
||||
|
|
@ -42,8 +42,8 @@ TEST_BEGIN(test_producer_consumer) {
|
|||
/* Remote deallocation by the current thread. */
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
for (unsigned j = 0; j < REMOTE_NALLOC; j++) {
|
||||
expect_ptr_not_null(mem[i][j],
|
||||
"Unexpected remote allocation failure");
|
||||
expect_ptr_not_null(
|
||||
mem[i][j], "Unexpected remote allocation failure");
|
||||
dallocx(mem[i][j], 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ TEST_END
|
|||
|
||||
static void *
|
||||
thd_start(void *varg) {
|
||||
void *ptr, *ptr2;
|
||||
void *ptr, *ptr2;
|
||||
edata_t *edata;
|
||||
unsigned shard1, shard2;
|
||||
|
||||
|
|
@ -82,10 +82,10 @@ thd_start(void *varg) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_bin_shard_mt) {
|
||||
test_skip_if(have_percpu_arena &&
|
||||
PERCPU_ARENA_ENABLED(opt_percpu_arena));
|
||||
test_skip_if(
|
||||
have_percpu_arena && PERCPU_ARENA_ENABLED(opt_percpu_arena));
|
||||
|
||||
thd_t thds[NTHREADS];
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned i;
|
||||
for (i = 0; i < NTHREADS; i++) {
|
||||
thd_create(&thds[i], thd_start, NULL);
|
||||
|
|
@ -104,8 +104,8 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_bin_shard) {
|
||||
unsigned nbins, i;
|
||||
size_t mib[4], mib2[4];
|
||||
size_t miblen, miblen2, len;
|
||||
size_t mib[4], mib2[4];
|
||||
size_t miblen, miblen2, len;
|
||||
|
||||
len = sizeof(nbins);
|
||||
expect_d_eq(mallctl("arenas.nbins", (void *)&nbins, &len, NULL, 0), 0,
|
||||
|
|
@ -120,17 +120,19 @@ TEST_BEGIN(test_bin_shard) {
|
|||
|
||||
for (i = 0; i < nbins; i++) {
|
||||
uint32_t nshards;
|
||||
size_t size, sz1, sz2;
|
||||
size_t size, sz1, sz2;
|
||||
|
||||
mib[2] = i;
|
||||
sz1 = sizeof(nshards);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&nshards, &sz1,
|
||||
NULL, 0), 0, "Unexpected mallctlbymib() failure");
|
||||
expect_d_eq(
|
||||
mallctlbymib(mib, miblen, (void *)&nshards, &sz1, NULL, 0),
|
||||
0, "Unexpected mallctlbymib() failure");
|
||||
|
||||
mib2[2] = i;
|
||||
sz2 = sizeof(size);
|
||||
expect_d_eq(mallctlbymib(mib2, miblen2, (void *)&size, &sz2,
|
||||
NULL, 0), 0, "Unexpected mallctlbymib() failure");
|
||||
expect_d_eq(
|
||||
mallctlbymib(mib2, miblen2, (void *)&size, &sz2, NULL, 0),
|
||||
0, "Unexpected mallctlbymib() failure");
|
||||
|
||||
if (size >= 1 && size <= 128) {
|
||||
expect_u_eq(nshards, 16, "Unexpected nshards");
|
||||
|
|
@ -148,7 +150,5 @@ TEST_END
|
|||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_bin_shard,
|
||||
test_bin_shard_mt,
|
||||
test_producer_consumer);
|
||||
test_bin_shard, test_bin_shard_mt, test_producer_consumer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,36 +2,37 @@
|
|||
|
||||
#include "jemalloc/internal/bit_util.h"
|
||||
|
||||
#define TEST_POW2_CEIL(t, suf, pri) do { \
|
||||
unsigned i, pow2; \
|
||||
t x; \
|
||||
\
|
||||
expect_##suf##_eq(pow2_ceil_##suf(0), 0, "Unexpected result"); \
|
||||
\
|
||||
for (i = 0; i < sizeof(t) * 8; i++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf(((t)1) << i), ((t)1) \
|
||||
<< i, "Unexpected result"); \
|
||||
} \
|
||||
\
|
||||
for (i = 2; i < sizeof(t) * 8; i++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf((((t)1) << i) - 1), \
|
||||
((t)1) << i, "Unexpected result"); \
|
||||
} \
|
||||
\
|
||||
for (i = 0; i < sizeof(t) * 8 - 1; i++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf((((t)1) << i) + 1), \
|
||||
((t)1) << (i+1), "Unexpected result"); \
|
||||
} \
|
||||
\
|
||||
for (pow2 = 1; pow2 < 25; pow2++) { \
|
||||
for (x = (((t)1) << (pow2-1)) + 1; x <= ((t)1) << pow2; \
|
||||
x++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf(x), \
|
||||
((t)1) << pow2, \
|
||||
"Unexpected result, x=%"pri, x); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
#define TEST_POW2_CEIL(t, suf, pri) \
|
||||
do { \
|
||||
unsigned i, pow2; \
|
||||
t x; \
|
||||
\
|
||||
expect_##suf##_eq(pow2_ceil_##suf(0), 0, "Unexpected result"); \
|
||||
\
|
||||
for (i = 0; i < sizeof(t) * 8; i++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf(((t)1) << i), \
|
||||
((t)1) << i, "Unexpected result"); \
|
||||
} \
|
||||
\
|
||||
for (i = 2; i < sizeof(t) * 8; i++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf((((t)1) << i) - 1), \
|
||||
((t)1) << i, "Unexpected result"); \
|
||||
} \
|
||||
\
|
||||
for (i = 0; i < sizeof(t) * 8 - 1; i++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf((((t)1) << i) + 1), \
|
||||
((t)1) << (i + 1), "Unexpected result"); \
|
||||
} \
|
||||
\
|
||||
for (pow2 = 1; pow2 < 25; pow2++) { \
|
||||
for (x = (((t)1) << (pow2 - 1)) + 1; \
|
||||
x <= ((t)1) << pow2; x++) { \
|
||||
expect_##suf##_eq(pow2_ceil_##suf(x), \
|
||||
((t)1) << pow2, \
|
||||
"Unexpected result, x=%" pri, x); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
TEST_BEGIN(test_pow2_ceil_u64) {
|
||||
TEST_POW2_CEIL(uint64_t, u64, FMTu64);
|
||||
|
|
@ -54,10 +55,10 @@ expect_lg_ceil_range(size_t input, unsigned answer) {
|
|||
expect_u_eq(0, answer, "Got %u as lg_ceil of 1", answer);
|
||||
return;
|
||||
}
|
||||
expect_zu_le(input, (ZU(1) << answer),
|
||||
"Got %u as lg_ceil of %zu", answer, input);
|
||||
expect_zu_gt(input, (ZU(1) << (answer - 1)),
|
||||
"Got %u as lg_ceil of %zu", answer, input);
|
||||
expect_zu_le(input, (ZU(1) << answer), "Got %u as lg_ceil of %zu",
|
||||
answer, input);
|
||||
expect_zu_gt(input, (ZU(1) << (answer - 1)), "Got %u as lg_ceil of %zu",
|
||||
answer, input);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -66,8 +67,8 @@ expect_lg_floor_range(size_t input, unsigned answer) {
|
|||
expect_u_eq(0, answer, "Got %u as lg_floor of 1", answer);
|
||||
return;
|
||||
}
|
||||
expect_zu_ge(input, (ZU(1) << answer),
|
||||
"Got %u as lg_floor of %zu", answer, input);
|
||||
expect_zu_ge(input, (ZU(1) << answer), "Got %u as lg_floor of %zu",
|
||||
answer, input);
|
||||
expect_zu_lt(input, (ZU(1) << (answer + 1)),
|
||||
"Got %u as lg_floor of %zu", answer, input);
|
||||
}
|
||||
|
|
@ -101,22 +102,24 @@ TEST_BEGIN(test_lg_ceil_floor) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
#define TEST_FFS(t, suf, test_suf, pri) do { \
|
||||
for (unsigned i = 0; i < sizeof(t) * 8; i++) { \
|
||||
for (unsigned j = 0; j <= i; j++) { \
|
||||
for (unsigned k = 0; k <= j; k++) { \
|
||||
t x = (t)1 << i; \
|
||||
x |= (t)1 << j; \
|
||||
x |= (t)1 << k; \
|
||||
expect_##test_suf##_eq(ffs_##suf(x), k, \
|
||||
"Unexpected result, x=%"pri, x); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
#define TEST_FFS(t, suf, test_suf, pri) \
|
||||
do { \
|
||||
for (unsigned i = 0; i < sizeof(t) * 8; i++) { \
|
||||
for (unsigned j = 0; j <= i; j++) { \
|
||||
for (unsigned k = 0; k <= j; k++) { \
|
||||
t x = (t)1 << i; \
|
||||
x |= (t)1 << j; \
|
||||
x |= (t)1 << k; \
|
||||
expect_##test_suf##_eq(ffs_##suf(x), \
|
||||
k, "Unexpected result, x=%" pri, \
|
||||
x); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
TEST_BEGIN(test_ffs_u) {
|
||||
TEST_FFS(unsigned, u, u,"u");
|
||||
TEST_FFS(unsigned, u, u, "u");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -145,22 +148,24 @@ TEST_BEGIN(test_ffs_zu) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
#define TEST_FLS(t, suf, test_suf, pri) do { \
|
||||
for (unsigned i = 0; i < sizeof(t) * 8; i++) { \
|
||||
for (unsigned j = 0; j <= i; j++) { \
|
||||
for (unsigned k = 0; k <= j; k++) { \
|
||||
t x = (t)1 << i; \
|
||||
x |= (t)1 << j; \
|
||||
x |= (t)1 << k; \
|
||||
expect_##test_suf##_eq(fls_##suf(x), i, \
|
||||
"Unexpected result, x=%"pri, x); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while(0)
|
||||
#define TEST_FLS(t, suf, test_suf, pri) \
|
||||
do { \
|
||||
for (unsigned i = 0; i < sizeof(t) * 8; i++) { \
|
||||
for (unsigned j = 0; j <= i; j++) { \
|
||||
for (unsigned k = 0; k <= j; k++) { \
|
||||
t x = (t)1 << i; \
|
||||
x |= (t)1 << j; \
|
||||
x |= (t)1 << k; \
|
||||
expect_##test_suf##_eq(fls_##suf(x), \
|
||||
i, "Unexpected result, x=%" pri, \
|
||||
x); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
TEST_BEGIN(test_fls_u) {
|
||||
TEST_FLS(unsigned, u, u,"u");
|
||||
TEST_FLS(unsigned, u, u, "u");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -190,7 +195,7 @@ TEST_BEGIN(test_fls_zu) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_fls_u_slow) {
|
||||
TEST_FLS(unsigned, u_slow, u,"u");
|
||||
TEST_FLS(unsigned, u_slow, u, "u");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -280,30 +285,11 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_pow2_ceil_u64,
|
||||
test_pow2_ceil_u32,
|
||||
test_pow2_ceil_zu,
|
||||
test_lg_ceil_floor,
|
||||
test_ffs_u,
|
||||
test_ffs_lu,
|
||||
test_ffs_llu,
|
||||
test_ffs_u32,
|
||||
test_ffs_u64,
|
||||
test_ffs_zu,
|
||||
test_fls_u,
|
||||
test_fls_lu,
|
||||
test_fls_llu,
|
||||
test_fls_u32,
|
||||
test_fls_u64,
|
||||
test_fls_zu,
|
||||
test_fls_u_slow,
|
||||
test_fls_lu_slow,
|
||||
test_fls_llu_slow,
|
||||
test_popcount_u,
|
||||
test_popcount_u_slow,
|
||||
test_popcount_lu,
|
||||
test_popcount_lu_slow,
|
||||
test_popcount_llu,
|
||||
test_popcount_llu_slow);
|
||||
return test_no_reentrancy(test_pow2_ceil_u64, test_pow2_ceil_u32,
|
||||
test_pow2_ceil_zu, test_lg_ceil_floor, test_ffs_u, test_ffs_lu,
|
||||
test_ffs_llu, test_ffs_u32, test_ffs_u64, test_ffs_zu, test_fls_u,
|
||||
test_fls_lu, test_fls_llu, test_fls_u32, test_fls_u64, test_fls_zu,
|
||||
test_fls_u_slow, test_fls_lu_slow, test_fls_llu_slow,
|
||||
test_popcount_u, test_popcount_u_slow, test_popcount_lu,
|
||||
test_popcount_lu_slow, test_popcount_llu, test_popcount_llu_slow);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,17 @@ test_bitmap_initializer_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
|
||||
expect_zu_eq(bitmap_size(binfo), bitmap_size(&binfo_dyn),
|
||||
"Unexpected difference between static and dynamic initialization, "
|
||||
"nbits=%zu", nbits);
|
||||
"nbits=%zu",
|
||||
nbits);
|
||||
expect_zu_eq(binfo->nbits, binfo_dyn.nbits,
|
||||
"Unexpected difference between static and dynamic initialization, "
|
||||
"nbits=%zu", nbits);
|
||||
"nbits=%zu",
|
||||
nbits);
|
||||
#ifdef BITMAP_USE_TREE
|
||||
expect_u_eq(binfo->nlevels, binfo_dyn.nlevels,
|
||||
"Unexpected difference between static and dynamic initialization, "
|
||||
"nbits=%zu", nbits);
|
||||
"nbits=%zu",
|
||||
nbits);
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
|
|
@ -24,7 +27,8 @@ test_bitmap_initializer_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
expect_zu_eq(binfo->levels[i].group_offset,
|
||||
binfo_dyn.levels[i].group_offset,
|
||||
"Unexpected difference between static and dynamic "
|
||||
"initialization, nbits=%zu, level=%u", nbits, i);
|
||||
"initialization, nbits=%zu, level=%u",
|
||||
nbits, i);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
|
@ -34,12 +38,12 @@ test_bitmap_initializer_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_bitmap_initializer) {
|
||||
#define NB(nbits) { \
|
||||
if (nbits <= BITMAP_MAXBITS) { \
|
||||
bitmap_info_t binfo = \
|
||||
BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_initializer_body(&binfo, nbits); \
|
||||
} \
|
||||
#define NB(nbits) \
|
||||
{ \
|
||||
if (nbits <= BITMAP_MAXBITS) { \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_initializer_body(&binfo, nbits); \
|
||||
} \
|
||||
}
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
|
|
@ -47,11 +51,11 @@ TEST_BEGIN(test_bitmap_initializer) {
|
|||
TEST_END
|
||||
|
||||
static size_t
|
||||
test_bitmap_size_body(const bitmap_info_t *binfo, size_t nbits,
|
||||
size_t prev_size) {
|
||||
test_bitmap_size_body(
|
||||
const bitmap_info_t *binfo, size_t nbits, size_t prev_size) {
|
||||
size_t size = bitmap_size(binfo);
|
||||
expect_zu_ge(size, (nbits >> 3),
|
||||
"Bitmap size is smaller than expected");
|
||||
expect_zu_ge(
|
||||
size, (nbits >> 3), "Bitmap size is smaller than expected");
|
||||
expect_zu_ge(size, prev_size, "Bitmap size is smaller than expected");
|
||||
return size;
|
||||
}
|
||||
|
|
@ -65,10 +69,10 @@ TEST_BEGIN(test_bitmap_size) {
|
|||
bitmap_info_init(&binfo, nbits);
|
||||
prev_size = test_bitmap_size_body(&binfo, nbits, prev_size);
|
||||
}
|
||||
#define NB(nbits) { \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
prev_size = test_bitmap_size_body(&binfo, nbits, \
|
||||
prev_size); \
|
||||
#define NB(nbits) \
|
||||
{ \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
prev_size = test_bitmap_size_body(&binfo, nbits, prev_size); \
|
||||
}
|
||||
prev_size = 0;
|
||||
NBITS_TAB
|
||||
|
|
@ -78,14 +82,14 @@ TEST_END
|
|||
|
||||
static void
|
||||
test_bitmap_init_body(const bitmap_info_t *binfo, size_t nbits) {
|
||||
size_t i;
|
||||
size_t i;
|
||||
bitmap_t *bitmap = (bitmap_t *)malloc(bitmap_size(binfo));
|
||||
expect_ptr_not_null(bitmap, "Unexpected malloc() failure");
|
||||
|
||||
bitmap_init(bitmap, binfo, false);
|
||||
for (i = 0; i < nbits; i++) {
|
||||
expect_false(bitmap_get(bitmap, binfo, i),
|
||||
"Bit should be unset");
|
||||
expect_false(
|
||||
bitmap_get(bitmap, binfo, i), "Bit should be unset");
|
||||
}
|
||||
|
||||
bitmap_init(bitmap, binfo, true);
|
||||
|
|
@ -104,9 +108,10 @@ TEST_BEGIN(test_bitmap_init) {
|
|||
bitmap_info_init(&binfo, nbits);
|
||||
test_bitmap_init_body(&binfo, nbits);
|
||||
}
|
||||
#define NB(nbits) { \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_init_body(&binfo, nbits); \
|
||||
#define NB(nbits) \
|
||||
{ \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_init_body(&binfo, nbits); \
|
||||
}
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
|
|
@ -115,7 +120,7 @@ TEST_END
|
|||
|
||||
static void
|
||||
test_bitmap_set_body(const bitmap_info_t *binfo, size_t nbits) {
|
||||
size_t i;
|
||||
size_t i;
|
||||
bitmap_t *bitmap = (bitmap_t *)malloc(bitmap_size(binfo));
|
||||
expect_ptr_not_null(bitmap, "Unexpected malloc() failure");
|
||||
bitmap_init(bitmap, binfo, false);
|
||||
|
|
@ -135,9 +140,10 @@ TEST_BEGIN(test_bitmap_set) {
|
|||
bitmap_info_init(&binfo, nbits);
|
||||
test_bitmap_set_body(&binfo, nbits);
|
||||
}
|
||||
#define NB(nbits) { \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_set_body(&binfo, nbits); \
|
||||
#define NB(nbits) \
|
||||
{ \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_set_body(&binfo, nbits); \
|
||||
}
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
|
|
@ -146,7 +152,7 @@ TEST_END
|
|||
|
||||
static void
|
||||
test_bitmap_unset_body(const bitmap_info_t *binfo, size_t nbits) {
|
||||
size_t i;
|
||||
size_t i;
|
||||
bitmap_t *bitmap = (bitmap_t *)malloc(bitmap_size(binfo));
|
||||
expect_ptr_not_null(bitmap, "Unexpected malloc() failure");
|
||||
bitmap_init(bitmap, binfo, false);
|
||||
|
|
@ -173,9 +179,10 @@ TEST_BEGIN(test_bitmap_unset) {
|
|||
bitmap_info_init(&binfo, nbits);
|
||||
test_bitmap_unset_body(&binfo, nbits);
|
||||
}
|
||||
#define NB(nbits) { \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_unset_body(&binfo, nbits); \
|
||||
#define NB(nbits) \
|
||||
{ \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_unset_body(&binfo, nbits); \
|
||||
}
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
|
|
@ -193,7 +200,7 @@ test_bitmap_xfu_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
expect_zu_eq(bitmap_ffu(bitmap, binfo, 0), i,
|
||||
"First unset bit should be just after previous first unset "
|
||||
"bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (i > 0) ? i-1 : i), i,
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (i > 0) ? i - 1 : i), i,
|
||||
"First unset bit should be just after previous first unset "
|
||||
"bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i), i,
|
||||
|
|
@ -213,7 +220,7 @@ test_bitmap_xfu_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
bitmap_unset(bitmap, binfo, i);
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, 0), i,
|
||||
"First unset bit should the bit previously unset");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (i > 0) ? i-1 : i), i,
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (i > 0) ? i - 1 : i), i,
|
||||
"First unset bit should the bit previously unset");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i), i,
|
||||
"First unset bit should the bit previously unset");
|
||||
|
|
@ -232,7 +239,7 @@ test_bitmap_xfu_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
expect_zu_eq(bitmap_ffu(bitmap, binfo, 0), i,
|
||||
"First unset bit should be just after the bit previously "
|
||||
"set");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (i > 0) ? i-1 : i), i,
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (i > 0) ? i - 1 : i), i,
|
||||
"First unset bit should be just after the bit previously "
|
||||
"set");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i), i,
|
||||
|
|
@ -245,7 +252,8 @@ test_bitmap_xfu_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
}
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, 0), nbits - 1,
|
||||
"First unset bit should be the last bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, (nbits > 1) ? nbits-2 : nbits-1),
|
||||
expect_zu_eq(
|
||||
bitmap_ffu(bitmap, binfo, (nbits > 1) ? nbits - 2 : nbits - 1),
|
||||
nbits - 1, "First unset bit should be the last bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, nbits - 1), nbits - 1,
|
||||
"First unset bit should be the last bit");
|
||||
|
|
@ -258,26 +266,26 @@ test_bitmap_xfu_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
* bitmap_ffu() finds the correct bit for all five min_bit cases.
|
||||
*/
|
||||
if (nbits >= 3) {
|
||||
for (size_t i = 0; i < nbits-2; i++) {
|
||||
for (size_t i = 0; i < nbits - 2; i++) {
|
||||
bitmap_unset(bitmap, binfo, i);
|
||||
bitmap_unset(bitmap, binfo, i+2);
|
||||
bitmap_unset(bitmap, binfo, i + 2);
|
||||
if (i > 0) {
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i-1), i,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i - 1),
|
||||
i, "Unexpected first unset bit");
|
||||
}
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i), i,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i+1), i+2,
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i + 1), i + 2,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i+2), i+2,
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i + 2), i + 2,
|
||||
"Unexpected first unset bit");
|
||||
if (i + 3 < nbits) {
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i+3),
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i + 3),
|
||||
nbits, "Unexpected first unset bit");
|
||||
}
|
||||
expect_zu_eq(bitmap_sfu(bitmap, binfo), i,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_sfu(bitmap, binfo), i+2,
|
||||
expect_zu_eq(bitmap_sfu(bitmap, binfo), i + 2,
|
||||
"Unexpected first unset bit");
|
||||
}
|
||||
}
|
||||
|
|
@ -288,24 +296,24 @@ test_bitmap_xfu_body(const bitmap_info_t *binfo, size_t nbits) {
|
|||
* cases.
|
||||
*/
|
||||
if (nbits >= 3) {
|
||||
bitmap_unset(bitmap, binfo, nbits-1);
|
||||
for (size_t i = 0; i < nbits-1; i++) {
|
||||
bitmap_unset(bitmap, binfo, nbits - 1);
|
||||
for (size_t i = 0; i < nbits - 1; i++) {
|
||||
bitmap_unset(bitmap, binfo, i);
|
||||
if (i > 0) {
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i-1), i,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i - 1),
|
||||
i, "Unexpected first unset bit");
|
||||
}
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i), i,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i+1), nbits-1,
|
||||
"Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, nbits-1),
|
||||
nbits-1, "Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, i + 1),
|
||||
nbits - 1, "Unexpected first unset bit");
|
||||
expect_zu_eq(bitmap_ffu(bitmap, binfo, nbits - 1),
|
||||
nbits - 1, "Unexpected first unset bit");
|
||||
|
||||
expect_zu_eq(bitmap_sfu(bitmap, binfo), i,
|
||||
"Unexpected first unset bit");
|
||||
}
|
||||
expect_zu_eq(bitmap_sfu(bitmap, binfo), nbits-1,
|
||||
expect_zu_eq(bitmap_sfu(bitmap, binfo), nbits - 1,
|
||||
"Unexpected first unset bit");
|
||||
}
|
||||
|
||||
|
|
@ -322,9 +330,10 @@ TEST_BEGIN(test_bitmap_xfu) {
|
|||
bitmap_info_init(&binfo, nbits);
|
||||
test_bitmap_xfu_body(&binfo, nbits);
|
||||
}
|
||||
#define NB(nbits) { \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_xfu_body(&binfo, nbits); \
|
||||
#define NB(nbits) \
|
||||
{ \
|
||||
bitmap_info_t binfo = BITMAP_INFO_INITIALIZER(nbits); \
|
||||
test_bitmap_xfu_body(&binfo, nbits); \
|
||||
}
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
|
|
@ -333,11 +342,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_bitmap_initializer,
|
||||
test_bitmap_size,
|
||||
test_bitmap_init,
|
||||
test_bitmap_set,
|
||||
test_bitmap_unset,
|
||||
test_bitmap_xfu);
|
||||
return test(test_bitmap_initializer, test_bitmap_size, test_bitmap_init,
|
||||
test_bitmap_set, test_bitmap_unset, test_bitmap_xfu);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,24 +5,24 @@
|
|||
#define TEST_BUF_SIZE 16
|
||||
#define UNIT_MAX (TEST_BUF_SIZE * 3)
|
||||
|
||||
static size_t test_write_len;
|
||||
static char test_buf[TEST_BUF_SIZE];
|
||||
static size_t test_write_len;
|
||||
static char test_buf[TEST_BUF_SIZE];
|
||||
static uint64_t arg;
|
||||
static uint64_t arg_store;
|
||||
|
||||
static void
|
||||
test_write_cb(void *cbopaque, const char *s) {
|
||||
size_t prev_test_write_len = test_write_len;
|
||||
test_write_len += strlen(s); /* only increase the length */
|
||||
test_write_len += strlen(s); /* only increase the length */
|
||||
arg_store = *(uint64_t *)cbopaque; /* only pass along the argument */
|
||||
assert_zu_le(prev_test_write_len, test_write_len,
|
||||
"Test write overflowed");
|
||||
assert_zu_le(
|
||||
prev_test_write_len, test_write_len, "Test write overflowed");
|
||||
}
|
||||
|
||||
static void
|
||||
test_buf_writer_body(tsdn_t *tsdn, buf_writer_t *buf_writer) {
|
||||
char s[UNIT_MAX + 1];
|
||||
size_t n_unit, remain, i;
|
||||
char s[UNIT_MAX + 1];
|
||||
size_t n_unit, remain, i;
|
||||
ssize_t unit;
|
||||
|
||||
assert(buf_writer->buf != NULL);
|
||||
|
|
@ -41,7 +41,8 @@ test_buf_writer_body(tsdn_t *tsdn, buf_writer_t *buf_writer) {
|
|||
remain += unit;
|
||||
if (remain > buf_writer->buf_size) {
|
||||
/* Flushes should have happened. */
|
||||
assert_u64_eq(arg_store, arg, "Call "
|
||||
assert_u64_eq(arg_store, arg,
|
||||
"Call "
|
||||
"back argument didn't get through");
|
||||
remain %= buf_writer->buf_size;
|
||||
if (remain == 0) {
|
||||
|
|
@ -51,12 +52,14 @@ test_buf_writer_body(tsdn_t *tsdn, buf_writer_t *buf_writer) {
|
|||
}
|
||||
assert_zu_eq(test_write_len + remain, i * unit,
|
||||
"Incorrect length after writing %zu strings"
|
||||
" of length %zu", i, unit);
|
||||
" of length %zu",
|
||||
i, unit);
|
||||
}
|
||||
buf_writer_flush(buf_writer);
|
||||
expect_zu_eq(test_write_len, n_unit * unit,
|
||||
"Incorrect length after flushing at the end of"
|
||||
" writing %zu strings of length %zu", n_unit, unit);
|
||||
" writing %zu strings of length %zu",
|
||||
n_unit, unit);
|
||||
}
|
||||
}
|
||||
buf_writer_terminate(tsdn, buf_writer);
|
||||
|
|
@ -64,9 +67,9 @@ test_buf_writer_body(tsdn_t *tsdn, buf_writer_t *buf_writer) {
|
|||
|
||||
TEST_BEGIN(test_buf_write_static) {
|
||||
buf_writer_t buf_writer;
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
assert_false(buf_writer_init(tsdn, &buf_writer, test_write_cb, &arg,
|
||||
test_buf, TEST_BUF_SIZE),
|
||||
test_buf, TEST_BUF_SIZE),
|
||||
"buf_writer_init() should not encounter error on static buffer");
|
||||
test_buf_writer_body(tsdn, &buf_writer);
|
||||
}
|
||||
|
|
@ -74,22 +77,24 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_buf_write_dynamic) {
|
||||
buf_writer_t buf_writer;
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
assert_false(buf_writer_init(tsdn, &buf_writer, test_write_cb, &arg,
|
||||
NULL, TEST_BUF_SIZE), "buf_writer_init() should not OOM");
|
||||
NULL, TEST_BUF_SIZE),
|
||||
"buf_writer_init() should not OOM");
|
||||
test_buf_writer_body(tsdn, &buf_writer);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_buf_write_oom) {
|
||||
buf_writer_t buf_writer;
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
assert_true(buf_writer_init(tsdn, &buf_writer, test_write_cb, &arg,
|
||||
NULL, SC_LARGE_MAXCLASS + 1), "buf_writer_init() should OOM");
|
||||
NULL, SC_LARGE_MAXCLASS + 1),
|
||||
"buf_writer_init() should OOM");
|
||||
assert(buf_writer.buf == NULL);
|
||||
|
||||
char s[UNIT_MAX + 1];
|
||||
size_t n_unit, i;
|
||||
char s[UNIT_MAX + 1];
|
||||
size_t n_unit, i;
|
||||
ssize_t unit;
|
||||
|
||||
memset(s, 'a', UNIT_MAX);
|
||||
|
|
@ -107,20 +112,22 @@ TEST_BEGIN(test_buf_write_oom) {
|
|||
"Call back argument didn't get through");
|
||||
assert_zu_eq(test_write_len, i * unit,
|
||||
"Incorrect length after writing %zu strings"
|
||||
" of length %zu", i, unit);
|
||||
" of length %zu",
|
||||
i, unit);
|
||||
}
|
||||
buf_writer_flush(&buf_writer);
|
||||
expect_zu_eq(test_write_len, n_unit * unit,
|
||||
"Incorrect length after flushing at the end of"
|
||||
" writing %zu strings of length %zu", n_unit, unit);
|
||||
" writing %zu strings of length %zu",
|
||||
n_unit, unit);
|
||||
}
|
||||
}
|
||||
buf_writer_terminate(tsdn, &buf_writer);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
static int test_read_count;
|
||||
static size_t test_read_len;
|
||||
static int test_read_count;
|
||||
static size_t test_read_len;
|
||||
static uint64_t arg_sum;
|
||||
|
||||
ssize_t
|
||||
|
|
@ -142,8 +149,8 @@ test_read_cb(void *cbopaque, void *buf, size_t limit) {
|
|||
memset(buf, 'a', read_len);
|
||||
size_t prev_test_read_len = test_read_len;
|
||||
test_read_len += read_len;
|
||||
assert_zu_le(prev_test_read_len, test_read_len,
|
||||
"Test read overflowed");
|
||||
assert_zu_le(
|
||||
prev_test_read_len, test_read_len, "Test read overflowed");
|
||||
return read_len;
|
||||
}
|
||||
}
|
||||
|
|
@ -168,9 +175,9 @@ test_buf_writer_pipe_body(tsdn_t *tsdn, buf_writer_t *buf_writer) {
|
|||
|
||||
TEST_BEGIN(test_buf_write_pipe) {
|
||||
buf_writer_t buf_writer;
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
assert_false(buf_writer_init(tsdn, &buf_writer, test_write_cb, &arg,
|
||||
test_buf, TEST_BUF_SIZE),
|
||||
test_buf, TEST_BUF_SIZE),
|
||||
"buf_writer_init() should not encounter error on static buffer");
|
||||
test_buf_writer_pipe_body(tsdn, &buf_writer);
|
||||
}
|
||||
|
|
@ -178,19 +185,16 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_buf_write_pipe_oom) {
|
||||
buf_writer_t buf_writer;
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
tsdn_t *tsdn = tsdn_fetch();
|
||||
assert_true(buf_writer_init(tsdn, &buf_writer, test_write_cb, &arg,
|
||||
NULL, SC_LARGE_MAXCLASS + 1), "buf_writer_init() should OOM");
|
||||
NULL, SC_LARGE_MAXCLASS + 1),
|
||||
"buf_writer_init() should OOM");
|
||||
test_buf_writer_pipe_body(tsdn, &buf_writer);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_buf_write_static,
|
||||
test_buf_write_dynamic,
|
||||
test_buf_write_oom,
|
||||
test_buf_write_pipe,
|
||||
test_buf_write_pipe_oom);
|
||||
return test(test_buf_write_static, test_buf_write_dynamic,
|
||||
test_buf_write_oom, test_buf_write_pipe, test_buf_write_pipe_oom);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
static void
|
||||
do_fill_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t ncached_max,
|
||||
cache_bin_sz_t nfill_attempt, cache_bin_sz_t nfill_succeed) {
|
||||
bool success;
|
||||
bool success;
|
||||
void *ptr;
|
||||
assert_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
CACHE_BIN_PTR_ARRAY_DECLARE(arr, nfill_attempt);
|
||||
|
|
@ -12,17 +12,16 @@ do_fill_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t ncached_max,
|
|||
arr.ptr[i] = &ptrs[i];
|
||||
}
|
||||
cache_bin_finish_fill(bin, &arr, nfill_succeed);
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill_succeed,
|
||||
"");
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill_succeed, "");
|
||||
cache_bin_low_water_set(bin);
|
||||
|
||||
for (cache_bin_sz_t i = 0; i < nfill_succeed; i++) {
|
||||
ptr = cache_bin_alloc(bin, &success);
|
||||
expect_true(success, "");
|
||||
expect_ptr_eq(ptr, (void *)&ptrs[i],
|
||||
"Should pop in order filled");
|
||||
expect_true(cache_bin_low_water_get(bin)
|
||||
== nfill_succeed - i - 1, "");
|
||||
expect_ptr_eq(
|
||||
ptr, (void *)&ptrs[i], "Should pop in order filled");
|
||||
expect_true(
|
||||
cache_bin_low_water_get(bin) == nfill_succeed - i - 1, "");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
expect_true(cache_bin_low_water_get(bin) == 0, "");
|
||||
|
|
@ -46,16 +45,15 @@ do_flush_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
|||
}
|
||||
cache_bin_finish_flush(bin, &arr, nflush);
|
||||
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill - nflush,
|
||||
"");
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill - nflush, "");
|
||||
while (cache_bin_ncached_get_local(bin) > 0) {
|
||||
cache_bin_alloc(bin, &success);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_batch_alloc_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
||||
size_t batch) {
|
||||
do_batch_alloc_test(
|
||||
cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill, size_t batch) {
|
||||
assert_true(cache_bin_ncached_get_local(bin) == 0, "");
|
||||
CACHE_BIN_PTR_ARRAY_DECLARE(arr, nfill);
|
||||
cache_bin_init_ptr_array_for_fill(bin, &arr, nfill);
|
||||
|
|
@ -72,8 +70,8 @@ do_batch_alloc_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
|||
for (cache_bin_sz_t i = 0; i < (cache_bin_sz_t)n; i++) {
|
||||
expect_ptr_eq(out[i], &ptrs[i], "");
|
||||
}
|
||||
expect_true(cache_bin_low_water_get(bin) == nfill -
|
||||
(cache_bin_sz_t)n, "");
|
||||
expect_true(
|
||||
cache_bin_low_water_get(bin) == nfill - (cache_bin_sz_t)n, "");
|
||||
while (cache_bin_ncached_get_local(bin) > 0) {
|
||||
bool success;
|
||||
cache_bin_alloc(bin, &success);
|
||||
|
|
@ -98,8 +96,8 @@ test_bin_init(cache_bin_t *bin, cache_bin_info_t *info) {
|
|||
|
||||
TEST_BEGIN(test_cache_bin) {
|
||||
const int ncached_max = 100;
|
||||
bool success;
|
||||
void *ptr;
|
||||
bool success;
|
||||
void *ptr;
|
||||
|
||||
cache_bin_info_t info;
|
||||
cache_bin_info_init(&info, ncached_max);
|
||||
|
|
@ -125,7 +123,7 @@ TEST_BEGIN(test_cache_bin) {
|
|||
*/
|
||||
void **ptrs = mallocx(sizeof(void *) * (ncached_max + 1), 0);
|
||||
assert_ptr_not_null(ptrs, "Unexpected mallocx failure");
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == i, "");
|
||||
success = cache_bin_dalloc_easy(&bin, &ptrs[i]);
|
||||
expect_true(success,
|
||||
|
|
@ -133,18 +131,17 @@ TEST_BEGIN(test_cache_bin) {
|
|||
expect_true(cache_bin_low_water_get(&bin) == 0,
|
||||
"Pushes and pops shouldn't change low water of zero.");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == ncached_max,
|
||||
"");
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == ncached_max, "");
|
||||
success = cache_bin_dalloc_easy(&bin, &ptrs[ncached_max]);
|
||||
expect_false(success, "Shouldn't be able to dalloc into a full bin.");
|
||||
|
||||
cache_bin_low_water_set(&bin);
|
||||
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
expect_true(cache_bin_low_water_get(&bin)
|
||||
== ncached_max - i, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin)
|
||||
== ncached_max - i, "");
|
||||
expect_true(
|
||||
cache_bin_low_water_get(&bin) == ncached_max - i, "");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(&bin) == ncached_max - i, "");
|
||||
/*
|
||||
* This should fail -- the easy variant can't change the low
|
||||
* water mark.
|
||||
|
|
@ -152,20 +149,21 @@ TEST_BEGIN(test_cache_bin) {
|
|||
ptr = cache_bin_alloc_easy(&bin, &success);
|
||||
expect_ptr_null(ptr, "");
|
||||
expect_false(success, "");
|
||||
expect_true(cache_bin_low_water_get(&bin)
|
||||
== ncached_max - i, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin)
|
||||
== ncached_max - i, "");
|
||||
expect_true(
|
||||
cache_bin_low_water_get(&bin) == ncached_max - i, "");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(&bin) == ncached_max - i, "");
|
||||
|
||||
/* This should succeed, though. */
|
||||
ptr = cache_bin_alloc(&bin, &success);
|
||||
expect_true(success, "");
|
||||
expect_ptr_eq(ptr, &ptrs[ncached_max - i - 1],
|
||||
"Alloc should pop in stack order");
|
||||
expect_true(cache_bin_low_water_get(&bin)
|
||||
== ncached_max - i - 1, "");
|
||||
expect_true(cache_bin_ncached_get_local(&bin)
|
||||
== ncached_max - i - 1, "");
|
||||
expect_true(
|
||||
cache_bin_low_water_get(&bin) == ncached_max - i - 1, "");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(&bin) == ncached_max - i - 1,
|
||||
"");
|
||||
}
|
||||
/* Now we're empty -- all alloc attempts should fail. */
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == 0, "");
|
||||
|
|
@ -184,8 +182,7 @@ TEST_BEGIN(test_cache_bin) {
|
|||
for (cache_bin_sz_t i = ncached_max / 2; i < ncached_max; i++) {
|
||||
cache_bin_dalloc_easy(&bin, &ptrs[i]);
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == ncached_max,
|
||||
"");
|
||||
expect_true(cache_bin_ncached_get_local(&bin) == ncached_max, "");
|
||||
for (cache_bin_sz_t i = ncached_max - 1; i >= ncached_max / 2; i--) {
|
||||
/*
|
||||
* Size is bigger than low water -- the reduced version should
|
||||
|
|
@ -208,20 +205,16 @@ TEST_BEGIN(test_cache_bin) {
|
|||
|
||||
/* Test fill. */
|
||||
/* Try to fill all, succeed fully. */
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max,
|
||||
ncached_max);
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max, ncached_max);
|
||||
/* Try to fill all, succeed partially. */
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max,
|
||||
ncached_max / 2);
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max, ncached_max / 2);
|
||||
/* Try to fill all, fail completely. */
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max, 0);
|
||||
|
||||
/* Try to fill some, succeed fully. */
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2,
|
||||
ncached_max / 2);
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2, ncached_max / 2);
|
||||
/* Try to fill some, succeed partially. */
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2,
|
||||
ncached_max / 4);
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2, ncached_max / 4);
|
||||
/* Try to fill some, fail completely. */
|
||||
do_fill_test(&bin, ptrs, ncached_max, ncached_max / 2, 0);
|
||||
|
||||
|
|
@ -262,11 +255,10 @@ TEST_END
|
|||
static void
|
||||
do_flush_stashed_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
||||
cache_bin_sz_t nstash) {
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0,
|
||||
"Bin not empty");
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == 0,
|
||||
"Bin not empty");
|
||||
expect_true(nfill + nstash <= bin->bin_info.ncached_max, "Exceeded max");
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0, "Bin not empty");
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == 0, "Bin not empty");
|
||||
expect_true(
|
||||
nfill + nstash <= bin->bin_info.ncached_max, "Exceeded max");
|
||||
|
||||
bool ret;
|
||||
/* Fill */
|
||||
|
|
@ -274,16 +266,16 @@ do_flush_stashed_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
|||
ret = cache_bin_dalloc_easy(bin, &ptrs[i]);
|
||||
expect_true(ret, "Unexpected fill failure");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(bin) == nfill,
|
||||
"Wrong cached count");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(bin) == nfill, "Wrong cached count");
|
||||
|
||||
/* Stash */
|
||||
for (cache_bin_sz_t i = 0; i < nstash; i++) {
|
||||
ret = cache_bin_stash(bin, &ptrs[i + nfill]);
|
||||
expect_true(ret, "Unexpected stash failure");
|
||||
}
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == nstash,
|
||||
"Wrong stashed count");
|
||||
expect_true(
|
||||
cache_bin_nstashed_get_local(bin) == nstash, "Wrong stashed count");
|
||||
|
||||
if (nfill + nstash == bin->bin_info.ncached_max) {
|
||||
ret = cache_bin_dalloc_easy(bin, &ptrs[0]);
|
||||
|
|
@ -300,20 +292,20 @@ do_flush_stashed_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
|||
expect_true((uintptr_t)ptr < (uintptr_t)&ptrs[nfill],
|
||||
"Should not alloc stashed ptrs");
|
||||
}
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0,
|
||||
"Wrong cached count");
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == nstash,
|
||||
"Wrong stashed count");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(bin) == 0, "Wrong cached count");
|
||||
expect_true(
|
||||
cache_bin_nstashed_get_local(bin) == nstash, "Wrong stashed count");
|
||||
|
||||
cache_bin_alloc(bin, &ret);
|
||||
expect_false(ret, "Should not alloc stashed");
|
||||
|
||||
/* Clear stashed ones */
|
||||
cache_bin_finish_flush_stashed(bin);
|
||||
expect_true(cache_bin_ncached_get_local(bin) == 0,
|
||||
"Wrong cached count");
|
||||
expect_true(cache_bin_nstashed_get_local(bin) == 0,
|
||||
"Wrong stashed count");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(bin) == 0, "Wrong cached count");
|
||||
expect_true(
|
||||
cache_bin_nstashed_get_local(bin) == 0, "Wrong stashed count");
|
||||
|
||||
cache_bin_alloc(bin, &ret);
|
||||
expect_false(ret, "Should not alloc from empty bin");
|
||||
|
|
@ -322,7 +314,7 @@ do_flush_stashed_test(cache_bin_t *bin, void **ptrs, cache_bin_sz_t nfill,
|
|||
TEST_BEGIN(test_cache_bin_stash) {
|
||||
const int ncached_max = 100;
|
||||
|
||||
cache_bin_t bin;
|
||||
cache_bin_t bin;
|
||||
cache_bin_info_t info;
|
||||
cache_bin_info_init(&info, ncached_max);
|
||||
test_bin_init(&bin, &info);
|
||||
|
|
@ -335,15 +327,17 @@ TEST_BEGIN(test_cache_bin_stash) {
|
|||
assert_ptr_not_null(ptrs, "Unexpected mallocx failure");
|
||||
bool ret;
|
||||
for (cache_bin_sz_t i = 0; i < ncached_max; i++) {
|
||||
expect_true(cache_bin_ncached_get_local(&bin) ==
|
||||
(i / 2 + i % 2), "Wrong ncached value");
|
||||
expect_true(cache_bin_nstashed_get_local(&bin) ==
|
||||
i / 2, "Wrong nstashed value");
|
||||
expect_true(
|
||||
cache_bin_ncached_get_local(&bin) == (i / 2 + i % 2),
|
||||
"Wrong ncached value");
|
||||
expect_true(cache_bin_nstashed_get_local(&bin) == i / 2,
|
||||
"Wrong nstashed value");
|
||||
if (i % 2 == 0) {
|
||||
cache_bin_dalloc_easy(&bin, &ptrs[i]);
|
||||
} else {
|
||||
ret = cache_bin_stash(&bin, &ptrs[i]);
|
||||
expect_true(ret, "Should be able to stash into a "
|
||||
expect_true(ret,
|
||||
"Should be able to stash into a "
|
||||
"non-full cache bin");
|
||||
}
|
||||
}
|
||||
|
|
@ -360,7 +354,8 @@ TEST_BEGIN(test_cache_bin_stash) {
|
|||
expect_true(diff % 2 == 0, "Should be able to alloc");
|
||||
} else {
|
||||
expect_false(ret, "Should not alloc stashed");
|
||||
expect_true(cache_bin_nstashed_get_local(&bin) == ncached_max / 2,
|
||||
expect_true(cache_bin_nstashed_get_local(&bin)
|
||||
== ncached_max / 2,
|
||||
"Wrong nstashed value");
|
||||
}
|
||||
}
|
||||
|
|
@ -368,19 +363,14 @@ TEST_BEGIN(test_cache_bin_stash) {
|
|||
test_bin_init(&bin, &info);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max, 0);
|
||||
do_flush_stashed_test(&bin, ptrs, 0, ncached_max);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 2,
|
||||
ncached_max / 2);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 4,
|
||||
ncached_max / 2);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 2,
|
||||
ncached_max / 4);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 4,
|
||||
ncached_max / 4);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 2, ncached_max / 2);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 4, ncached_max / 2);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 2, ncached_max / 4);
|
||||
do_flush_stashed_test(&bin, ptrs, ncached_max / 4, ncached_max / 4);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test(test_cache_bin,
|
||||
test_cache_bin_stash);
|
||||
return test(test_cache_bin, test_cache_bin_stash);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,55 +2,51 @@
|
|||
|
||||
TEST_BEGIN(test_new_delete) {
|
||||
tsd_t *tsd;
|
||||
ckh_t ckh;
|
||||
ckh_t ckh;
|
||||
|
||||
tsd = tsd_fetch();
|
||||
|
||||
expect_false(ckh_new(tsd, &ckh, 2, ckh_string_hash,
|
||||
ckh_string_keycomp), "Unexpected ckh_new() error");
|
||||
expect_false(ckh_new(tsd, &ckh, 2, ckh_string_hash, ckh_string_keycomp),
|
||||
"Unexpected ckh_new() error");
|
||||
ckh_delete(tsd, &ckh);
|
||||
|
||||
expect_false(ckh_new(tsd, &ckh, 3, ckh_pointer_hash,
|
||||
ckh_pointer_keycomp), "Unexpected ckh_new() error");
|
||||
expect_false(
|
||||
ckh_new(tsd, &ckh, 3, ckh_pointer_hash, ckh_pointer_keycomp),
|
||||
"Unexpected ckh_new() error");
|
||||
ckh_delete(tsd, &ckh);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_count_insert_search_remove) {
|
||||
tsd_t *tsd;
|
||||
ckh_t ckh;
|
||||
const char *strs[] = {
|
||||
"a string",
|
||||
"A string",
|
||||
"a string.",
|
||||
"A string."
|
||||
};
|
||||
tsd_t *tsd;
|
||||
ckh_t ckh;
|
||||
const char *strs[] = {"a string", "A string", "a string.", "A string."};
|
||||
const char *missing = "A string not in the hash table.";
|
||||
size_t i;
|
||||
size_t i;
|
||||
|
||||
tsd = tsd_fetch();
|
||||
|
||||
expect_false(ckh_new(tsd, &ckh, 2, ckh_string_hash,
|
||||
ckh_string_keycomp), "Unexpected ckh_new() error");
|
||||
expect_false(ckh_new(tsd, &ckh, 2, ckh_string_hash, ckh_string_keycomp),
|
||||
"Unexpected ckh_new() error");
|
||||
expect_zu_eq(ckh_count(&ckh), 0,
|
||||
"ckh_count() should return %zu, but it returned %zu", ZU(0),
|
||||
ckh_count(&ckh));
|
||||
|
||||
/* Insert. */
|
||||
for (i = 0; i < sizeof(strs)/sizeof(const char *); i++) {
|
||||
for (i = 0; i < sizeof(strs) / sizeof(const char *); i++) {
|
||||
ckh_insert(tsd, &ckh, strs[i], strs[i]);
|
||||
expect_zu_eq(ckh_count(&ckh), i+1,
|
||||
"ckh_count() should return %zu, but it returned %zu", i+1,
|
||||
expect_zu_eq(ckh_count(&ckh), i + 1,
|
||||
"ckh_count() should return %zu, but it returned %zu", i + 1,
|
||||
ckh_count(&ckh));
|
||||
}
|
||||
|
||||
/* Search. */
|
||||
for (i = 0; i < sizeof(strs)/sizeof(const char *); i++) {
|
||||
for (i = 0; i < sizeof(strs) / sizeof(const char *); i++) {
|
||||
union {
|
||||
void *p;
|
||||
void *p;
|
||||
const char *s;
|
||||
} k, v;
|
||||
void **kp, **vp;
|
||||
void **kp, **vp;
|
||||
const char *ks, *vs;
|
||||
|
||||
kp = (i & 1) ? &k.p : NULL;
|
||||
|
|
@ -62,21 +58,21 @@ TEST_BEGIN(test_count_insert_search_remove) {
|
|||
|
||||
ks = (i & 1) ? strs[i] : (const char *)NULL;
|
||||
vs = (i & 2) ? strs[i] : (const char *)NULL;
|
||||
expect_ptr_eq((void *)ks, (void *)k.s, "Key mismatch, i=%zu",
|
||||
i);
|
||||
expect_ptr_eq((void *)vs, (void *)v.s, "Value mismatch, i=%zu",
|
||||
i);
|
||||
expect_ptr_eq(
|
||||
(void *)ks, (void *)k.s, "Key mismatch, i=%zu", i);
|
||||
expect_ptr_eq(
|
||||
(void *)vs, (void *)v.s, "Value mismatch, i=%zu", i);
|
||||
}
|
||||
expect_true(ckh_search(&ckh, missing, NULL, NULL),
|
||||
"Unexpected ckh_search() success");
|
||||
|
||||
/* Remove. */
|
||||
for (i = 0; i < sizeof(strs)/sizeof(const char *); i++) {
|
||||
for (i = 0; i < sizeof(strs) / sizeof(const char *); i++) {
|
||||
union {
|
||||
void *p;
|
||||
void *p;
|
||||
const char *s;
|
||||
} k, v;
|
||||
void **kp, **vp;
|
||||
void **kp, **vp;
|
||||
const char *ks, *vs;
|
||||
|
||||
kp = (i & 1) ? &k.p : NULL;
|
||||
|
|
@ -88,14 +84,14 @@ TEST_BEGIN(test_count_insert_search_remove) {
|
|||
|
||||
ks = (i & 1) ? strs[i] : (const char *)NULL;
|
||||
vs = (i & 2) ? strs[i] : (const char *)NULL;
|
||||
expect_ptr_eq((void *)ks, (void *)k.s, "Key mismatch, i=%zu",
|
||||
i);
|
||||
expect_ptr_eq((void *)vs, (void *)v.s, "Value mismatch, i=%zu",
|
||||
i);
|
||||
expect_ptr_eq(
|
||||
(void *)ks, (void *)k.s, "Key mismatch, i=%zu", i);
|
||||
expect_ptr_eq(
|
||||
(void *)vs, (void *)v.s, "Value mismatch, i=%zu", i);
|
||||
expect_zu_eq(ckh_count(&ckh),
|
||||
sizeof(strs)/sizeof(const char *) - i - 1,
|
||||
sizeof(strs) / sizeof(const char *) - i - 1,
|
||||
"ckh_count() should return %zu, but it returned %zu",
|
||||
sizeof(strs)/sizeof(const char *) - i - 1,
|
||||
sizeof(strs) / sizeof(const char *) - i - 1,
|
||||
ckh_count(&ckh));
|
||||
}
|
||||
|
||||
|
|
@ -106,18 +102,19 @@ TEST_END
|
|||
TEST_BEGIN(test_insert_iter_remove) {
|
||||
#define NITEMS ZU(1000)
|
||||
tsd_t *tsd;
|
||||
ckh_t ckh;
|
||||
ckh_t ckh;
|
||||
void **p[NITEMS];
|
||||
void *q, *r;
|
||||
void *q, *r;
|
||||
size_t i;
|
||||
|
||||
tsd = tsd_fetch();
|
||||
|
||||
expect_false(ckh_new(tsd, &ckh, 2, ckh_pointer_hash,
|
||||
ckh_pointer_keycomp), "Unexpected ckh_new() error");
|
||||
expect_false(
|
||||
ckh_new(tsd, &ckh, 2, ckh_pointer_hash, ckh_pointer_keycomp),
|
||||
"Unexpected ckh_new() error");
|
||||
|
||||
for (i = 0; i < NITEMS; i++) {
|
||||
p[i] = mallocx(i+1, 0);
|
||||
p[i] = mallocx(i + 1, 0);
|
||||
expect_ptr_not_null(p[i], "Unexpected mallocx() failure");
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +148,7 @@ TEST_BEGIN(test_insert_iter_remove) {
|
|||
}
|
||||
|
||||
{
|
||||
bool seen[NITEMS];
|
||||
bool seen[NITEMS];
|
||||
size_t tabind;
|
||||
|
||||
memset(seen, 0, sizeof(seen));
|
||||
|
|
@ -195,8 +192,8 @@ TEST_BEGIN(test_insert_iter_remove) {
|
|||
}
|
||||
|
||||
expect_zu_eq(ckh_count(&ckh), 0,
|
||||
"ckh_count() should return %zu, but it returned %zu",
|
||||
ZU(0), ckh_count(&ckh));
|
||||
"ckh_count() should return %zu, but it returned %zu", ZU(0),
|
||||
ckh_count(&ckh));
|
||||
ckh_delete(tsd, &ckh);
|
||||
#undef NITEMS
|
||||
}
|
||||
|
|
@ -204,8 +201,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_new_delete,
|
||||
test_count_insert_search_remove,
|
||||
return test(test_new_delete, test_count_insert_search_remove,
|
||||
test_insert_iter_remove);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ TEST_BEGIN(test_counter_accum) {
|
|||
counter_accum_init(&c, interval);
|
||||
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
bool trigger;
|
||||
bool trigger;
|
||||
for (unsigned i = 0; i < n; i++) {
|
||||
trigger = counter_accum(tsd_tsdn(tsd), &c, increment);
|
||||
accum += increment;
|
||||
|
|
@ -39,8 +39,8 @@ static void *
|
|||
thd_start(void *varg) {
|
||||
counter_accum_t *c = (counter_accum_t *)varg;
|
||||
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
bool trigger;
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
bool trigger;
|
||||
uintptr_t n_triggered = 0;
|
||||
for (unsigned i = 0; i < N_ITER_THD; i++) {
|
||||
trigger = counter_accum(tsd_tsdn(tsd), c, ITER_INCREMENT);
|
||||
|
|
@ -50,12 +50,11 @@ thd_start(void *varg) {
|
|||
return (void *)n_triggered;
|
||||
}
|
||||
|
||||
|
||||
TEST_BEGIN(test_counter_mt) {
|
||||
counter_accum_t shared_c;
|
||||
counter_accum_init(&shared_c, interval);
|
||||
|
||||
thd_t thds[N_THDS];
|
||||
thd_t thds[N_THDS];
|
||||
unsigned i;
|
||||
for (i = 0; i < N_THDS; i++) {
|
||||
thd_create(&thds[i], thd_start, (void *)&shared_c);
|
||||
|
|
@ -74,7 +73,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_counter_accum,
|
||||
test_counter_mt);
|
||||
return test(test_counter_accum, test_counter_mt);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,11 @@ TEST_BEGIN(test_decay_init) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_decay_ms_valid) {
|
||||
expect_false(decay_ms_valid(-7),
|
||||
"Misclassified negative decay as valid");
|
||||
expect_false(
|
||||
decay_ms_valid(-7), "Misclassified negative decay as valid");
|
||||
expect_true(decay_ms_valid(-1),
|
||||
"Misclassified -1 (never decay) as invalid decay");
|
||||
expect_true(decay_ms_valid(8943),
|
||||
"Misclassified valid decay");
|
||||
expect_true(decay_ms_valid(8943), "Misclassified valid decay");
|
||||
if (SSIZE_MAX > NSTIME_SEC_MAX) {
|
||||
expect_false(
|
||||
decay_ms_valid((ssize_t)(NSTIME_SEC_MAX * KQU(1000) + 39)),
|
||||
|
|
@ -111,12 +110,12 @@ TEST_BEGIN(test_decay_empty) {
|
|||
assert_false(err, "");
|
||||
|
||||
uint64_t time_between_calls = decay_epoch_duration_ns(&decay) / 5;
|
||||
int nepochs = 0;
|
||||
int nepochs = 0;
|
||||
for (uint64_t i = 0; i < decay_ns / time_between_calls * 10; i++) {
|
||||
size_t dirty_pages = 0;
|
||||
nstime_init(&curtime, i * time_between_calls);
|
||||
bool epoch_advanced = decay_maybe_advance_epoch(&decay,
|
||||
&curtime, dirty_pages);
|
||||
bool epoch_advanced = decay_maybe_advance_epoch(
|
||||
&decay, &curtime, dirty_pages);
|
||||
if (epoch_advanced) {
|
||||
nepochs++;
|
||||
expect_zu_eq(decay_npages_limit_get(&decay), 0,
|
||||
|
|
@ -158,30 +157,32 @@ TEST_BEGIN(test_decay) {
|
|||
nstime_init(&epochtime, decay_epoch_duration_ns(&decay));
|
||||
|
||||
const size_t dirty_pages_per_epoch = 1000;
|
||||
size_t dirty_pages = 0;
|
||||
uint64_t epoch_ns = decay_epoch_duration_ns(&decay);
|
||||
bool epoch_advanced = false;
|
||||
size_t dirty_pages = 0;
|
||||
uint64_t epoch_ns = decay_epoch_duration_ns(&decay);
|
||||
bool epoch_advanced = false;
|
||||
|
||||
/* Populate backlog with some dirty pages */
|
||||
for (uint64_t i = 0; i < nepoch_init; i++) {
|
||||
nstime_add(&curtime, &epochtime);
|
||||
dirty_pages += dirty_pages_per_epoch;
|
||||
epoch_advanced |= decay_maybe_advance_epoch(&decay, &curtime,
|
||||
dirty_pages);
|
||||
epoch_advanced |= decay_maybe_advance_epoch(
|
||||
&decay, &curtime, dirty_pages);
|
||||
}
|
||||
expect_true(epoch_advanced, "Epoch never advanced");
|
||||
|
||||
size_t npages_limit = decay_npages_limit_get(&decay);
|
||||
expect_zu_gt(npages_limit, 0, "npages_limit is incorrectly equal "
|
||||
expect_zu_gt(npages_limit, 0,
|
||||
"npages_limit is incorrectly equal "
|
||||
"to zero after dirty pages have been added");
|
||||
|
||||
/* Keep dirty pages unchanged and verify that npages_limit decreases */
|
||||
for (uint64_t i = nepoch_init; i * epoch_ns < decay_ns; ++i) {
|
||||
nstime_add(&curtime, &epochtime);
|
||||
epoch_advanced = decay_maybe_advance_epoch(&decay, &curtime,
|
||||
dirty_pages);
|
||||
epoch_advanced = decay_maybe_advance_epoch(
|
||||
&decay, &curtime, dirty_pages);
|
||||
if (epoch_advanced) {
|
||||
size_t npages_limit_new = decay_npages_limit_get(&decay);
|
||||
size_t npages_limit_new = decay_npages_limit_get(
|
||||
&decay);
|
||||
expect_zu_lt(npages_limit_new, npages_limit,
|
||||
"napges_limit failed to decay");
|
||||
|
||||
|
|
@ -189,20 +190,22 @@ TEST_BEGIN(test_decay) {
|
|||
}
|
||||
}
|
||||
|
||||
expect_zu_gt(npages_limit, 0, "npages_limit decayed to zero earlier "
|
||||
expect_zu_gt(npages_limit, 0,
|
||||
"npages_limit decayed to zero earlier "
|
||||
"than decay_ms since last dirty page was added");
|
||||
|
||||
/* Completely push all dirty pages out of the backlog */
|
||||
epoch_advanced = false;
|
||||
for (uint64_t i = 0; i < nepoch_init; i++) {
|
||||
nstime_add(&curtime, &epochtime);
|
||||
epoch_advanced |= decay_maybe_advance_epoch(&decay, &curtime,
|
||||
dirty_pages);
|
||||
epoch_advanced |= decay_maybe_advance_epoch(
|
||||
&decay, &curtime, dirty_pages);
|
||||
}
|
||||
expect_true(epoch_advanced, "Epoch never advanced");
|
||||
|
||||
npages_limit = decay_npages_limit_get(&decay);
|
||||
expect_zu_eq(npages_limit, 0, "npages_limit didn't decay to 0 after "
|
||||
expect_zu_eq(npages_limit, 0,
|
||||
"npages_limit didn't decay to 0 after "
|
||||
"decay_ms since last bump in dirty pages");
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -230,29 +233,29 @@ TEST_BEGIN(test_decay_ns_until_purge) {
|
|||
"Failed to return unbounded wait time for zero threshold");
|
||||
|
||||
const size_t dirty_pages_per_epoch = 1000;
|
||||
size_t dirty_pages = 0;
|
||||
bool epoch_advanced = false;
|
||||
size_t dirty_pages = 0;
|
||||
bool epoch_advanced = false;
|
||||
for (uint64_t i = 0; i < nepoch_init; i++) {
|
||||
nstime_add(&curtime, &epochtime);
|
||||
dirty_pages += dirty_pages_per_epoch;
|
||||
epoch_advanced |= decay_maybe_advance_epoch(&decay, &curtime,
|
||||
dirty_pages);
|
||||
epoch_advanced |= decay_maybe_advance_epoch(
|
||||
&decay, &curtime, dirty_pages);
|
||||
}
|
||||
expect_true(epoch_advanced, "Epoch never advanced");
|
||||
|
||||
uint64_t ns_until_purge_all = decay_ns_until_purge(&decay,
|
||||
dirty_pages, dirty_pages);
|
||||
uint64_t ns_until_purge_all = decay_ns_until_purge(
|
||||
&decay, dirty_pages, dirty_pages);
|
||||
expect_u64_ge(ns_until_purge_all, decay_ns,
|
||||
"Incorrectly calculated time to purge all pages");
|
||||
|
||||
uint64_t ns_until_purge_none = decay_ns_until_purge(&decay,
|
||||
dirty_pages, 0);
|
||||
uint64_t ns_until_purge_none = decay_ns_until_purge(
|
||||
&decay, dirty_pages, 0);
|
||||
expect_u64_eq(ns_until_purge_none, decay_epoch_duration_ns(&decay) * 2,
|
||||
"Incorrectly calculated time to purge 0 pages");
|
||||
|
||||
uint64_t npages_threshold = dirty_pages / 2;
|
||||
uint64_t ns_until_purge_half = decay_ns_until_purge(&decay,
|
||||
dirty_pages, npages_threshold);
|
||||
uint64_t ns_until_purge_half = decay_ns_until_purge(
|
||||
&decay, dirty_pages, npages_threshold);
|
||||
|
||||
nstime_t waittime;
|
||||
nstime_init(&waittime, ns_until_purge_half);
|
||||
|
|
@ -263,7 +266,7 @@ TEST_BEGIN(test_decay_ns_until_purge) {
|
|||
expect_zu_lt(npages_limit, dirty_pages,
|
||||
"npages_limit failed to decrease after waiting");
|
||||
size_t expected = dirty_pages - npages_limit;
|
||||
int deviation = abs((int)expected - (int)(npages_threshold));
|
||||
int deviation = abs((int)expected - (int)(npages_threshold));
|
||||
expect_d_lt(deviation, (int)(npages_threshold / 2),
|
||||
"After waiting, number of pages is out of the expected interval "
|
||||
"[0.5 * npages_threshold .. 1.5 * npages_threshold]");
|
||||
|
|
@ -272,12 +275,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_decay_init,
|
||||
test_decay_ms_valid,
|
||||
test_decay_npages_purge_in,
|
||||
test_decay_maybe_advance_epoch,
|
||||
test_decay_empty,
|
||||
test_decay,
|
||||
test_decay_ns_until_purge);
|
||||
return test(test_decay_init, test_decay_ms_valid,
|
||||
test_decay_npages_purge_in, test_decay_maybe_advance_epoch,
|
||||
test_decay_empty, test_decay, test_decay_ns_until_purge);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ TEST_BEGIN(test_div_exhaustive) {
|
|||
max = 1000 * 1000;
|
||||
}
|
||||
for (size_t dividend = 0; dividend < 1000 * divisor;
|
||||
dividend += divisor) {
|
||||
size_t quotient = div_compute(
|
||||
&div_info, dividend);
|
||||
dividend += divisor) {
|
||||
size_t quotient = div_compute(&div_info, dividend);
|
||||
expect_zu_eq(dividend, quotient * divisor,
|
||||
"With divisor = %zu, dividend = %zu, "
|
||||
"got quotient %zu", divisor, dividend, quotient);
|
||||
"got quotient %zu",
|
||||
divisor, dividend, quotient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_div_exhaustive);
|
||||
return test_no_reentrancy(test_div_exhaustive);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
#include "jemalloc/internal/safety_check.h"
|
||||
|
||||
bool fake_abort_called;
|
||||
void fake_abort(const char *message) {
|
||||
void
|
||||
fake_abort(const char *message) {
|
||||
(void)message;
|
||||
fake_abort_called = true;
|
||||
}
|
||||
|
|
@ -23,10 +24,9 @@ test_double_free_post(void) {
|
|||
|
||||
static bool
|
||||
tcache_enabled(void) {
|
||||
bool enabled;
|
||||
bool enabled;
|
||||
size_t sz = sizeof(enabled);
|
||||
assert_d_eq(
|
||||
mallctl("thread.tcache.enabled", &enabled, &sz, NULL, 0), 0,
|
||||
assert_d_eq(mallctl("thread.tcache.enabled", &enabled, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl failure");
|
||||
return enabled;
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ TEST_BEGIN(test_large_double_free_tcache) {
|
|||
|
||||
test_double_free_pre();
|
||||
char *ptr = malloc(SC_LARGE_MINCLASS);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
free(ptr);
|
||||
if (!guarded) {
|
||||
free(ptr);
|
||||
|
|
@ -64,7 +64,7 @@ TEST_BEGIN(test_large_double_free_no_tcache) {
|
|||
|
||||
test_double_free_pre();
|
||||
char *ptr = mallocx(SC_LARGE_MINCLASS, MALLOCX_TCACHE_NONE);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
dallocx(ptr, MALLOCX_TCACHE_NONE);
|
||||
if (!guarded) {
|
||||
dallocx(ptr, MALLOCX_TCACHE_NONE);
|
||||
|
|
@ -87,7 +87,7 @@ TEST_BEGIN(test_small_double_free_tcache) {
|
|||
|
||||
test_double_free_pre();
|
||||
char *ptr = malloc(1);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
free(ptr);
|
||||
if (!guarded) {
|
||||
free(ptr);
|
||||
|
|
@ -115,7 +115,7 @@ TEST_BEGIN(test_small_double_free_arena) {
|
|||
*/
|
||||
char *ptr1 = malloc(1);
|
||||
char *ptr = malloc(1);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
bool guarded = extent_is_guarded(tsdn_fetch(), ptr);
|
||||
free(ptr);
|
||||
if (!guarded) {
|
||||
mallctl("thread.tcache.flush", NULL, NULL, NULL, 0);
|
||||
|
|
@ -135,9 +135,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_large_double_free_no_tcache,
|
||||
test_large_double_free_tcache,
|
||||
test_small_double_free_tcache,
|
||||
return test(test_large_double_free_no_tcache,
|
||||
test_large_double_free_tcache, test_small_double_free_tcache,
|
||||
test_small_double_free_arena);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,16 +49,16 @@ TEST_END
|
|||
|
||||
static size_t
|
||||
ecf_count(edata_cache_fast_t *ecf) {
|
||||
size_t count = 0;
|
||||
size_t count = 0;
|
||||
edata_t *cur;
|
||||
ql_foreach(cur, &ecf->list.head, ql_link_inactive) {
|
||||
ql_foreach (cur, &ecf->list.head, ql_link_inactive) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_edata_cache_fast_simple) {
|
||||
edata_cache_t ec;
|
||||
edata_cache_t ec;
|
||||
edata_cache_fast_t ecf;
|
||||
|
||||
test_edata_cache_init(&ec);
|
||||
|
|
@ -96,7 +96,7 @@ TEST_BEGIN(test_edata_cache_fast_simple) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_edata_cache_fill) {
|
||||
edata_cache_t ec;
|
||||
edata_cache_t ec;
|
||||
edata_cache_fast_t ecf;
|
||||
|
||||
test_edata_cache_init(&ec);
|
||||
|
|
@ -179,7 +179,7 @@ TEST_BEGIN(test_edata_cache_fill) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_edata_cache_disable) {
|
||||
edata_cache_t ec;
|
||||
edata_cache_t ec;
|
||||
edata_cache_fast_t ecf;
|
||||
|
||||
test_edata_cache_init(&ec);
|
||||
|
|
@ -198,7 +198,8 @@ TEST_BEGIN(test_edata_cache_disable) {
|
|||
|
||||
expect_zu_eq(0, ecf_count(&ecf), "");
|
||||
expect_zu_eq(EDATA_CACHE_FAST_FILL,
|
||||
atomic_load_zu(&ec.count, ATOMIC_RELAXED), "Disabling should flush");
|
||||
atomic_load_zu(&ec.count, ATOMIC_RELAXED),
|
||||
"Disabling should flush");
|
||||
|
||||
edata_t *edata = edata_cache_fast_get(TSDN_NULL, &ecf);
|
||||
expect_zu_eq(0, ecf_count(&ecf), "");
|
||||
|
|
@ -218,9 +219,6 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_edata_cache,
|
||||
test_edata_cache_fast_simple,
|
||||
test_edata_cache_fill,
|
||||
test_edata_cache_disable);
|
||||
return test(test_edata_cache, test_edata_cache_fast_simple,
|
||||
test_edata_cache_fill, test_edata_cache_disable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ static bool print_escaped = false;
|
|||
|
||||
typedef struct buf_descriptor_s buf_descriptor_t;
|
||||
struct buf_descriptor_s {
|
||||
char *buf;
|
||||
char *buf;
|
||||
size_t len;
|
||||
bool mid_quote;
|
||||
bool mid_quote;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -56,8 +56,8 @@ forwarding_cb(void *buf_descriptor_v, const char *str) {
|
|||
}
|
||||
}
|
||||
|
||||
size_t written = malloc_snprintf(buf_descriptor->buf,
|
||||
buf_descriptor->len, "%s", str);
|
||||
size_t written = malloc_snprintf(
|
||||
buf_descriptor->buf, buf_descriptor->len, "%s", str);
|
||||
expect_zu_eq(written, strlen(str), "Buffer overflow!");
|
||||
buf_descriptor->buf += written;
|
||||
buf_descriptor->len -= written;
|
||||
|
|
@ -66,19 +66,18 @@ forwarding_cb(void *buf_descriptor_v, const char *str) {
|
|||
|
||||
static void
|
||||
expect_emit_output(void (*emit_fn)(emitter_t *),
|
||||
const char *expected_json_output,
|
||||
const char *expected_json_compact_output,
|
||||
const char *expected_json_output, const char *expected_json_compact_output,
|
||||
const char *expected_table_output) {
|
||||
emitter_t emitter;
|
||||
char buf[MALLOC_PRINTF_BUFSIZE];
|
||||
emitter_t emitter;
|
||||
char buf[MALLOC_PRINTF_BUFSIZE];
|
||||
buf_descriptor_t buf_descriptor;
|
||||
|
||||
buf_descriptor.buf = buf;
|
||||
buf_descriptor.len = MALLOC_PRINTF_BUFSIZE;
|
||||
buf_descriptor.mid_quote = false;
|
||||
|
||||
emitter_init(&emitter, emitter_output_json, &forwarding_cb,
|
||||
&buf_descriptor);
|
||||
emitter_init(
|
||||
&emitter, emitter_output_json, &forwarding_cb, &buf_descriptor);
|
||||
(*emit_fn)(&emitter);
|
||||
expect_str_eq(expected_json_output, buf, "json output failure");
|
||||
|
||||
|
|
@ -89,24 +88,24 @@ expect_emit_output(void (*emit_fn)(emitter_t *),
|
|||
emitter_init(&emitter, emitter_output_json_compact, &forwarding_cb,
|
||||
&buf_descriptor);
|
||||
(*emit_fn)(&emitter);
|
||||
expect_str_eq(expected_json_compact_output, buf,
|
||||
"compact json output failure");
|
||||
expect_str_eq(
|
||||
expected_json_compact_output, buf, "compact json output failure");
|
||||
|
||||
buf_descriptor.buf = buf;
|
||||
buf_descriptor.len = MALLOC_PRINTF_BUFSIZE;
|
||||
buf_descriptor.mid_quote = false;
|
||||
|
||||
emitter_init(&emitter, emitter_output_table, &forwarding_cb,
|
||||
&buf_descriptor);
|
||||
emitter_init(
|
||||
&emitter, emitter_output_table, &forwarding_cb, &buf_descriptor);
|
||||
(*emit_fn)(&emitter);
|
||||
expect_str_eq(expected_table_output, buf, "table output failure");
|
||||
}
|
||||
|
||||
static void
|
||||
emit_dict(emitter_t *emitter) {
|
||||
bool b_false = false;
|
||||
bool b_true = true;
|
||||
int i_123 = 123;
|
||||
bool b_false = false;
|
||||
bool b_true = true;
|
||||
int i_123 = 123;
|
||||
const char *str = "a string";
|
||||
|
||||
emitter_begin(emitter);
|
||||
|
|
@ -122,48 +121,49 @@ emit_dict(emitter_t *emitter) {
|
|||
}
|
||||
|
||||
static const char *dict_json =
|
||||
"{\n"
|
||||
"\t\"foo\": {\n"
|
||||
"\t\t\"abc\": false,\n"
|
||||
"\t\t\"def\": true,\n"
|
||||
"\t\t\"ghi\": 123,\n"
|
||||
"\t\t\"jkl\": \"a string\"\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"\t\"foo\": {\n"
|
||||
"\t\t\"abc\": false,\n"
|
||||
"\t\t\"def\": true,\n"
|
||||
"\t\t\"ghi\": 123,\n"
|
||||
"\t\t\"jkl\": \"a string\"\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
static const char *dict_json_compact =
|
||||
"{"
|
||||
"\"foo\":{"
|
||||
"\"abc\":false,"
|
||||
"\"def\":true,"
|
||||
"\"ghi\":123,"
|
||||
"\"jkl\":\"a string\""
|
||||
"}"
|
||||
"}";
|
||||
"{"
|
||||
"\"foo\":{"
|
||||
"\"abc\":false,"
|
||||
"\"def\":true,"
|
||||
"\"ghi\":123,"
|
||||
"\"jkl\":\"a string\""
|
||||
"}"
|
||||
"}";
|
||||
static const char *dict_table =
|
||||
"This is the foo table:\n"
|
||||
" ABC: false\n"
|
||||
" DEF: true\n"
|
||||
" GHI: 123 (note_key1: \"a string\")\n"
|
||||
" JKL: \"a string\" (note_key2: false)\n";
|
||||
"This is the foo table:\n"
|
||||
" ABC: false\n"
|
||||
" DEF: true\n"
|
||||
" GHI: 123 (note_key1: \"a string\")\n"
|
||||
" JKL: \"a string\" (note_key2: false)\n";
|
||||
|
||||
static void
|
||||
emit_table_printf(emitter_t *emitter) {
|
||||
emitter_begin(emitter);
|
||||
emitter_table_printf(emitter, "Table note 1\n");
|
||||
emitter_table_printf(emitter, "Table note 2 %s\n",
|
||||
"with format string");
|
||||
emitter_table_printf(
|
||||
emitter, "Table note 2 %s\n", "with format string");
|
||||
emitter_end(emitter);
|
||||
}
|
||||
|
||||
static const char *table_printf_json =
|
||||
"{\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"}\n";
|
||||
static const char *table_printf_json_compact = "{}";
|
||||
static const char *table_printf_table =
|
||||
"Table note 1\n"
|
||||
"Table note 2 with format string\n";
|
||||
"Table note 1\n"
|
||||
"Table note 2 with format string\n";
|
||||
|
||||
static void emit_nested_dict(emitter_t *emitter) {
|
||||
static void
|
||||
emit_nested_dict(emitter_t *emitter) {
|
||||
int val = 123;
|
||||
emitter_begin(emitter);
|
||||
emitter_dict_begin(emitter, "json1", "Dict 1");
|
||||
|
|
@ -174,53 +174,53 @@ static void emit_nested_dict(emitter_t *emitter) {
|
|||
emitter_dict_end(emitter); /* Close 3 */
|
||||
emitter_dict_end(emitter); /* Close 1 */
|
||||
emitter_dict_begin(emitter, "json4", "Dict 4");
|
||||
emitter_kv(emitter, "primitive", "Another primitive",
|
||||
emitter_type_int, &val);
|
||||
emitter_kv(
|
||||
emitter, "primitive", "Another primitive", emitter_type_int, &val);
|
||||
emitter_dict_end(emitter); /* Close 4 */
|
||||
emitter_end(emitter);
|
||||
}
|
||||
|
||||
static const char *nested_dict_json =
|
||||
"{\n"
|
||||
"\t\"json1\": {\n"
|
||||
"\t\t\"json2\": {\n"
|
||||
"\t\t\t\"primitive\": 123\n"
|
||||
"\t\t},\n"
|
||||
"\t\t\"json3\": {\n"
|
||||
"\t\t}\n"
|
||||
"\t},\n"
|
||||
"\t\"json4\": {\n"
|
||||
"\t\t\"primitive\": 123\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"\t\"json1\": {\n"
|
||||
"\t\t\"json2\": {\n"
|
||||
"\t\t\t\"primitive\": 123\n"
|
||||
"\t\t},\n"
|
||||
"\t\t\"json3\": {\n"
|
||||
"\t\t}\n"
|
||||
"\t},\n"
|
||||
"\t\"json4\": {\n"
|
||||
"\t\t\"primitive\": 123\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
static const char *nested_dict_json_compact =
|
||||
"{"
|
||||
"\"json1\":{"
|
||||
"\"json2\":{"
|
||||
"\"primitive\":123"
|
||||
"},"
|
||||
"\"json3\":{"
|
||||
"}"
|
||||
"},"
|
||||
"\"json4\":{"
|
||||
"\"primitive\":123"
|
||||
"}"
|
||||
"}";
|
||||
"{"
|
||||
"\"json1\":{"
|
||||
"\"json2\":{"
|
||||
"\"primitive\":123"
|
||||
"},"
|
||||
"\"json3\":{"
|
||||
"}"
|
||||
"},"
|
||||
"\"json4\":{"
|
||||
"\"primitive\":123"
|
||||
"}"
|
||||
"}";
|
||||
static const char *nested_dict_table =
|
||||
"Dict 1\n"
|
||||
" Dict 2\n"
|
||||
" A primitive: 123\n"
|
||||
" Dict 3\n"
|
||||
"Dict 4\n"
|
||||
" Another primitive: 123\n";
|
||||
"Dict 1\n"
|
||||
" Dict 2\n"
|
||||
" A primitive: 123\n"
|
||||
" Dict 3\n"
|
||||
"Dict 4\n"
|
||||
" Another primitive: 123\n";
|
||||
|
||||
static void
|
||||
emit_types(emitter_t *emitter) {
|
||||
bool b = false;
|
||||
int i = -123;
|
||||
unsigned u = 123;
|
||||
ssize_t zd = -456;
|
||||
size_t zu = 456;
|
||||
bool b = false;
|
||||
int i = -123;
|
||||
unsigned u = 123;
|
||||
ssize_t zd = -456;
|
||||
size_t zu = 456;
|
||||
const char *str = "string";
|
||||
const char *long_str =
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
|
|
@ -254,55 +254,55 @@ emit_types(emitter_t *emitter) {
|
|||
}
|
||||
|
||||
static const char *types_json =
|
||||
"{\n"
|
||||
"\t\"k1\": false,\n"
|
||||
"\t\"k2\": -123,\n"
|
||||
"\t\"k3\": 123,\n"
|
||||
"\t\"k4\": -456,\n"
|
||||
"\t\"k5\": 456,\n"
|
||||
"\t\"k6\": \"string\",\n"
|
||||
"\t\"k7\": \"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz\",\n"
|
||||
"\t\"k8\": 789,\n"
|
||||
"\t\"k9\": 10000000000\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"\t\"k1\": false,\n"
|
||||
"\t\"k2\": -123,\n"
|
||||
"\t\"k3\": 123,\n"
|
||||
"\t\"k4\": -456,\n"
|
||||
"\t\"k5\": 456,\n"
|
||||
"\t\"k6\": \"string\",\n"
|
||||
"\t\"k7\": \"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz\",\n"
|
||||
"\t\"k8\": 789,\n"
|
||||
"\t\"k9\": 10000000000\n"
|
||||
"}\n";
|
||||
static const char *types_json_compact =
|
||||
"{"
|
||||
"\"k1\":false,"
|
||||
"\"k2\":-123,"
|
||||
"\"k3\":123,"
|
||||
"\"k4\":-456,"
|
||||
"\"k5\":456,"
|
||||
"\"k6\":\"string\","
|
||||
"\"k7\":\"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz\","
|
||||
"\"k8\":789,"
|
||||
"\"k9\":10000000000"
|
||||
"}";
|
||||
"{"
|
||||
"\"k1\":false,"
|
||||
"\"k2\":-123,"
|
||||
"\"k3\":123,"
|
||||
"\"k4\":-456,"
|
||||
"\"k5\":456,"
|
||||
"\"k6\":\"string\","
|
||||
"\"k7\":\"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz\","
|
||||
"\"k8\":789,"
|
||||
"\"k9\":10000000000"
|
||||
"}";
|
||||
static const char *types_table =
|
||||
"K1: false\n"
|
||||
"K2: -123\n"
|
||||
"K3: 123\n"
|
||||
"K4: -456\n"
|
||||
"K5: 456\n"
|
||||
"K6: \"string\"\n"
|
||||
"K7: \"abcdefghijklmnopqrstuvwxyz "
|
||||
"K1: false\n"
|
||||
"K2: -123\n"
|
||||
"K3: 123\n"
|
||||
"K4: -456\n"
|
||||
"K5: 456\n"
|
||||
"K6: \"string\"\n"
|
||||
"K7: \"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
|
|
@ -312,8 +312,8 @@ static const char *types_table =
|
|||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz "
|
||||
"abcdefghijklmnopqrstuvwxyz\"\n"
|
||||
"K8: 789\n"
|
||||
"K9: 10000000000\n";
|
||||
"K8: 789\n"
|
||||
"K9: 10000000000\n";
|
||||
|
||||
static void
|
||||
emit_modal(emitter_t *emitter) {
|
||||
|
|
@ -336,37 +336,37 @@ emit_modal(emitter_t *emitter) {
|
|||
}
|
||||
|
||||
const char *modal_json =
|
||||
"{\n"
|
||||
"\t\"j0\": {\n"
|
||||
"\t\t\"j1\": {\n"
|
||||
"\t\t\t\"i1\": 123,\n"
|
||||
"\t\t\t\"i2\": 123,\n"
|
||||
"\t\t\t\"i4\": 123\n"
|
||||
"\t\t},\n"
|
||||
"\t\t\"i5\": 123,\n"
|
||||
"\t\t\"i6\": 123\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"\t\"j0\": {\n"
|
||||
"\t\t\"j1\": {\n"
|
||||
"\t\t\t\"i1\": 123,\n"
|
||||
"\t\t\t\"i2\": 123,\n"
|
||||
"\t\t\t\"i4\": 123\n"
|
||||
"\t\t},\n"
|
||||
"\t\t\"i5\": 123,\n"
|
||||
"\t\t\"i6\": 123\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
const char *modal_json_compact =
|
||||
"{"
|
||||
"\"j0\":{"
|
||||
"\"j1\":{"
|
||||
"\"i1\":123,"
|
||||
"\"i2\":123,"
|
||||
"\"i4\":123"
|
||||
"},"
|
||||
"\"i5\":123,"
|
||||
"\"i6\":123"
|
||||
"}"
|
||||
"}";
|
||||
"{"
|
||||
"\"j0\":{"
|
||||
"\"j1\":{"
|
||||
"\"i1\":123,"
|
||||
"\"i2\":123,"
|
||||
"\"i4\":123"
|
||||
"},"
|
||||
"\"i5\":123,"
|
||||
"\"i6\":123"
|
||||
"}"
|
||||
"}";
|
||||
const char *modal_table =
|
||||
"T0\n"
|
||||
" I1: 123\n"
|
||||
" I3: 123\n"
|
||||
" T1\n"
|
||||
" I4: 123\n"
|
||||
" I5: 123\n"
|
||||
" I6: 123\n";
|
||||
"T0\n"
|
||||
" I1: 123\n"
|
||||
" I3: 123\n"
|
||||
" T1\n"
|
||||
" I4: 123\n"
|
||||
" I5: 123\n"
|
||||
" I6: 123\n";
|
||||
|
||||
static void
|
||||
emit_json_array(emitter_t *emitter) {
|
||||
|
|
@ -387,121 +387,124 @@ emit_json_array(emitter_t *emitter) {
|
|||
emitter_json_kv(emitter, "bar", emitter_type_int, &ival);
|
||||
emitter_json_kv(emitter, "baz", emitter_type_int, &ival);
|
||||
emitter_json_object_end(emitter); /* Close arr[3]. */
|
||||
emitter_json_array_end(emitter); /* Close arr. */
|
||||
emitter_json_array_end(emitter); /* Close arr. */
|
||||
emitter_json_object_end(emitter); /* Close dict. */
|
||||
emitter_end(emitter);
|
||||
}
|
||||
|
||||
static const char *json_array_json =
|
||||
"{\n"
|
||||
"\t\"dict\": {\n"
|
||||
"\t\t\"arr\": [\n"
|
||||
"\t\t\t{\n"
|
||||
"\t\t\t\t\"foo\": 123\n"
|
||||
"\t\t\t},\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t{\n"
|
||||
"\t\t\t\t\"bar\": 123,\n"
|
||||
"\t\t\t\t\"baz\": 123\n"
|
||||
"\t\t\t}\n"
|
||||
"\t\t]\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"\t\"dict\": {\n"
|
||||
"\t\t\"arr\": [\n"
|
||||
"\t\t\t{\n"
|
||||
"\t\t\t\t\"foo\": 123\n"
|
||||
"\t\t\t},\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t{\n"
|
||||
"\t\t\t\t\"bar\": 123,\n"
|
||||
"\t\t\t\t\"baz\": 123\n"
|
||||
"\t\t\t}\n"
|
||||
"\t\t]\n"
|
||||
"\t}\n"
|
||||
"}\n";
|
||||
static const char *json_array_json_compact =
|
||||
"{"
|
||||
"\"dict\":{"
|
||||
"\"arr\":["
|
||||
"{"
|
||||
"\"foo\":123"
|
||||
"},"
|
||||
"123,"
|
||||
"123,"
|
||||
"{"
|
||||
"\"bar\":123,"
|
||||
"\"baz\":123"
|
||||
"}"
|
||||
"]"
|
||||
"}"
|
||||
"}";
|
||||
"{"
|
||||
"\"dict\":{"
|
||||
"\"arr\":["
|
||||
"{"
|
||||
"\"foo\":123"
|
||||
"},"
|
||||
"123,"
|
||||
"123,"
|
||||
"{"
|
||||
"\"bar\":123,"
|
||||
"\"baz\":123"
|
||||
"}"
|
||||
"]"
|
||||
"}"
|
||||
"}";
|
||||
static const char *json_array_table = "";
|
||||
|
||||
static void
|
||||
emit_json_nested_array(emitter_t *emitter) {
|
||||
int ival = 123;
|
||||
int ival = 123;
|
||||
char *sval = "foo";
|
||||
emitter_begin(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_value(emitter, emitter_type_string, &sval);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_value(emitter, emitter_type_string, &sval);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_value(emitter, emitter_type_string, &sval);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_value(emitter, emitter_type_string, &sval);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_value(emitter, emitter_type_string, &sval);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_value(emitter, emitter_type_string, &sval);
|
||||
emitter_json_value(emitter, emitter_type_int, &ival);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_begin(emitter);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_json_array_end(emitter);
|
||||
emitter_end(emitter);
|
||||
}
|
||||
|
||||
static const char *json_nested_array_json =
|
||||
"{\n"
|
||||
"\t[\n"
|
||||
"\t\t[\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t\"foo\",\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t\"foo\"\n"
|
||||
"\t\t],\n"
|
||||
"\t\t[\n"
|
||||
"\t\t\t123\n"
|
||||
"\t\t],\n"
|
||||
"\t\t[\n"
|
||||
"\t\t\t\"foo\",\n"
|
||||
"\t\t\t123\n"
|
||||
"\t\t],\n"
|
||||
"\t\t[\n"
|
||||
"\t\t]\n"
|
||||
"\t]\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"\t[\n"
|
||||
"\t\t[\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t\"foo\",\n"
|
||||
"\t\t\t123,\n"
|
||||
"\t\t\t\"foo\"\n"
|
||||
"\t\t],\n"
|
||||
"\t\t[\n"
|
||||
"\t\t\t123\n"
|
||||
"\t\t],\n"
|
||||
"\t\t[\n"
|
||||
"\t\t\t\"foo\",\n"
|
||||
"\t\t\t123\n"
|
||||
"\t\t],\n"
|
||||
"\t\t[\n"
|
||||
"\t\t]\n"
|
||||
"\t]\n"
|
||||
"}\n";
|
||||
static const char *json_nested_array_json_compact =
|
||||
"{"
|
||||
"["
|
||||
"["
|
||||
"123,"
|
||||
"\"foo\","
|
||||
"123,"
|
||||
"\"foo\""
|
||||
"],"
|
||||
"["
|
||||
"123"
|
||||
"],"
|
||||
"["
|
||||
"\"foo\","
|
||||
"123"
|
||||
"],"
|
||||
"["
|
||||
"]"
|
||||
"]"
|
||||
"}";
|
||||
"{"
|
||||
"["
|
||||
"["
|
||||
"123,"
|
||||
"\"foo\","
|
||||
"123,"
|
||||
"\"foo\""
|
||||
"],"
|
||||
"["
|
||||
"123"
|
||||
"],"
|
||||
"["
|
||||
"\"foo\","
|
||||
"123"
|
||||
"],"
|
||||
"["
|
||||
"]"
|
||||
"]"
|
||||
"}";
|
||||
static const char *json_nested_array_table = "";
|
||||
|
||||
static void
|
||||
emit_table_row(emitter_t *emitter) {
|
||||
emitter_begin(emitter);
|
||||
emitter_row_t row;
|
||||
emitter_col_t abc = {emitter_justify_left, 10, emitter_type_title, {0}, {0, 0}};
|
||||
emitter_col_t abc = {
|
||||
emitter_justify_left, 10, emitter_type_title, {0}, {0, 0}};
|
||||
abc.str_val = "ABC title";
|
||||
emitter_col_t def = {emitter_justify_right, 15, emitter_type_title, {0}, {0, 0}};
|
||||
emitter_col_t def = {
|
||||
emitter_justify_right, 15, emitter_type_title, {0}, {0, 0}};
|
||||
def.str_val = "DEF title";
|
||||
emitter_col_t ghi = {emitter_justify_right, 5, emitter_type_title, {0}, {0, 0}};
|
||||
emitter_col_t ghi = {
|
||||
emitter_justify_right, 5, emitter_type_title, {0}, {0, 0}};
|
||||
ghi.str_val = "GHI";
|
||||
|
||||
emitter_row_init(&row);
|
||||
|
|
@ -536,21 +539,21 @@ emit_table_row(emitter_t *emitter) {
|
|||
}
|
||||
|
||||
static const char *table_row_json =
|
||||
"{\n"
|
||||
"}\n";
|
||||
"{\n"
|
||||
"}\n";
|
||||
static const char *table_row_json_compact = "{}";
|
||||
static const char *table_row_table =
|
||||
"ABC title DEF title GHI\n"
|
||||
"123 true 456\n"
|
||||
"789 false 1011\n"
|
||||
"\"a string\" false ghi\n";
|
||||
"ABC title DEF title GHI\n"
|
||||
"123 true 456\n"
|
||||
"789 false 1011\n"
|
||||
"\"a string\" false ghi\n";
|
||||
|
||||
#define GENERATE_TEST(feature) \
|
||||
TEST_BEGIN(test_##feature) { \
|
||||
expect_emit_output(emit_##feature, feature##_json, \
|
||||
feature##_json_compact, feature##_table); \
|
||||
} \
|
||||
TEST_END
|
||||
#define GENERATE_TEST(feature) \
|
||||
TEST_BEGIN(test_##feature) { \
|
||||
expect_emit_output(emit_##feature, feature##_json, \
|
||||
feature##_json_compact, feature##_table); \
|
||||
} \
|
||||
TEST_END
|
||||
|
||||
GENERATE_TEST(dict)
|
||||
GENERATE_TEST(table_printf)
|
||||
|
|
@ -563,13 +566,7 @@ GENERATE_TEST(table_row)
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_dict,
|
||||
test_table_printf,
|
||||
test_nested_dict,
|
||||
test_types,
|
||||
test_modal,
|
||||
test_json_array,
|
||||
test_json_nested_array,
|
||||
test_table_row);
|
||||
return test_no_reentrancy(test_dict, test_table_printf,
|
||||
test_nested_dict, test_types, test_modal, test_json_array,
|
||||
test_json_nested_array, test_table_row);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
TEST_BEGIN(test_small_extent_size) {
|
||||
unsigned nbins, i;
|
||||
size_t sz, extent_size;
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
size_t sz, extent_size;
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
|
||||
/*
|
||||
* Iterate over all small size classes, get their extent sizes, and
|
||||
|
|
@ -21,25 +21,26 @@ TEST_BEGIN(test_small_extent_size) {
|
|||
mib[2] = i;
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&extent_size, &sz,
|
||||
NULL, 0), 0, "Unexpected mallctlbymib failure");
|
||||
expect_zu_eq(extent_size,
|
||||
sz_psz_quantize_floor(extent_size),
|
||||
NULL, 0),
|
||||
0, "Unexpected mallctlbymib failure");
|
||||
expect_zu_eq(extent_size, sz_psz_quantize_floor(extent_size),
|
||||
"Small extent quantization should be a no-op "
|
||||
"(extent_size=%zu)", extent_size);
|
||||
expect_zu_eq(extent_size,
|
||||
sz_psz_quantize_ceil(extent_size),
|
||||
"(extent_size=%zu)",
|
||||
extent_size);
|
||||
expect_zu_eq(extent_size, sz_psz_quantize_ceil(extent_size),
|
||||
"Small extent quantization should be a no-op "
|
||||
"(extent_size=%zu)", extent_size);
|
||||
"(extent_size=%zu)",
|
||||
extent_size);
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_large_extent_size) {
|
||||
bool cache_oblivious;
|
||||
bool cache_oblivious;
|
||||
unsigned nlextents, i;
|
||||
size_t sz, extent_size_prev, ceil_prev;
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
size_t sz, extent_size_prev, ceil_prev;
|
||||
size_t mib[4];
|
||||
size_t miblen = sizeof(mib) / sizeof(size_t);
|
||||
|
||||
/*
|
||||
* Iterate over all large size classes, get their extent sizes, and
|
||||
|
|
@ -48,11 +49,13 @@ TEST_BEGIN(test_large_extent_size) {
|
|||
|
||||
sz = sizeof(bool);
|
||||
expect_d_eq(mallctl("opt.cache_oblivious", (void *)&cache_oblivious,
|
||||
&sz, NULL, 0), 0, "Unexpected mallctl failure");
|
||||
&sz, NULL, 0),
|
||||
0, "Unexpected mallctl failure");
|
||||
|
||||
sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.nlextents", (void *)&nlextents, &sz, NULL,
|
||||
0), 0, "Unexpected mallctl failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.nlextents", (void *)&nlextents, &sz, NULL, 0), 0,
|
||||
"Unexpected mallctl failure");
|
||||
|
||||
expect_d_eq(mallctlnametomib("arenas.lextent.0.size", mib, &miblen), 0,
|
||||
"Unexpected mallctlnametomib failure");
|
||||
|
|
@ -62,20 +65,21 @@ TEST_BEGIN(test_large_extent_size) {
|
|||
mib[2] = i;
|
||||
sz = sizeof(size_t);
|
||||
expect_d_eq(mallctlbymib(mib, miblen, (void *)&lextent_size,
|
||||
&sz, NULL, 0), 0, "Unexpected mallctlbymib failure");
|
||||
extent_size = cache_oblivious ? lextent_size + PAGE :
|
||||
lextent_size;
|
||||
&sz, NULL, 0),
|
||||
0, "Unexpected mallctlbymib failure");
|
||||
extent_size = cache_oblivious ? lextent_size + PAGE
|
||||
: lextent_size;
|
||||
floor = sz_psz_quantize_floor(extent_size);
|
||||
ceil = sz_psz_quantize_ceil(extent_size);
|
||||
|
||||
expect_zu_eq(extent_size, floor,
|
||||
"Extent quantization should be a no-op for precise size "
|
||||
"(lextent_size=%zu, extent_size=%zu)", lextent_size,
|
||||
extent_size);
|
||||
"(lextent_size=%zu, extent_size=%zu)",
|
||||
lextent_size, extent_size);
|
||||
expect_zu_eq(extent_size, ceil,
|
||||
"Extent quantization should be a no-op for precise size "
|
||||
"(lextent_size=%zu, extent_size=%zu)", lextent_size,
|
||||
extent_size);
|
||||
"(lextent_size=%zu, extent_size=%zu)",
|
||||
lextent_size, extent_size);
|
||||
|
||||
if (i > 0) {
|
||||
expect_zu_eq(extent_size_prev,
|
||||
|
|
@ -85,23 +89,22 @@ TEST_BEGIN(test_large_extent_size) {
|
|||
expect_zu_eq(ceil_prev, extent_size,
|
||||
"Ceiling should be a precise size "
|
||||
"(extent_size_prev=%zu, ceil_prev=%zu, "
|
||||
"extent_size=%zu)", extent_size_prev,
|
||||
ceil_prev, extent_size);
|
||||
"extent_size=%zu)",
|
||||
extent_size_prev, ceil_prev, extent_size);
|
||||
}
|
||||
}
|
||||
if (i + 1 < nlextents) {
|
||||
extent_size_prev = floor;
|
||||
ceil_prev = sz_psz_quantize_ceil(extent_size +
|
||||
PAGE);
|
||||
ceil_prev = sz_psz_quantize_ceil(extent_size + PAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_monotonic) {
|
||||
#define SZ_MAX ZU(4 * 1024 * 1024)
|
||||
#define SZ_MAX ZU(4 * 1024 * 1024)
|
||||
unsigned i;
|
||||
size_t floor_prev, ceil_prev;
|
||||
size_t floor_prev, ceil_prev;
|
||||
|
||||
floor_prev = 0;
|
||||
ceil_prev = 0;
|
||||
|
|
@ -117,12 +120,15 @@ TEST_BEGIN(test_monotonic) {
|
|||
floor, extent_size, ceil);
|
||||
expect_zu_ge(ceil, extent_size,
|
||||
"Ceiling should be >= (floor=%zu, extent_size=%zu, "
|
||||
"ceil=%zu)", floor, extent_size, ceil);
|
||||
"ceil=%zu)",
|
||||
floor, extent_size, ceil);
|
||||
|
||||
expect_zu_le(floor_prev, floor, "Floor should be monotonic "
|
||||
expect_zu_le(floor_prev, floor,
|
||||
"Floor should be monotonic "
|
||||
"(floor_prev=%zu, floor=%zu, extent_size=%zu, ceil=%zu)",
|
||||
floor_prev, floor, extent_size, ceil);
|
||||
expect_zu_le(ceil_prev, ceil, "Ceiling should be monotonic "
|
||||
expect_zu_le(ceil_prev, ceil,
|
||||
"Ceiling should be monotonic "
|
||||
"(floor=%zu, extent_size=%zu, ceil_prev=%zu, ceil=%zu)",
|
||||
floor, extent_size, ceil_prev, ceil);
|
||||
|
||||
|
|
@ -135,7 +141,5 @@ TEST_END
|
|||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_small_extent_size,
|
||||
test_large_extent_size,
|
||||
test_monotonic);
|
||||
test_small_extent_size, test_large_extent_size, test_monotonic);
|
||||
}
|
||||
|
|
|
|||
220
test/unit/fb.c
220
test/unit/fb.c
|
|
@ -5,21 +5,19 @@
|
|||
|
||||
static void
|
||||
do_test_init(size_t nbits) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb = malloc(sz);
|
||||
/* Junk fb's contents. */
|
||||
memset(fb, 99, sz);
|
||||
fb_init(fb, nbits);
|
||||
for (size_t i = 0; i < nbits; i++) {
|
||||
expect_false(fb_get(fb, nbits, i),
|
||||
"bitmap should start empty");
|
||||
expect_false(fb_get(fb, nbits, i), "bitmap should start empty");
|
||||
}
|
||||
free(fb);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_fb_init) {
|
||||
#define NB(nbits) \
|
||||
do_test_init(nbits);
|
||||
#define NB(nbits) do_test_init(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -27,7 +25,7 @@ TEST_END
|
|||
|
||||
static void
|
||||
do_test_get_set_unset(size_t nbits) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb = malloc(sz);
|
||||
fb_init(fb, nbits);
|
||||
/* Set the bits divisible by 3. */
|
||||
|
|
@ -56,8 +54,7 @@ do_test_get_set_unset(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_get_set_unset) {
|
||||
#define NB(nbits) \
|
||||
do_test_get_set_unset(nbits);
|
||||
#define NB(nbits) do_test_get_set_unset(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -65,7 +62,7 @@ TEST_END
|
|||
|
||||
static ssize_t
|
||||
find_3_5_compute(ssize_t i, size_t nbits, bool bit, bool forward) {
|
||||
for(; i < (ssize_t)nbits && i >= 0; i += (forward ? 1 : -1)) {
|
||||
for (; i < (ssize_t)nbits && i >= 0; i += (forward ? 1 : -1)) {
|
||||
bool expected_bit = i % 3 == 0 || i % 5 == 0;
|
||||
if (expected_bit == bit) {
|
||||
return i;
|
||||
|
|
@ -76,7 +73,7 @@ find_3_5_compute(ssize_t i, size_t nbits, bool bit, bool forward) {
|
|||
|
||||
static void
|
||||
do_test_search_simple(size_t nbits) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb = malloc(sz);
|
||||
fb_init(fb, nbits);
|
||||
|
||||
|
|
@ -96,7 +93,7 @@ do_test_search_simple(size_t nbits) {
|
|||
expect_zu_eq(ffs_compute, ffs_search, "ffs mismatch at %zu", i);
|
||||
|
||||
ssize_t fls_compute = find_3_5_compute(i, nbits, true, false);
|
||||
size_t fls_search = fb_fls(fb, nbits, i);
|
||||
size_t fls_search = fb_fls(fb, nbits, i);
|
||||
expect_zu_eq(fls_compute, fls_search, "fls mismatch at %zu", i);
|
||||
|
||||
size_t ffu_compute = find_3_5_compute(i, nbits, false, true);
|
||||
|
|
@ -112,8 +109,7 @@ do_test_search_simple(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_search_simple) {
|
||||
#define NB(nbits) \
|
||||
do_test_search_simple(nbits);
|
||||
#define NB(nbits) do_test_search_simple(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -145,15 +141,17 @@ expect_exhaustive_results(fb_group_t *mostly_full, fb_group_t *mostly_empty,
|
|||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(special_bit, fb_fls(mostly_empty, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zu_eq(position + 1, fb_ffu(mostly_empty, nbits, position),
|
||||
expect_zu_eq(position + 1,
|
||||
fb_ffu(mostly_empty, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(position - 1,
|
||||
fb_flu(mostly_empty, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(position - 1, fb_flu(mostly_empty, nbits,
|
||||
position), "mismatch at %zu, %zu", position, special_bit);
|
||||
|
||||
expect_zu_eq(position + 1, fb_ffs(mostly_full, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(position - 1, fb_fls(mostly_full, nbits,
|
||||
position), "mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(position - 1, fb_fls(mostly_full, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zu_eq(position, fb_ffu(mostly_full, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(position, fb_flu(mostly_full, nbits, position),
|
||||
|
|
@ -162,8 +160,8 @@ expect_exhaustive_results(fb_group_t *mostly_full, fb_group_t *mostly_empty,
|
|||
/* position > special_bit. */
|
||||
expect_zu_eq(nbits, fb_ffs(mostly_empty, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(special_bit, fb_fls(mostly_empty, nbits,
|
||||
position), "mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(special_bit, fb_fls(mostly_empty, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zu_eq(position, fb_ffu(mostly_empty, nbits, position),
|
||||
"mismatch at %zu, %zu", position, special_bit);
|
||||
expect_zd_eq(position, fb_flu(mostly_empty, nbits, position),
|
||||
|
|
@ -186,7 +184,7 @@ do_test_search_exhaustive(size_t nbits) {
|
|||
if (nbits > 1000) {
|
||||
return;
|
||||
}
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *empty = malloc(sz);
|
||||
fb_init(empty, nbits);
|
||||
fb_group_t *full = malloc(sz);
|
||||
|
|
@ -209,8 +207,7 @@ do_test_search_exhaustive(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_search_exhaustive) {
|
||||
#define NB(nbits) \
|
||||
do_test_search_exhaustive(nbits);
|
||||
#define NB(nbits) do_test_search_exhaustive(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -222,8 +219,8 @@ TEST_BEGIN(test_range_simple) {
|
|||
* big enough that usages of things like weirdnum (below) near the
|
||||
* beginning fit comfortably into the beginning of the bitmap.
|
||||
*/
|
||||
size_t nbits = 64 * 10;
|
||||
size_t ngroups = FB_NGROUPS(nbits);
|
||||
size_t nbits = 64 * 10;
|
||||
size_t ngroups = FB_NGROUPS(nbits);
|
||||
fb_group_t *fb = malloc(sizeof(fb_group_t) * ngroups);
|
||||
fb_init(fb, nbits);
|
||||
for (size_t i = 0; i < nbits; i++) {
|
||||
|
|
@ -255,7 +252,7 @@ TEST_END
|
|||
|
||||
static void
|
||||
do_test_empty_full_exhaustive(size_t nbits) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *empty = malloc(sz);
|
||||
fb_init(empty, nbits);
|
||||
fb_group_t *full = malloc(sz);
|
||||
|
|
@ -273,15 +270,15 @@ do_test_empty_full_exhaustive(size_t nbits) {
|
|||
|
||||
expect_false(fb_empty(empty, nbits), "error at bit %zu", i);
|
||||
if (nbits != 1) {
|
||||
expect_false(fb_full(empty, nbits),
|
||||
"error at bit %zu", i);
|
||||
expect_false(fb_empty(full, nbits),
|
||||
"error at bit %zu", i);
|
||||
expect_false(
|
||||
fb_full(empty, nbits), "error at bit %zu", i);
|
||||
expect_false(
|
||||
fb_empty(full, nbits), "error at bit %zu", i);
|
||||
} else {
|
||||
expect_true(fb_full(empty, nbits),
|
||||
"error at bit %zu", i);
|
||||
expect_true(fb_empty(full, nbits),
|
||||
"error at bit %zu", i);
|
||||
expect_true(
|
||||
fb_full(empty, nbits), "error at bit %zu", i);
|
||||
expect_true(
|
||||
fb_empty(full, nbits), "error at bit %zu", i);
|
||||
}
|
||||
expect_false(fb_full(full, nbits), "error at bit %zu", i);
|
||||
|
||||
|
|
@ -294,8 +291,7 @@ do_test_empty_full_exhaustive(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_empty_full) {
|
||||
#define NB(nbits) \
|
||||
do_test_empty_full_exhaustive(nbits);
|
||||
#define NB(nbits) do_test_empty_full_exhaustive(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -306,8 +302,8 @@ TEST_END
|
|||
* built closely on top of it.
|
||||
*/
|
||||
TEST_BEGIN(test_iter_range_simple) {
|
||||
size_t set_limit = 30;
|
||||
size_t nbits = 100;
|
||||
size_t set_limit = 30;
|
||||
size_t nbits = 100;
|
||||
fb_group_t fb[FB_NGROUPS(100)];
|
||||
|
||||
fb_init(fb, nbits);
|
||||
|
|
@ -318,7 +314,7 @@ TEST_BEGIN(test_iter_range_simple) {
|
|||
*/
|
||||
size_t begin = (size_t)-1;
|
||||
size_t len = (size_t)-1;
|
||||
bool result;
|
||||
bool result;
|
||||
|
||||
/* A set of checks with only the first set_limit bits *set*. */
|
||||
fb_set_range(fb, nbits, 0, set_limit);
|
||||
|
|
@ -410,7 +406,6 @@ TEST_BEGIN(test_iter_range_simple) {
|
|||
expect_zu_eq(0, begin, "Incorrect begin at %zu", i);
|
||||
expect_zu_eq(set_limit, len, "Incorrect len at %zu", i);
|
||||
}
|
||||
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -426,11 +421,11 @@ fb_iter_simple(fb_group_t *fb, size_t nbits, size_t start, size_t *r_begin,
|
|||
ssize_t stride = (forward ? (ssize_t)1 : (ssize_t)-1);
|
||||
ssize_t range_begin = (ssize_t)start;
|
||||
for (; range_begin != (ssize_t)nbits && range_begin != -1;
|
||||
range_begin += stride) {
|
||||
range_begin += stride) {
|
||||
if (fb_get(fb, nbits, range_begin) == val) {
|
||||
ssize_t range_end = range_begin;
|
||||
for (; range_end != (ssize_t)nbits && range_end != -1;
|
||||
range_end += stride) {
|
||||
range_end += stride) {
|
||||
if (fb_get(fb, nbits, range_end) != val) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -470,26 +465,26 @@ fb_range_longest_simple(fb_group_t *fb, size_t nbits, bool val) {
|
|||
}
|
||||
|
||||
static void
|
||||
expect_iter_results_at(fb_group_t *fb, size_t nbits, size_t pos,
|
||||
bool val, bool forward) {
|
||||
bool iter_res;
|
||||
expect_iter_results_at(
|
||||
fb_group_t *fb, size_t nbits, size_t pos, bool val, bool forward) {
|
||||
bool iter_res;
|
||||
size_t iter_begin JEMALLOC_CC_SILENCE_INIT(0);
|
||||
size_t iter_len JEMALLOC_CC_SILENCE_INIT(0);
|
||||
size_t iter_len JEMALLOC_CC_SILENCE_INIT(0);
|
||||
if (val) {
|
||||
if (forward) {
|
||||
iter_res = fb_srange_iter(fb, nbits, pos,
|
||||
&iter_begin, &iter_len);
|
||||
iter_res = fb_srange_iter(
|
||||
fb, nbits, pos, &iter_begin, &iter_len);
|
||||
} else {
|
||||
iter_res = fb_srange_riter(fb, nbits, pos,
|
||||
&iter_begin, &iter_len);
|
||||
iter_res = fb_srange_riter(
|
||||
fb, nbits, pos, &iter_begin, &iter_len);
|
||||
}
|
||||
} else {
|
||||
if (forward) {
|
||||
iter_res = fb_urange_iter(fb, nbits, pos,
|
||||
&iter_begin, &iter_len);
|
||||
iter_res = fb_urange_iter(
|
||||
fb, nbits, pos, &iter_begin, &iter_len);
|
||||
} else {
|
||||
iter_res = fb_urange_riter(fb, nbits, pos,
|
||||
&iter_begin, &iter_len);
|
||||
iter_res = fb_urange_riter(
|
||||
fb, nbits, pos, &iter_begin, &iter_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -500,15 +495,15 @@ expect_iter_results_at(fb_group_t *fb, size_t nbits, size_t pos,
|
|||
*/
|
||||
size_t simple_iter_begin = 0;
|
||||
size_t simple_iter_len = 0;
|
||||
simple_iter_res = fb_iter_simple(fb, nbits, pos, &simple_iter_begin,
|
||||
&simple_iter_len, val, forward);
|
||||
simple_iter_res = fb_iter_simple(
|
||||
fb, nbits, pos, &simple_iter_begin, &simple_iter_len, val, forward);
|
||||
|
||||
expect_b_eq(iter_res, simple_iter_res, "Result mismatch at %zu", pos);
|
||||
if (iter_res && simple_iter_res) {
|
||||
assert_zu_eq(iter_begin, simple_iter_begin,
|
||||
"Begin mismatch at %zu", pos);
|
||||
expect_zu_eq(iter_len, simple_iter_len,
|
||||
"Length mismatch at %zu", pos);
|
||||
expect_zu_eq(
|
||||
iter_len, simple_iter_len, "Length mismatch at %zu", pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -543,7 +538,7 @@ do_test_iter_range_exhaustive(size_t nbits) {
|
|||
if (nbits > 1000) {
|
||||
return;
|
||||
}
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb = malloc(sz);
|
||||
fb_init(fb, nbits);
|
||||
|
||||
|
|
@ -558,7 +553,7 @@ do_test_iter_range_exhaustive(size_t nbits) {
|
|||
expect_iter_results(fb, nbits);
|
||||
|
||||
fb_unset_range(fb, nbits, 0, nbits);
|
||||
fb_set_range(fb, nbits, 0, nbits / 2 == 0 ? 1: nbits / 2);
|
||||
fb_set_range(fb, nbits, 0, nbits / 2 == 0 ? 1 : nbits / 2);
|
||||
expect_iter_results(fb, nbits);
|
||||
|
||||
free(fb);
|
||||
|
|
@ -569,8 +564,7 @@ do_test_iter_range_exhaustive(size_t nbits) {
|
|||
* computation.
|
||||
*/
|
||||
TEST_BEGIN(test_iter_range_exhaustive) {
|
||||
#define NB(nbits) \
|
||||
do_test_iter_range_exhaustive(nbits);
|
||||
#define NB(nbits) do_test_iter_range_exhaustive(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -581,8 +575,8 @@ TEST_END
|
|||
* returns the number of set bits in [scount_start, scount_end).
|
||||
*/
|
||||
static size_t
|
||||
scount_contiguous(size_t set_start, size_t set_end, size_t scount_start,
|
||||
size_t scount_end) {
|
||||
scount_contiguous(
|
||||
size_t set_start, size_t set_end, size_t scount_start, size_t scount_end) {
|
||||
/* No overlap. */
|
||||
if (set_end <= scount_start || scount_end <= set_start) {
|
||||
return 0;
|
||||
|
|
@ -611,8 +605,8 @@ scount_contiguous(size_t set_start, size_t set_end, size_t scount_start,
|
|||
}
|
||||
|
||||
static size_t
|
||||
ucount_contiguous(size_t set_start, size_t set_end, size_t ucount_start,
|
||||
size_t ucount_end) {
|
||||
ucount_contiguous(
|
||||
size_t set_start, size_t set_end, size_t ucount_start, size_t ucount_end) {
|
||||
/* No overlap. */
|
||||
if (set_end <= ucount_start || ucount_end <= set_start) {
|
||||
return ucount_end - ucount_start;
|
||||
|
|
@ -641,34 +635,33 @@ ucount_contiguous(size_t set_start, size_t set_end, size_t ucount_start,
|
|||
}
|
||||
|
||||
static void
|
||||
expect_count_match_contiguous(fb_group_t *fb, size_t nbits, size_t set_start,
|
||||
size_t set_end) {
|
||||
expect_count_match_contiguous(
|
||||
fb_group_t *fb, size_t nbits, size_t set_start, size_t set_end) {
|
||||
for (size_t i = 0; i < nbits; i++) {
|
||||
for (size_t j = i + 1; j <= nbits; j++) {
|
||||
size_t cnt = j - i;
|
||||
size_t scount_expected = scount_contiguous(set_start,
|
||||
set_end, i, j);
|
||||
size_t scount_expected = scount_contiguous(
|
||||
set_start, set_end, i, j);
|
||||
size_t scount_computed = fb_scount(fb, nbits, i, cnt);
|
||||
expect_zu_eq(scount_expected, scount_computed,
|
||||
"fb_scount error with nbits=%zu, start=%zu, "
|
||||
"cnt=%zu, with bits set in [%zu, %zu)",
|
||||
nbits, i, cnt, set_start, set_end);
|
||||
|
||||
size_t ucount_expected = ucount_contiguous(set_start,
|
||||
set_end, i, j);
|
||||
size_t ucount_expected = ucount_contiguous(
|
||||
set_start, set_end, i, j);
|
||||
size_t ucount_computed = fb_ucount(fb, nbits, i, cnt);
|
||||
assert_zu_eq(ucount_expected, ucount_computed,
|
||||
"fb_ucount error with nbits=%zu, start=%zu, "
|
||||
"cnt=%zu, with bits set in [%zu, %zu)",
|
||||
nbits, i, cnt, set_start, set_end);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_test_count_contiguous(size_t nbits) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb = malloc(sz);
|
||||
|
||||
fb_init(fb, nbits);
|
||||
|
|
@ -688,7 +681,7 @@ do_test_count_contiguous(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_count_contiguous_simple) {
|
||||
enum {nbits = 300};
|
||||
enum { nbits = 300 };
|
||||
fb_group_t fb[FB_NGROUPS(nbits)];
|
||||
fb_init(fb, nbits);
|
||||
/* Just an arbitrary number. */
|
||||
|
|
@ -718,10 +711,10 @@ TEST_BEGIN(test_count_contiguous_simple) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_count_contiguous) {
|
||||
#define NB(nbits) \
|
||||
/* This test is *particularly* slow in debug builds. */ \
|
||||
if ((!config_debug && nbits < 300) || nbits < 150) { \
|
||||
do_test_count_contiguous(nbits); \
|
||||
#define NB(nbits) \
|
||||
/* This test is *particularly* slow in debug builds. */ \
|
||||
if ((!config_debug && nbits < 300) || nbits < 150) { \
|
||||
do_test_count_contiguous(nbits); \
|
||||
}
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
|
|
@ -729,15 +722,15 @@ TEST_BEGIN(test_count_contiguous) {
|
|||
TEST_END
|
||||
|
||||
static void
|
||||
expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
|
||||
size_t nbits) {
|
||||
expect_count_match_alternating(
|
||||
fb_group_t *fb_even, fb_group_t *fb_odd, size_t nbits) {
|
||||
for (size_t i = 0; i < nbits; i++) {
|
||||
for (size_t j = i + 1; j <= nbits; j++) {
|
||||
size_t cnt = j - i;
|
||||
size_t odd_scount = cnt / 2
|
||||
+ (size_t)(cnt % 2 == 1 && i % 2 == 1);
|
||||
size_t odd_scount_computed = fb_scount(fb_odd, nbits,
|
||||
i, j - i);
|
||||
size_t odd_scount_computed = fb_scount(
|
||||
fb_odd, nbits, i, j - i);
|
||||
assert_zu_eq(odd_scount, odd_scount_computed,
|
||||
"fb_scount error with nbits=%zu, start=%zu, "
|
||||
"cnt=%zu, with alternating bits set.",
|
||||
|
|
@ -745,8 +738,8 @@ expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
|
|||
|
||||
size_t odd_ucount = cnt / 2
|
||||
+ (size_t)(cnt % 2 == 1 && i % 2 == 0);
|
||||
size_t odd_ucount_computed = fb_ucount(fb_odd, nbits,
|
||||
i, j - i);
|
||||
size_t odd_ucount_computed = fb_ucount(
|
||||
fb_odd, nbits, i, j - i);
|
||||
assert_zu_eq(odd_ucount, odd_ucount_computed,
|
||||
"fb_ucount error with nbits=%zu, start=%zu, "
|
||||
"cnt=%zu, with alternating bits set.",
|
||||
|
|
@ -754,8 +747,8 @@ expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
|
|||
|
||||
size_t even_scount = cnt / 2
|
||||
+ (size_t)(cnt % 2 == 1 && i % 2 == 0);
|
||||
size_t even_scount_computed = fb_scount(fb_even, nbits,
|
||||
i, j - i);
|
||||
size_t even_scount_computed = fb_scount(
|
||||
fb_even, nbits, i, j - i);
|
||||
assert_zu_eq(even_scount, even_scount_computed,
|
||||
"fb_scount error with nbits=%zu, start=%zu, "
|
||||
"cnt=%zu, with alternating bits set.",
|
||||
|
|
@ -763,8 +756,8 @@ expect_count_match_alternating(fb_group_t *fb_even, fb_group_t *fb_odd,
|
|||
|
||||
size_t even_ucount = cnt / 2
|
||||
+ (size_t)(cnt % 2 == 1 && i % 2 == 1);
|
||||
size_t even_ucount_computed = fb_ucount(fb_even, nbits,
|
||||
i, j - i);
|
||||
size_t even_ucount_computed = fb_ucount(
|
||||
fb_even, nbits, i, j - i);
|
||||
assert_zu_eq(even_ucount, even_ucount_computed,
|
||||
"fb_ucount error with nbits=%zu, start=%zu, "
|
||||
"cnt=%zu, with alternating bits set.",
|
||||
|
|
@ -778,7 +771,7 @@ do_test_count_alternating(size_t nbits) {
|
|||
if (nbits > 1000) {
|
||||
return;
|
||||
}
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb_even = malloc(sz);
|
||||
fb_group_t *fb_odd = malloc(sz);
|
||||
|
||||
|
|
@ -800,8 +793,7 @@ do_test_count_alternating(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_count_alternating) {
|
||||
#define NB(nbits) \
|
||||
do_test_count_alternating(nbits);
|
||||
#define NB(nbits) do_test_count_alternating(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -809,8 +801,9 @@ TEST_END
|
|||
|
||||
static void
|
||||
do_test_bit_op(size_t nbits, bool (*op)(bool a, bool b),
|
||||
void (*fb_op)(fb_group_t *dst, fb_group_t *src1, fb_group_t *src2, size_t nbits)) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
void (*fb_op)(
|
||||
fb_group_t *dst, fb_group_t *src1, fb_group_t *src2, size_t nbits)) {
|
||||
size_t sz = FB_NGROUPS(nbits) * sizeof(fb_group_t);
|
||||
fb_group_t *fb1 = malloc(sz);
|
||||
fb_group_t *fb2 = malloc(sz);
|
||||
fb_group_t *fb_result = malloc(sz);
|
||||
|
|
@ -853,8 +846,10 @@ do_test_bit_op(size_t nbits, bool (*op)(bool a, bool b),
|
|||
bool bit2 = ((prng2 & (1ULL << (i % 64))) != 0);
|
||||
|
||||
/* Original bitmaps shouldn't change. */
|
||||
expect_b_eq(bit1, fb_get(fb1, nbits, i), "difference at bit %zu", i);
|
||||
expect_b_eq(bit2, fb_get(fb2, nbits, i), "difference at bit %zu", i);
|
||||
expect_b_eq(
|
||||
bit1, fb_get(fb1, nbits, i), "difference at bit %zu", i);
|
||||
expect_b_eq(
|
||||
bit2, fb_get(fb2, nbits, i), "difference at bit %zu", i);
|
||||
|
||||
/* New one should be bitwise and. */
|
||||
expect_b_eq(op(bit1, bit2), fb_get(fb_result, nbits, i),
|
||||
|
|
@ -883,8 +878,7 @@ do_test_bit_and(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_bit_and) {
|
||||
#define NB(nbits) \
|
||||
do_test_bit_and(nbits);
|
||||
#define NB(nbits) do_test_bit_and(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -901,8 +895,7 @@ do_test_bit_or(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_bit_or) {
|
||||
#define NB(nbits) \
|
||||
do_test_bit_or(nbits);
|
||||
#define NB(nbits) do_test_bit_or(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -915,8 +908,8 @@ binary_not(bool a, bool b) {
|
|||
}
|
||||
|
||||
static void
|
||||
fb_bit_not_shim(fb_group_t *dst, fb_group_t *src1, fb_group_t *src2,
|
||||
size_t nbits) {
|
||||
fb_bit_not_shim(
|
||||
fb_group_t *dst, fb_group_t *src1, fb_group_t *src2, size_t nbits) {
|
||||
(void)src2;
|
||||
fb_bit_not(dst, src1, nbits);
|
||||
}
|
||||
|
|
@ -927,8 +920,7 @@ do_test_bit_not(size_t nbits) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_bit_not) {
|
||||
#define NB(nbits) \
|
||||
do_test_bit_not(nbits);
|
||||
#define NB(nbits) do_test_bit_not(nbits);
|
||||
NBITS_TAB
|
||||
#undef NB
|
||||
}
|
||||
|
|
@ -936,19 +928,9 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_fb_init,
|
||||
test_get_set_unset,
|
||||
test_search_simple,
|
||||
test_search_exhaustive,
|
||||
test_range_simple,
|
||||
test_empty_full,
|
||||
test_iter_range_simple,
|
||||
test_iter_range_exhaustive,
|
||||
test_count_contiguous_simple,
|
||||
test_count_contiguous,
|
||||
test_count_alternating,
|
||||
test_bit_and,
|
||||
test_bit_or,
|
||||
test_bit_not);
|
||||
return test_no_reentrancy(test_fb_init, test_get_set_unset,
|
||||
test_search_simple, test_search_exhaustive, test_range_simple,
|
||||
test_empty_full, test_iter_range_simple, test_iter_range_exhaustive,
|
||||
test_count_contiguous_simple, test_count_contiguous,
|
||||
test_count_alternating, test_bit_and, test_bit_or, test_bit_not);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ TEST_BEGIN(test_fork) {
|
|||
|
||||
/* Set up a manually managed arena for test. */
|
||||
unsigned arena_ind;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0),
|
||||
0, "Unexpected mallctl() failure");
|
||||
|
||||
|
|
@ -16,8 +16,8 @@ TEST_BEGIN(test_fork) {
|
|||
unsigned old_arena_ind;
|
||||
sz = sizeof(old_arena_ind);
|
||||
expect_d_eq(mallctl("thread.arena", (void *)&old_arena_ind, &sz,
|
||||
(void *)&arena_ind, sizeof(arena_ind)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
(void *)&arena_ind, sizeof(arena_ind)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
|
||||
p = malloc(1);
|
||||
expect_ptr_not_null(p, "Unexpected malloc() failure");
|
||||
|
|
@ -108,7 +108,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_fork,
|
||||
test_fork_multithreaded);
|
||||
return test_no_reentrancy(test_fork, test_fork_multithreaded);
|
||||
}
|
||||
|
|
|
|||
138
test/unit/fxp.c
138
test/unit/fxp.c
|
|
@ -28,7 +28,7 @@ fxp_close(fxp_t a, fxp_t b) {
|
|||
static fxp_t
|
||||
xparse_fxp(const char *str) {
|
||||
fxp_t result;
|
||||
bool err = fxp_parse(&result, str, NULL);
|
||||
bool err = fxp_parse(&result, str, NULL);
|
||||
assert_false(err, "Invalid fxp string: %s", str);
|
||||
return result;
|
||||
}
|
||||
|
|
@ -36,14 +36,14 @@ xparse_fxp(const char *str) {
|
|||
static void
|
||||
expect_parse_accurate(const char *str, const char *parse_str) {
|
||||
double true_val = strtod(str, NULL);
|
||||
fxp_t fxp_val;
|
||||
char *end;
|
||||
bool err = fxp_parse(&fxp_val, parse_str, &end);
|
||||
fxp_t fxp_val;
|
||||
char *end;
|
||||
bool err = fxp_parse(&fxp_val, parse_str, &end);
|
||||
expect_false(err, "Unexpected parse failure");
|
||||
expect_ptr_eq(parse_str + strlen(str), end,
|
||||
"Didn't parse whole string");
|
||||
expect_true(double_close(fxp2double(fxp_val), true_val),
|
||||
"Misparsed %s", str);
|
||||
expect_ptr_eq(
|
||||
parse_str + strlen(str), end, "Didn't parse whole string");
|
||||
expect_true(
|
||||
double_close(fxp2double(fxp_val), true_val), "Misparsed %s", str);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -100,12 +100,12 @@ static void
|
|||
expect_parse_failure(const char *str) {
|
||||
fxp_t result = FXP_INIT_INT(333);
|
||||
char *end = (void *)0x123;
|
||||
bool err = fxp_parse(&result, str, &end);
|
||||
bool err = fxp_parse(&result, str, &end);
|
||||
expect_true(err, "Expected a parse error on: %s", str);
|
||||
expect_ptr_eq((void *)0x123, end,
|
||||
"Parse error shouldn't change results");
|
||||
expect_u32_eq(result, FXP_INIT_INT(333),
|
||||
"Parse error shouldn't change results");
|
||||
expect_ptr_eq(
|
||||
(void *)0x123, end, "Parse error shouldn't change results");
|
||||
expect_u32_eq(
|
||||
result, FXP_INIT_INT(333), "Parse error shouldn't change results");
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_parse_invalid) {
|
||||
|
|
@ -129,7 +129,6 @@ expect_init_percent(unsigned percent, const char *str) {
|
|||
"Expect representations of FXP_INIT_PERCENT(%u) and "
|
||||
"fxp_parse(\"%s\") to be equal; got %x and %x",
|
||||
percent, str, result_init, result_parse);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -145,12 +144,12 @@ TEST_BEGIN(test_init_percent) {
|
|||
TEST_END
|
||||
|
||||
static void
|
||||
expect_add(const char *astr, const char *bstr, const char* resultstr) {
|
||||
expect_add(const char *astr, const char *bstr, const char *resultstr) {
|
||||
fxp_t a = xparse_fxp(astr);
|
||||
fxp_t b = xparse_fxp(bstr);
|
||||
fxp_t result = xparse_fxp(resultstr);
|
||||
expect_true(fxp_close(fxp_add(a, b), result),
|
||||
"Expected %s + %s == %s", astr, bstr, resultstr);
|
||||
expect_true(fxp_close(fxp_add(a, b), result), "Expected %s + %s == %s",
|
||||
astr, bstr, resultstr);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_add_simple) {
|
||||
|
|
@ -164,12 +163,12 @@ TEST_BEGIN(test_add_simple) {
|
|||
TEST_END
|
||||
|
||||
static void
|
||||
expect_sub(const char *astr, const char *bstr, const char* resultstr) {
|
||||
expect_sub(const char *astr, const char *bstr, const char *resultstr) {
|
||||
fxp_t a = xparse_fxp(astr);
|
||||
fxp_t b = xparse_fxp(bstr);
|
||||
fxp_t result = xparse_fxp(resultstr);
|
||||
expect_true(fxp_close(fxp_sub(a, b), result),
|
||||
"Expected %s - %s == %s", astr, bstr, resultstr);
|
||||
expect_true(fxp_close(fxp_sub(a, b), result), "Expected %s - %s == %s",
|
||||
astr, bstr, resultstr);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_sub_simple) {
|
||||
|
|
@ -183,12 +182,12 @@ TEST_BEGIN(test_sub_simple) {
|
|||
TEST_END
|
||||
|
||||
static void
|
||||
expect_mul(const char *astr, const char *bstr, const char* resultstr) {
|
||||
expect_mul(const char *astr, const char *bstr, const char *resultstr) {
|
||||
fxp_t a = xparse_fxp(astr);
|
||||
fxp_t b = xparse_fxp(bstr);
|
||||
fxp_t result = xparse_fxp(resultstr);
|
||||
expect_true(fxp_close(fxp_mul(a, b), result),
|
||||
"Expected %s * %s == %s", astr, bstr, resultstr);
|
||||
expect_true(fxp_close(fxp_mul(a, b), result), "Expected %s * %s == %s",
|
||||
astr, bstr, resultstr);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_mul_simple) {
|
||||
|
|
@ -202,12 +201,12 @@ TEST_BEGIN(test_mul_simple) {
|
|||
TEST_END
|
||||
|
||||
static void
|
||||
expect_div(const char *astr, const char *bstr, const char* resultstr) {
|
||||
expect_div(const char *astr, const char *bstr, const char *resultstr) {
|
||||
fxp_t a = xparse_fxp(astr);
|
||||
fxp_t b = xparse_fxp(bstr);
|
||||
fxp_t result = xparse_fxp(resultstr);
|
||||
expect_true(fxp_close(fxp_div(a, b), result),
|
||||
"Expected %s / %s == %s", astr, bstr, resultstr);
|
||||
expect_true(fxp_close(fxp_div(a, b), result), "Expected %s / %s == %s",
|
||||
astr, bstr, resultstr);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_div_simple) {
|
||||
|
|
@ -223,11 +222,11 @@ TEST_END
|
|||
|
||||
static void
|
||||
expect_round(const char *str, uint32_t rounded_down, uint32_t rounded_nearest) {
|
||||
fxp_t fxp = xparse_fxp(str);
|
||||
fxp_t fxp = xparse_fxp(str);
|
||||
uint32_t fxp_rounded_down = fxp_round_down(fxp);
|
||||
uint32_t fxp_rounded_nearest = fxp_round_nearest(fxp);
|
||||
expect_u32_eq(rounded_down, fxp_rounded_down,
|
||||
"Mistake rounding %s down", str);
|
||||
expect_u32_eq(
|
||||
rounded_down, fxp_rounded_down, "Mistake rounding %s down", str);
|
||||
expect_u32_eq(rounded_nearest, fxp_rounded_nearest,
|
||||
"Mistake rounding %s to nearest", str);
|
||||
}
|
||||
|
|
@ -248,11 +247,11 @@ TEST_END
|
|||
|
||||
static void
|
||||
expect_mul_frac(size_t a, const char *fracstr, size_t expected) {
|
||||
fxp_t frac = xparse_fxp(fracstr);
|
||||
fxp_t frac = xparse_fxp(fracstr);
|
||||
size_t result = fxp_mul_frac(a, frac);
|
||||
expect_true(double_close(expected, result),
|
||||
"Expected %zu * %s == %zu (fracmul); got %zu", a, fracstr,
|
||||
expected, result);
|
||||
"Expected %zu * %s == %zu (fracmul); got %zu", a, fracstr, expected,
|
||||
result);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_mul_frac_simple) {
|
||||
|
|
@ -273,7 +272,7 @@ TEST_END
|
|||
static void
|
||||
expect_print(const char *str) {
|
||||
fxp_t fxp = xparse_fxp(str);
|
||||
char buf[FXP_BUF_SIZE];
|
||||
char buf[FXP_BUF_SIZE];
|
||||
fxp_print(fxp, buf);
|
||||
expect_d_eq(0, strcmp(str, buf), "Couldn't round-trip print %s", str);
|
||||
}
|
||||
|
|
@ -298,33 +297,32 @@ TEST_BEGIN(test_print_simple) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_stress) {
|
||||
const char *numbers[] = {
|
||||
"0.0", "0.1", "0.2", "0.3", "0.4",
|
||||
"0.5", "0.6", "0.7", "0.8", "0.9",
|
||||
const char *numbers[] = {"0.0", "0.1", "0.2", "0.3", "0.4", "0.5",
|
||||
"0.6", "0.7", "0.8", "0.9",
|
||||
|
||||
"1.0", "1.1", "1.2", "1.3", "1.4",
|
||||
"1.5", "1.6", "1.7", "1.8", "1.9",
|
||||
"1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8",
|
||||
"1.9",
|
||||
|
||||
"2.0", "2.1", "2.2", "2.3", "2.4",
|
||||
"2.5", "2.6", "2.7", "2.8", "2.9",
|
||||
"2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8",
|
||||
"2.9",
|
||||
|
||||
"17.0", "17.1", "17.2", "17.3", "17.4",
|
||||
"17.5", "17.6", "17.7", "17.8", "17.9",
|
||||
"17.0", "17.1", "17.2", "17.3", "17.4", "17.5", "17.6", "17.7",
|
||||
"17.8", "17.9",
|
||||
|
||||
"18.0", "18.1", "18.2", "18.3", "18.4",
|
||||
"18.5", "18.6", "18.7", "18.8", "18.9",
|
||||
"18.0", "18.1", "18.2", "18.3", "18.4", "18.5", "18.6", "18.7",
|
||||
"18.8", "18.9",
|
||||
|
||||
"123.0", "123.1", "123.2", "123.3", "123.4",
|
||||
"123.5", "123.6", "123.7", "123.8", "123.9",
|
||||
"123.0", "123.1", "123.2", "123.3", "123.4", "123.5", "123.6",
|
||||
"123.7", "123.8", "123.9",
|
||||
|
||||
"124.0", "124.1", "124.2", "124.3", "124.4",
|
||||
"124.5", "124.6", "124.7", "124.8", "124.9",
|
||||
"124.0", "124.1", "124.2", "124.3", "124.4", "124.5", "124.6",
|
||||
"124.7", "124.8", "124.9",
|
||||
|
||||
"125.0", "125.1", "125.2", "125.3", "125.4",
|
||||
"125.5", "125.6", "125.7", "125.8", "125.9"};
|
||||
size_t numbers_len = sizeof(numbers)/sizeof(numbers[0]);
|
||||
"125.0", "125.1", "125.2", "125.3", "125.4", "125.5", "125.6",
|
||||
"125.7", "125.8", "125.9"};
|
||||
size_t numbers_len = sizeof(numbers) / sizeof(numbers[0]);
|
||||
for (size_t i = 0; i < numbers_len; i++) {
|
||||
fxp_t fxp_a = xparse_fxp(numbers[i]);
|
||||
fxp_t fxp_a = xparse_fxp(numbers[i]);
|
||||
double double_a = strtod(numbers[i], NULL);
|
||||
|
||||
uint32_t fxp_rounded_down = fxp_round_down(fxp_a);
|
||||
|
|
@ -338,37 +336,35 @@ TEST_BEGIN(test_stress) {
|
|||
"Incorrectly rounded-to-nearest %s", numbers[i]);
|
||||
|
||||
for (size_t j = 0; j < numbers_len; j++) {
|
||||
fxp_t fxp_b = xparse_fxp(numbers[j]);
|
||||
fxp_t fxp_b = xparse_fxp(numbers[j]);
|
||||
double double_b = strtod(numbers[j], NULL);
|
||||
|
||||
fxp_t fxp_sum = fxp_add(fxp_a, fxp_b);
|
||||
fxp_t fxp_sum = fxp_add(fxp_a, fxp_b);
|
||||
double double_sum = double_a + double_b;
|
||||
expect_true(
|
||||
double_close(fxp2double(fxp_sum), double_sum),
|
||||
"Miscomputed %s + %s", numbers[i], numbers[j]);
|
||||
|
||||
if (double_a > double_b) {
|
||||
fxp_t fxp_diff = fxp_sub(fxp_a, fxp_b);
|
||||
fxp_t fxp_diff = fxp_sub(fxp_a, fxp_b);
|
||||
double double_diff = double_a - double_b;
|
||||
expect_true(
|
||||
double_close(fxp2double(fxp_diff),
|
||||
double_diff),
|
||||
expect_true(double_close(fxp2double(fxp_diff),
|
||||
double_diff),
|
||||
"Miscomputed %s - %s", numbers[i],
|
||||
numbers[j]);
|
||||
}
|
||||
|
||||
fxp_t fxp_prod = fxp_mul(fxp_a, fxp_b);
|
||||
fxp_t fxp_prod = fxp_mul(fxp_a, fxp_b);
|
||||
double double_prod = double_a * double_b;
|
||||
expect_true(
|
||||
double_close(fxp2double(fxp_prod), double_prod),
|
||||
"Miscomputed %s * %s", numbers[i], numbers[j]);
|
||||
|
||||
if (double_b != 0.0) {
|
||||
fxp_t fxp_quot = fxp_div(fxp_a, fxp_b);
|
||||
fxp_t fxp_quot = fxp_div(fxp_a, fxp_b);
|
||||
double double_quot = double_a / double_b;
|
||||
expect_true(
|
||||
double_close(fxp2double(fxp_quot),
|
||||
double_quot),
|
||||
expect_true(double_close(fxp2double(fxp_quot),
|
||||
double_quot),
|
||||
"Miscomputed %s / %s", numbers[i],
|
||||
numbers[j]);
|
||||
}
|
||||
|
|
@ -379,16 +375,8 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_parse_valid,
|
||||
test_parse_invalid,
|
||||
test_init_percent,
|
||||
test_add_simple,
|
||||
test_sub_simple,
|
||||
test_mul_simple,
|
||||
test_div_simple,
|
||||
test_round_simple,
|
||||
test_mul_frac_simple,
|
||||
test_print_simple,
|
||||
test_stress);
|
||||
return test_no_reentrancy(test_parse_valid, test_parse_invalid,
|
||||
test_init_percent, test_add_simple, test_sub_simple,
|
||||
test_mul_simple, test_div_simple, test_round_simple,
|
||||
test_mul_frac_simple, test_print_simple, test_stress);
|
||||
}
|
||||
|
|
|
|||
101
test/unit/hash.c
101
test/unit/hash.c
|
|
@ -39,24 +39,32 @@ typedef enum {
|
|||
static int
|
||||
hash_variant_bits(hash_variant_t variant) {
|
||||
switch (variant) {
|
||||
case hash_variant_x86_32: return 32;
|
||||
case hash_variant_x86_128: return 128;
|
||||
case hash_variant_x64_128: return 128;
|
||||
default: not_reached();
|
||||
case hash_variant_x86_32:
|
||||
return 32;
|
||||
case hash_variant_x86_128:
|
||||
return 128;
|
||||
case hash_variant_x64_128:
|
||||
return 128;
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
hash_variant_string(hash_variant_t variant) {
|
||||
switch (variant) {
|
||||
case hash_variant_x86_32: return "hash_x86_32";
|
||||
case hash_variant_x86_128: return "hash_x86_128";
|
||||
case hash_variant_x64_128: return "hash_x64_128";
|
||||
default: not_reached();
|
||||
case hash_variant_x86_32:
|
||||
return "hash_x86_32";
|
||||
case hash_variant_x86_128:
|
||||
return "hash_x86_128";
|
||||
case hash_variant_x64_128:
|
||||
return "hash_x64_128";
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
#define KEY_SIZE 256
|
||||
#define KEY_SIZE 256
|
||||
static void
|
||||
hash_variant_verify_key(hash_variant_t variant, uint8_t *key) {
|
||||
const int hashbytes = hash_variant_bits(variant) / 8;
|
||||
|
|
@ -79,20 +87,24 @@ hash_variant_verify_key(hash_variant_t variant, uint8_t *key) {
|
|||
switch (variant) {
|
||||
case hash_variant_x86_32: {
|
||||
uint32_t out;
|
||||
out = hash_x86_32(key, i, 256-i);
|
||||
memcpy(&hashes[i*hashbytes], &out, hashbytes);
|
||||
out = hash_x86_32(key, i, 256 - i);
|
||||
memcpy(&hashes[i * hashbytes], &out, hashbytes);
|
||||
break;
|
||||
} case hash_variant_x86_128: {
|
||||
}
|
||||
case hash_variant_x86_128: {
|
||||
uint64_t out[2];
|
||||
hash_x86_128(key, i, 256-i, out);
|
||||
memcpy(&hashes[i*hashbytes], out, hashbytes);
|
||||
hash_x86_128(key, i, 256 - i, out);
|
||||
memcpy(&hashes[i * hashbytes], out, hashbytes);
|
||||
break;
|
||||
} case hash_variant_x64_128: {
|
||||
}
|
||||
case hash_variant_x64_128: {
|
||||
uint64_t out[2];
|
||||
hash_x64_128(key, i, 256-i, out);
|
||||
memcpy(&hashes[i*hashbytes], out, hashbytes);
|
||||
hash_x64_128(key, i, 256 - i, out);
|
||||
memcpy(&hashes[i * hashbytes], out, hashbytes);
|
||||
break;
|
||||
} default: not_reached();
|
||||
}
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,36 +114,50 @@ hash_variant_verify_key(hash_variant_t variant, uint8_t *key) {
|
|||
uint32_t out = hash_x86_32(hashes, hashes_size, 0);
|
||||
memcpy(final, &out, sizeof(out));
|
||||
break;
|
||||
} case hash_variant_x86_128: {
|
||||
}
|
||||
case hash_variant_x86_128: {
|
||||
uint64_t out[2];
|
||||
hash_x86_128(hashes, hashes_size, 0, out);
|
||||
memcpy(final, out, sizeof(out));
|
||||
break;
|
||||
} case hash_variant_x64_128: {
|
||||
}
|
||||
case hash_variant_x64_128: {
|
||||
uint64_t out[2];
|
||||
hash_x64_128(hashes, hashes_size, 0, out);
|
||||
memcpy(final, out, sizeof(out));
|
||||
break;
|
||||
} default: not_reached();
|
||||
}
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
|
||||
computed =
|
||||
((uint32_t)final[0] << 0) |
|
||||
((uint32_t)final[1] << 8) |
|
||||
((uint32_t)final[2] << 16) |
|
||||
((uint32_t)final[3] << 24);
|
||||
computed = ((uint32_t) final[0] << 0) | ((uint32_t) final[1] << 8)
|
||||
| ((uint32_t) final[2] << 16) | ((uint32_t) final[3] << 24);
|
||||
|
||||
switch (variant) {
|
||||
#ifdef JEMALLOC_BIG_ENDIAN
|
||||
case hash_variant_x86_32: expected = 0x6213303eU; break;
|
||||
case hash_variant_x86_128: expected = 0x266820caU; break;
|
||||
case hash_variant_x64_128: expected = 0xcc622b6fU; break;
|
||||
case hash_variant_x86_32:
|
||||
expected = 0x6213303eU;
|
||||
break;
|
||||
case hash_variant_x86_128:
|
||||
expected = 0x266820caU;
|
||||
break;
|
||||
case hash_variant_x64_128:
|
||||
expected = 0xcc622b6fU;
|
||||
break;
|
||||
#else
|
||||
case hash_variant_x86_32: expected = 0xb0f57ee3U; break;
|
||||
case hash_variant_x86_128: expected = 0xb3ece62aU; break;
|
||||
case hash_variant_x64_128: expected = 0x6384ba69U; break;
|
||||
case hash_variant_x86_32:
|
||||
expected = 0xb0f57ee3U;
|
||||
break;
|
||||
case hash_variant_x86_128:
|
||||
expected = 0xb3ece62aU;
|
||||
break;
|
||||
case hash_variant_x64_128:
|
||||
expected = 0x6384ba69U;
|
||||
break;
|
||||
#endif
|
||||
default: not_reached();
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
|
||||
expect_u32_eq(computed, expected,
|
||||
|
|
@ -141,8 +167,8 @@ hash_variant_verify_key(hash_variant_t variant, uint8_t *key) {
|
|||
|
||||
static void
|
||||
hash_variant_verify(hash_variant_t variant) {
|
||||
#define MAX_ALIGN 16
|
||||
uint8_t key[KEY_SIZE + (MAX_ALIGN - 1)];
|
||||
#define MAX_ALIGN 16
|
||||
uint8_t key[KEY_SIZE + (MAX_ALIGN - 1)];
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < MAX_ALIGN; i++) {
|
||||
|
|
@ -169,8 +195,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_hash_x86_32,
|
||||
test_hash_x86_128,
|
||||
test_hash_x64_128);
|
||||
return test(test_hash_x86_32, test_hash_x86_128, test_hash_x64_128);
|
||||
}
|
||||
|
|
|
|||
177
test/unit/hook.c
177
test/unit/hook.c
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
#include "jemalloc/internal/hook.h"
|
||||
|
||||
static void *arg_extra;
|
||||
static int arg_type;
|
||||
static void *arg_result;
|
||||
static void *arg_address;
|
||||
static size_t arg_old_usize;
|
||||
static size_t arg_new_usize;
|
||||
static void *arg_extra;
|
||||
static int arg_type;
|
||||
static void *arg_result;
|
||||
static void *arg_address;
|
||||
static size_t arg_old_usize;
|
||||
static size_t arg_new_usize;
|
||||
static uintptr_t arg_result_raw;
|
||||
static uintptr_t arg_args_raw[4];
|
||||
|
||||
|
|
@ -71,8 +71,8 @@ set_args_raw(uintptr_t *args_raw, int nargs) {
|
|||
|
||||
static void
|
||||
expect_args_raw(uintptr_t *args_raw_expected, int nargs) {
|
||||
int cmp = memcmp(args_raw_expected, arg_args_raw,
|
||||
sizeof(uintptr_t) * nargs);
|
||||
int cmp = memcmp(
|
||||
args_raw_expected, arg_args_raw, sizeof(uintptr_t) * nargs);
|
||||
expect_d_eq(cmp, 0, "Raw args mismatch");
|
||||
}
|
||||
|
||||
|
|
@ -95,8 +95,8 @@ test_alloc_hook(void *extra, hook_alloc_t type, void *result,
|
|||
}
|
||||
|
||||
static void
|
||||
test_dalloc_hook(void *extra, hook_dalloc_t type, void *address,
|
||||
uintptr_t args_raw[3]) {
|
||||
test_dalloc_hook(
|
||||
void *extra, hook_dalloc_t type, void *address, uintptr_t args_raw[3]) {
|
||||
call_count++;
|
||||
arg_extra = extra;
|
||||
arg_type = (int)type;
|
||||
|
|
@ -122,16 +122,15 @@ test_expand_hook(void *extra, hook_expand_t type, void *address,
|
|||
|
||||
TEST_BEGIN(test_hooks_basic) {
|
||||
/* Just verify that the record their arguments correctly. */
|
||||
hooks_t hooks = {
|
||||
&test_alloc_hook, &test_dalloc_hook, &test_expand_hook,
|
||||
(void *)111};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook, &test_expand_hook,
|
||||
(void *)111};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
uintptr_t args_raw[4] = {10, 20, 30, 40};
|
||||
|
||||
/* Alloc */
|
||||
reset_args();
|
||||
hook_invoke_alloc(hook_alloc_posix_memalign, (void *)222, 333,
|
||||
args_raw);
|
||||
hook_invoke_alloc(
|
||||
hook_alloc_posix_memalign, (void *)222, 333, args_raw);
|
||||
expect_ptr_eq(arg_extra, (void *)111, "Passed wrong user pointer");
|
||||
expect_d_eq((int)hook_alloc_posix_memalign, arg_type,
|
||||
"Passed wrong alloc type");
|
||||
|
|
@ -142,18 +141,18 @@ TEST_BEGIN(test_hooks_basic) {
|
|||
/* Dalloc */
|
||||
reset_args();
|
||||
hook_invoke_dalloc(hook_dalloc_sdallocx, (void *)222, args_raw);
|
||||
expect_d_eq((int)hook_dalloc_sdallocx, arg_type,
|
||||
"Passed wrong dalloc type");
|
||||
expect_d_eq(
|
||||
(int)hook_dalloc_sdallocx, arg_type, "Passed wrong dalloc type");
|
||||
expect_ptr_eq((void *)111, arg_extra, "Passed wrong user pointer");
|
||||
expect_ptr_eq((void *)222, arg_address, "Passed wrong address");
|
||||
expect_args_raw(args_raw, 3);
|
||||
|
||||
/* Expand */
|
||||
reset_args();
|
||||
hook_invoke_expand(hook_expand_xallocx, (void *)222, 333, 444, 555,
|
||||
args_raw);
|
||||
expect_d_eq((int)hook_expand_xallocx, arg_type,
|
||||
"Passed wrong expand type");
|
||||
hook_invoke_expand(
|
||||
hook_expand_xallocx, (void *)222, 333, 444, 555, args_raw);
|
||||
expect_d_eq(
|
||||
(int)hook_expand_xallocx, arg_type, "Passed wrong expand type");
|
||||
expect_ptr_eq((void *)111, arg_extra, "Passed wrong user pointer");
|
||||
expect_ptr_eq((void *)222, arg_address, "Passed wrong address");
|
||||
expect_zu_eq(333, arg_old_usize, "Passed wrong old usize");
|
||||
|
|
@ -205,7 +204,7 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(test_hooks_remove) {
|
||||
hooks_t hooks = {&test_alloc_hook, NULL, NULL, NULL};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
expect_ptr_ne(handle, NULL, "Hook installation failed");
|
||||
call_count = 0;
|
||||
uintptr_t args_raw[4] = {10, 20, 30, 40};
|
||||
|
|
@ -216,14 +215,13 @@ TEST_BEGIN(test_hooks_remove) {
|
|||
hook_remove(TSDN_NULL, handle);
|
||||
hook_invoke_alloc(hook_alloc_malloc, NULL, 0, NULL);
|
||||
expect_d_eq(call_count, 0, "Hook invoked after removal");
|
||||
|
||||
}
|
||||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_hooks_alloc_simple) {
|
||||
/* "Simple" in the sense that we're not in a realloc variant. */
|
||||
hooks_t hooks = {&test_alloc_hook, NULL, NULL, (void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
expect_ptr_ne(handle, NULL, "Hook installation failed");
|
||||
|
||||
/* Stop malloc from being optimized away. */
|
||||
|
|
@ -237,8 +235,8 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_malloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[0], "Wrong argument");
|
||||
free(ptr);
|
||||
|
||||
|
|
@ -247,11 +245,11 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
err = posix_memalign((void **)&ptr, 1024, 1);
|
||||
expect_d_eq(call_count, 1, "Hook not called");
|
||||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_posix_memalign,
|
||||
"Wrong hook type");
|
||||
expect_d_eq(
|
||||
arg_type, (int)hook_alloc_posix_memalign, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)err, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)err, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)&ptr, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)1024, arg_args_raw[1], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[2], "Wrong argument");
|
||||
|
|
@ -262,11 +260,10 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
ptr = aligned_alloc(1024, 1);
|
||||
expect_d_eq(call_count, 1, "Hook not called");
|
||||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_aligned_alloc,
|
||||
"Wrong hook type");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_aligned_alloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)1024, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
|
@ -278,8 +275,8 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_calloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)11, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)13, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
|
@ -292,8 +289,8 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_memalign, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)1024, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
|
@ -307,8 +304,8 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_valloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[0], "Wrong argument");
|
||||
free(ptr);
|
||||
#endif /* JEMALLOC_OVERRIDE_VALLOC */
|
||||
|
|
@ -321,8 +318,8 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_pvalloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[0], "Wrong argument");
|
||||
free(ptr);
|
||||
#endif /* JEMALLOC_OVERRIDE_PVALLOC */
|
||||
|
|
@ -334,11 +331,11 @@ TEST_BEGIN(test_hooks_alloc_simple) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_mallocx, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)MALLOCX_LG_ALIGN(10), arg_args_raw[1],
|
||||
"Wrong flags");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)MALLOCX_LG_ALIGN(10), arg_args_raw[1], "Wrong flags");
|
||||
free(ptr);
|
||||
|
||||
hook_remove(TSDN_NULL, handle);
|
||||
|
|
@ -348,7 +345,7 @@ TEST_END
|
|||
TEST_BEGIN(test_hooks_dalloc_simple) {
|
||||
/* "Simple" in the sense that we're not in a realloc variant. */
|
||||
hooks_t hooks = {NULL, &test_dalloc_hook, NULL, (void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
expect_ptr_ne(handle, NULL, "Hook installation failed");
|
||||
|
||||
void *volatile ptr;
|
||||
|
|
@ -372,8 +369,8 @@ TEST_BEGIN(test_hooks_dalloc_simple) {
|
|||
expect_d_eq(arg_type, (int)hook_dalloc_dallocx, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_address, "Wrong pointer freed");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0], "Wrong raw arg");
|
||||
expect_u64_eq((uintptr_t)MALLOCX_TCACHE_NONE, arg_args_raw[1],
|
||||
"Wrong raw arg");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)MALLOCX_TCACHE_NONE, arg_args_raw[1], "Wrong raw arg");
|
||||
|
||||
/* sdallocx() */
|
||||
reset();
|
||||
|
|
@ -385,8 +382,8 @@ TEST_BEGIN(test_hooks_dalloc_simple) {
|
|||
expect_ptr_eq(ptr, arg_address, "Wrong pointer freed");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0], "Wrong raw arg");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[1], "Wrong raw arg");
|
||||
expect_u64_eq((uintptr_t)MALLOCX_TCACHE_NONE, arg_args_raw[2],
|
||||
"Wrong raw arg");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)MALLOCX_TCACHE_NONE, arg_args_raw[2], "Wrong raw arg");
|
||||
|
||||
hook_remove(TSDN_NULL, handle);
|
||||
}
|
||||
|
|
@ -395,7 +392,7 @@ TEST_END
|
|||
TEST_BEGIN(test_hooks_expand_simple) {
|
||||
/* "Simple" in the sense that we're not in a realloc variant. */
|
||||
hooks_t hooks = {NULL, NULL, &test_expand_hook, (void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
expect_ptr_ne(handle, NULL, "Hook installation failed");
|
||||
|
||||
void *volatile ptr;
|
||||
|
|
@ -421,9 +418,9 @@ TEST_BEGIN(test_hooks_expand_simple) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_hooks_realloc_as_malloc_or_free) {
|
||||
hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook,
|
||||
&test_expand_hook, (void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook, &test_expand_hook,
|
||||
(void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
expect_ptr_ne(handle, NULL, "Hook installation failed");
|
||||
|
||||
void *volatile ptr;
|
||||
|
|
@ -435,8 +432,8 @@ TEST_BEGIN(test_hooks_realloc_as_malloc_or_free) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_realloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)NULL, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)1, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
|
@ -448,14 +445,11 @@ TEST_BEGIN(test_hooks_realloc_as_malloc_or_free) {
|
|||
realloc(ptr, 0);
|
||||
expect_d_eq(call_count, 1, "Hook not called");
|
||||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_dalloc_realloc,
|
||||
"Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_address,
|
||||
"Wrong pointer freed");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0],
|
||||
"Wrong raw arg");
|
||||
expect_u64_eq((uintptr_t)0, arg_args_raw[1],
|
||||
"Wrong raw arg");
|
||||
expect_d_eq(
|
||||
arg_type, (int)hook_dalloc_realloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_address, "Wrong pointer freed");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0], "Wrong raw arg");
|
||||
expect_u64_eq((uintptr_t)0, arg_args_raw[1], "Wrong raw arg");
|
||||
}
|
||||
|
||||
/* realloc(NULL, 0) as malloc(0) */
|
||||
|
|
@ -465,8 +459,8 @@ TEST_BEGIN(test_hooks_realloc_as_malloc_or_free) {
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, (int)hook_alloc_realloc, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_result, "Wrong result");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)NULL, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)0, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
|
@ -478,9 +472,9 @@ TEST_END
|
|||
static void
|
||||
do_realloc_test(void *(*ralloc)(void *, size_t, int), int flags,
|
||||
int expand_type, int dalloc_type) {
|
||||
hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook,
|
||||
&test_expand_hook, (void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
hooks_t hooks = {&test_alloc_hook, &test_dalloc_hook, &test_expand_hook,
|
||||
(void *)123};
|
||||
void *handle = hook_install(TSDN_NULL, &hooks);
|
||||
expect_ptr_ne(handle, NULL, "Hook installation failed");
|
||||
|
||||
void *volatile ptr;
|
||||
|
|
@ -496,8 +490,8 @@ do_realloc_test(void *(*ralloc)(void *, size_t, int), int flags,
|
|||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_d_eq(arg_type, expand_type, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_address, "Wrong address");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)130, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
|
@ -522,11 +516,11 @@ do_realloc_test(void *(*ralloc)(void *, size_t, int), int flags,
|
|||
}
|
||||
expect_ptr_eq(arg_extra, (void *)123, "Wrong extra");
|
||||
expect_ptr_eq(ptr2, arg_address, "Wrong address");
|
||||
expect_u64_eq((uintptr_t)ptr, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)ptr2, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)2 * 1024 * 1024, arg_args_raw[1],
|
||||
"Wrong argument");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)2 * 1024 * 1024, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr);
|
||||
|
||||
/* Realloc with move, small. */
|
||||
|
|
@ -540,8 +534,8 @@ do_realloc_test(void *(*ralloc)(void *, size_t, int), int flags,
|
|||
expect_d_eq(arg_type, dalloc_type, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_address, "Wrong address");
|
||||
expect_ptr_eq(ptr2, arg_result, "Wrong address");
|
||||
expect_u64_eq((uintptr_t)ptr2, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr2, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)128, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr2);
|
||||
|
|
@ -557,11 +551,11 @@ do_realloc_test(void *(*ralloc)(void *, size_t, int), int flags,
|
|||
expect_d_eq(arg_type, dalloc_type, "Wrong hook type");
|
||||
expect_ptr_eq(ptr, arg_address, "Wrong address");
|
||||
expect_ptr_eq(ptr2, arg_result, "Wrong address");
|
||||
expect_u64_eq((uintptr_t)ptr2, (uintptr_t)arg_result_raw,
|
||||
"Wrong raw result");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)ptr2, (uintptr_t)arg_result_raw, "Wrong raw result");
|
||||
expect_u64_eq((uintptr_t)ptr, arg_args_raw[0], "Wrong argument");
|
||||
expect_u64_eq((uintptr_t)2 * 1024 * 1024, arg_args_raw[1],
|
||||
"Wrong argument");
|
||||
expect_u64_eq(
|
||||
(uintptr_t)2 * 1024 * 1024, arg_args_raw[1], "Wrong argument");
|
||||
free(ptr2);
|
||||
|
||||
hook_remove(TSDN_NULL, handle);
|
||||
|
|
@ -573,8 +567,8 @@ realloc_wrapper(void *ptr, size_t size, UNUSED int flags) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_hooks_realloc) {
|
||||
do_realloc_test(&realloc_wrapper, 0, hook_expand_realloc,
|
||||
hook_dalloc_realloc);
|
||||
do_realloc_test(
|
||||
&realloc_wrapper, 0, hook_expand_realloc, hook_dalloc_realloc);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
|
|
@ -587,14 +581,9 @@ TEST_END
|
|||
int
|
||||
main(void) {
|
||||
/* We assert on call counts. */
|
||||
return test_no_reentrancy(
|
||||
test_hooks_basic,
|
||||
test_hooks_null,
|
||||
test_hooks_remove,
|
||||
test_hooks_alloc_simple,
|
||||
test_hooks_dalloc_simple,
|
||||
test_hooks_expand_simple,
|
||||
test_hooks_realloc_as_malloc_or_free,
|
||||
test_hooks_realloc,
|
||||
return test_no_reentrancy(test_hooks_basic, test_hooks_null,
|
||||
test_hooks_remove, test_hooks_alloc_simple,
|
||||
test_hooks_dalloc_simple, test_hooks_expand_simple,
|
||||
test_hooks_realloc_as_malloc_or_free, test_hooks_realloc,
|
||||
test_hooks_rallocx);
|
||||
}
|
||||
|
|
|
|||
211
test/unit/hpa.c
211
test/unit/hpa.c
|
|
@ -13,55 +13,53 @@ struct test_data_s {
|
|||
* Must be the first member -- we convert back and forth between the
|
||||
* test_data_t and the hpa_shard_t;
|
||||
*/
|
||||
hpa_shard_t shard;
|
||||
hpa_shard_t shard;
|
||||
hpa_central_t central;
|
||||
base_t *base;
|
||||
base_t *base;
|
||||
edata_cache_t shard_edata_cache;
|
||||
|
||||
emap_t emap;
|
||||
};
|
||||
|
||||
static hpa_shard_opts_t test_hpa_shard_opts_default = {
|
||||
/* slab_max_alloc */
|
||||
ALLOC_MAX,
|
||||
/* hugification_threshold */
|
||||
HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(25),
|
||||
/* deferral_allowed */
|
||||
false,
|
||||
/* hugify_delay_ms */
|
||||
10 * 1000,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1
|
||||
};
|
||||
/* slab_max_alloc */
|
||||
ALLOC_MAX,
|
||||
/* hugification_threshold */
|
||||
HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(25),
|
||||
/* deferral_allowed */
|
||||
false,
|
||||
/* hugify_delay_ms */
|
||||
10 * 1000,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1};
|
||||
|
||||
static hpa_shard_opts_t test_hpa_shard_opts_purge = {
|
||||
/* slab_max_alloc */
|
||||
HUGEPAGE,
|
||||
/* hugification_threshold */
|
||||
0.9 * HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(11),
|
||||
/* deferral_allowed */
|
||||
true,
|
||||
/* hugify_delay_ms */
|
||||
0,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1
|
||||
};
|
||||
/* slab_max_alloc */
|
||||
HUGEPAGE,
|
||||
/* hugification_threshold */
|
||||
0.9 * HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(11),
|
||||
/* deferral_allowed */
|
||||
true,
|
||||
/* hugify_delay_ms */
|
||||
0,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1};
|
||||
|
||||
static hpa_shard_t *
|
||||
create_test_data(const hpa_hooks_t *hooks, hpa_shard_opts_t *opts) {
|
||||
bool err;
|
||||
bool err;
|
||||
base_t *base = base_new(TSDN_NULL, /* ind */ SHARD_IND,
|
||||
&ehooks_default_extent_hooks, /* metadata_use_hooks */ true);
|
||||
assert_ptr_not_null(base, "");
|
||||
|
|
@ -98,8 +96,8 @@ destroy_test_data(hpa_shard_t *shard) {
|
|||
TEST_BEGIN(test_alloc_max) {
|
||||
test_skip_if(!hpa_supported());
|
||||
|
||||
hpa_shard_t *shard = create_test_data(&hpa_hooks_default,
|
||||
&test_hpa_shard_opts_default);
|
||||
hpa_shard_t *shard = create_test_data(
|
||||
&hpa_hooks_default, &test_hpa_shard_opts_default);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
edata_t *edata;
|
||||
|
|
@ -107,19 +105,19 @@ TEST_BEGIN(test_alloc_max) {
|
|||
/* Small max */
|
||||
bool deferred_work_generated = false;
|
||||
edata = pai_alloc(tsdn, &shard->pai, ALLOC_MAX, PAGE, false, false,
|
||||
/* frequent_reuse */ false, &deferred_work_generated);
|
||||
/* frequent_reuse */ false, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Allocation of small max failed");
|
||||
|
||||
edata = pai_alloc(tsdn, &shard->pai, ALLOC_MAX + PAGE, PAGE, false,
|
||||
false, /* frequent_reuse */ false, &deferred_work_generated);
|
||||
expect_ptr_null(edata, "Allocation of larger than small max succeeded");
|
||||
|
||||
edata = pai_alloc(tsdn, &shard->pai, ALLOC_MAX, PAGE, false,
|
||||
false, /* frequent_reuse */ true, &deferred_work_generated);
|
||||
edata = pai_alloc(tsdn, &shard->pai, ALLOC_MAX, PAGE, false, false,
|
||||
/* frequent_reuse */ true, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Allocation of frequent reused failed");
|
||||
|
||||
edata = pai_alloc(tsdn, &shard->pai, HUGEPAGE, PAGE, false,
|
||||
false, /* frequent_reuse */ true, &deferred_work_generated);
|
||||
edata = pai_alloc(tsdn, &shard->pai, HUGEPAGE, PAGE, false, false,
|
||||
/* frequent_reuse */ true, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Allocation of frequent reused failed");
|
||||
|
||||
edata = pai_alloc(tsdn, &shard->pai, HUGEPAGE + PAGE, PAGE, false,
|
||||
|
|
@ -133,8 +131,8 @@ TEST_END
|
|||
typedef struct mem_contents_s mem_contents_t;
|
||||
struct mem_contents_s {
|
||||
uintptr_t my_addr;
|
||||
size_t size;
|
||||
edata_t *my_edata;
|
||||
size_t size;
|
||||
edata_t *my_edata;
|
||||
rb_node(mem_contents_t) link;
|
||||
};
|
||||
|
||||
|
|
@ -144,8 +142,7 @@ mem_contents_cmp(const mem_contents_t *a, const mem_contents_t *b) {
|
|||
}
|
||||
|
||||
typedef rb_tree(mem_contents_t) mem_tree_t;
|
||||
rb_gen(static, mem_tree_, mem_tree_t, mem_contents_t, link,
|
||||
mem_contents_cmp);
|
||||
rb_gen(static, mem_tree_, mem_tree_t, mem_contents_t, link, mem_contents_cmp);
|
||||
|
||||
static void
|
||||
node_assert_ordered(mem_contents_t *a, mem_contents_t *b) {
|
||||
|
|
@ -191,14 +188,14 @@ node_remove(mem_tree_t *tree, edata_t *edata) {
|
|||
TEST_BEGIN(test_stress) {
|
||||
test_skip_if(!hpa_supported());
|
||||
|
||||
hpa_shard_t *shard = create_test_data(&hpa_hooks_default,
|
||||
&test_hpa_shard_opts_default);
|
||||
hpa_shard_t *shard = create_test_data(
|
||||
&hpa_hooks_default, &test_hpa_shard_opts_default);
|
||||
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
const size_t nlive_edatas_max = 500;
|
||||
size_t nlive_edatas = 0;
|
||||
edata_t **live_edatas = calloc(nlive_edatas_max, sizeof(edata_t *));
|
||||
size_t nlive_edatas = 0;
|
||||
edata_t **live_edatas = calloc(nlive_edatas_max, sizeof(edata_t *));
|
||||
/*
|
||||
* Nothing special about this constant; we're only fixing it for
|
||||
* consistency across runs.
|
||||
|
|
@ -224,13 +221,14 @@ TEST_BEGIN(test_stress) {
|
|||
*/
|
||||
size_t npages_min = 1;
|
||||
size_t npages_max = ALLOC_MAX / PAGE;
|
||||
size_t npages = npages_min + prng_range_zu(&prng_state,
|
||||
npages_max - npages_min);
|
||||
size_t npages = npages_min
|
||||
+ prng_range_zu(
|
||||
&prng_state, npages_max - npages_min);
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai,
|
||||
npages * PAGE, PAGE, false, false, false,
|
||||
&deferred_work_generated);
|
||||
assert_ptr_not_null(edata,
|
||||
"Unexpected allocation failure");
|
||||
assert_ptr_not_null(
|
||||
edata, "Unexpected allocation failure");
|
||||
live_edatas[nlive_edatas] = edata;
|
||||
nlive_edatas++;
|
||||
node_insert(&tree, edata, npages);
|
||||
|
|
@ -239,7 +237,8 @@ TEST_BEGIN(test_stress) {
|
|||
if (nlive_edatas == 0) {
|
||||
continue;
|
||||
}
|
||||
size_t victim = prng_range_zu(&prng_state, nlive_edatas);
|
||||
size_t victim = prng_range_zu(
|
||||
&prng_state, nlive_edatas);
|
||||
edata_t *to_free = live_edatas[victim];
|
||||
live_edatas[victim] = live_edatas[nlive_edatas - 1];
|
||||
nlive_edatas--;
|
||||
|
|
@ -251,7 +250,7 @@ TEST_BEGIN(test_stress) {
|
|||
|
||||
size_t ntreenodes = 0;
|
||||
for (mem_contents_t *contents = mem_tree_first(&tree); contents != NULL;
|
||||
contents = mem_tree_next(&tree, contents)) {
|
||||
contents = mem_tree_next(&tree, contents)) {
|
||||
ntreenodes++;
|
||||
node_check(&tree, contents);
|
||||
}
|
||||
|
|
@ -264,8 +263,8 @@ TEST_BEGIN(test_stress) {
|
|||
for (size_t i = 0; i < nlive_edatas; i++) {
|
||||
edata_t *to_free = live_edatas[i];
|
||||
node_remove(&tree, to_free);
|
||||
pai_dalloc(tsdn, &shard->pai, to_free,
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(
|
||||
tsdn, &shard->pai, to_free, &deferred_work_generated);
|
||||
}
|
||||
hpa_shard_destroy(tsdn, shard);
|
||||
|
||||
|
|
@ -277,8 +276,7 @@ TEST_END
|
|||
static void
|
||||
expect_contiguous(edata_t **edatas, size_t nedatas) {
|
||||
for (size_t i = 0; i < nedatas; i++) {
|
||||
size_t expected = (size_t)edata_base_get(edatas[0])
|
||||
+ i * PAGE;
|
||||
size_t expected = (size_t)edata_base_get(edatas[0]) + i * PAGE;
|
||||
expect_zu_eq(expected, (size_t)edata_base_get(edatas[i]),
|
||||
"Mismatch at index %zu", i);
|
||||
}
|
||||
|
|
@ -287,13 +285,13 @@ expect_contiguous(edata_t **edatas, size_t nedatas) {
|
|||
TEST_BEGIN(test_alloc_dalloc_batch) {
|
||||
test_skip_if(!hpa_supported());
|
||||
|
||||
hpa_shard_t *shard = create_test_data(&hpa_hooks_default,
|
||||
&test_hpa_shard_opts_default);
|
||||
hpa_shard_t *shard = create_test_data(
|
||||
&hpa_hooks_default, &test_hpa_shard_opts_default);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
bool deferred_work_generated = false;
|
||||
|
||||
enum {NALLOCS = 8};
|
||||
enum { NALLOCS = 8 };
|
||||
|
||||
edata_t *allocs[NALLOCS];
|
||||
/*
|
||||
|
|
@ -329,11 +327,11 @@ TEST_BEGIN(test_alloc_dalloc_batch) {
|
|||
for (size_t i = 0; i < NALLOCS / 2; i++) {
|
||||
edata_list_active_append(&allocs_list, allocs[i]);
|
||||
}
|
||||
pai_dalloc_batch(tsdn, &shard->pai, &allocs_list,
|
||||
&deferred_work_generated);
|
||||
pai_dalloc_batch(
|
||||
tsdn, &shard->pai, &allocs_list, &deferred_work_generated);
|
||||
for (size_t i = NALLOCS / 2; i < NALLOCS; i++) {
|
||||
pai_dalloc(tsdn, &shard->pai, allocs[i],
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(
|
||||
tsdn, &shard->pai, allocs[i], &deferred_work_generated);
|
||||
}
|
||||
|
||||
/* Reallocate (individually), and ensure reuse and contiguity. */
|
||||
|
|
@ -344,8 +342,8 @@ TEST_BEGIN(test_alloc_dalloc_batch) {
|
|||
expect_ptr_not_null(allocs[i], "Unexpected alloc failure.");
|
||||
}
|
||||
void *new_base = edata_base_get(allocs[0]);
|
||||
expect_ptr_eq(orig_base, new_base,
|
||||
"Failed to reuse the allocated memory.");
|
||||
expect_ptr_eq(
|
||||
orig_base, new_base, "Failed to reuse the allocated memory.");
|
||||
expect_contiguous(allocs, NALLOCS);
|
||||
|
||||
destroy_test_data(shard);
|
||||
|
|
@ -429,7 +427,7 @@ TEST_BEGIN(test_defer_time) {
|
|||
bool deferred_work_generated = false;
|
||||
|
||||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
edata_t *edatas[HUGEPAGE_PAGES];
|
||||
for (int i = 0; i < (int)HUGEPAGE_PAGES; i++) {
|
||||
edatas[i] = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
|
|
@ -448,8 +446,8 @@ TEST_BEGIN(test_defer_time) {
|
|||
|
||||
/* Purge. Recall that dirty_mult is .25. */
|
||||
for (int i = 0; i < (int)HUGEPAGE_PAGES / 2; i++) {
|
||||
pai_dalloc(tsdn, &shard->pai, edatas[i],
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(
|
||||
tsdn, &shard->pai, edatas[i], &deferred_work_generated);
|
||||
}
|
||||
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -474,8 +472,7 @@ TEST_BEGIN(test_defer_time) {
|
|||
* We would be ineligible for hugification, had we not already met the
|
||||
* threshold before dipping below it.
|
||||
*/
|
||||
pai_dalloc(tsdn, &shard->pai, edatas[0],
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(tsdn, &shard->pai, edatas[0], &deferred_work_generated);
|
||||
/* Wait for the threshold again. */
|
||||
nstime_init2(&defer_curtime, 22, 0);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -491,8 +488,8 @@ TEST_END
|
|||
TEST_BEGIN(test_purge_no_infinite_loop) {
|
||||
test_skip_if(!hpa_supported());
|
||||
|
||||
hpa_shard_t *shard = create_test_data(&hpa_hooks_default,
|
||||
&test_hpa_shard_opts_purge);
|
||||
hpa_shard_t *shard = create_test_data(
|
||||
&hpa_hooks_default, &test_hpa_shard_opts_purge);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
/*
|
||||
|
|
@ -500,14 +497,15 @@ TEST_BEGIN(test_purge_no_infinite_loop) {
|
|||
* criteria for huge page and at the same time do not allow hugify page
|
||||
* without triggering a purge.
|
||||
*/
|
||||
const size_t npages =
|
||||
test_hpa_shard_opts_purge.hugification_threshold / PAGE + 1;
|
||||
const size_t npages = test_hpa_shard_opts_purge.hugification_threshold
|
||||
/ PAGE
|
||||
+ 1;
|
||||
const size_t size = npages * PAGE;
|
||||
|
||||
bool deferred_work_generated = false;
|
||||
bool deferred_work_generated = false;
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, size, PAGE,
|
||||
/* zero */ false, /* guarded */ false, /* frequent_reuse */ false,
|
||||
&deferred_work_generated);
|
||||
/* zero */ false, /* guarded */ false, /* frequent_reuse */ false,
|
||||
&deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Unexpected alloc failure");
|
||||
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -542,8 +540,8 @@ TEST_BEGIN(test_no_min_purge_interval) {
|
|||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
false, false, &deferred_work_generated);
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false, false,
|
||||
false, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Unexpected null edata");
|
||||
pai_dalloc(tsdn, &shard->pai, edata, &deferred_work_generated);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -584,8 +582,8 @@ TEST_BEGIN(test_min_purge_interval) {
|
|||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
false, false, &deferred_work_generated);
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false, false,
|
||||
false, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Unexpected null edata");
|
||||
pai_dalloc(tsdn, &shard->pai, edata, &deferred_work_generated);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -634,7 +632,7 @@ TEST_BEGIN(test_purge) {
|
|||
|
||||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
enum {NALLOCS = 8 * HUGEPAGE_PAGES};
|
||||
enum { NALLOCS = 8 * HUGEPAGE_PAGES };
|
||||
edata_t *edatas[NALLOCS];
|
||||
for (int i = 0; i < NALLOCS; i++) {
|
||||
edatas[i] = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
|
|
@ -643,8 +641,8 @@ TEST_BEGIN(test_purge) {
|
|||
}
|
||||
/* Deallocate 3 hugepages out of 8. */
|
||||
for (int i = 0; i < 3 * (int)HUGEPAGE_PAGES; i++) {
|
||||
pai_dalloc(tsdn, &shard->pai, edatas[i],
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(
|
||||
tsdn, &shard->pai, edatas[i], &deferred_work_generated);
|
||||
}
|
||||
nstime_init2(&defer_curtime, 6, 0);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -702,7 +700,7 @@ TEST_BEGIN(test_experimental_max_purge_nhp) {
|
|||
|
||||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
enum {NALLOCS = 8 * HUGEPAGE_PAGES};
|
||||
enum { NALLOCS = 8 * HUGEPAGE_PAGES };
|
||||
edata_t *edatas[NALLOCS];
|
||||
for (int i = 0; i < NALLOCS; i++) {
|
||||
edatas[i] = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
|
|
@ -711,8 +709,8 @@ TEST_BEGIN(test_experimental_max_purge_nhp) {
|
|||
}
|
||||
/* Deallocate 3 hugepages out of 8. */
|
||||
for (int i = 0; i < 3 * (int)HUGEPAGE_PAGES; i++) {
|
||||
pai_dalloc(tsdn, &shard->pai, edatas[i],
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(
|
||||
tsdn, &shard->pai, edatas[i], &deferred_work_generated);
|
||||
}
|
||||
nstime_init2(&defer_curtime, 6, 0);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -749,8 +747,7 @@ TEST_BEGIN(test_experimental_max_purge_nhp) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_vectorized_opt_eq_zero) {
|
||||
test_skip_if(!hpa_supported() ||
|
||||
(opt_process_madvise_max_batch != 0));
|
||||
test_skip_if(!hpa_supported() || (opt_process_madvise_max_batch != 0));
|
||||
|
||||
hpa_hooks_t hooks;
|
||||
hooks.map = &defer_test_map;
|
||||
|
|
@ -770,11 +767,11 @@ TEST_BEGIN(test_vectorized_opt_eq_zero) {
|
|||
ndefer_purge_calls = 0;
|
||||
|
||||
hpa_shard_t *shard = create_test_data(&hooks, &opts);
|
||||
bool deferred_work_generated = false;
|
||||
bool deferred_work_generated = false;
|
||||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
false, false, &deferred_work_generated);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false, false,
|
||||
false, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Unexpected null edata");
|
||||
pai_dalloc(tsdn, &shard->pai, edata, &deferred_work_generated);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -800,15 +797,9 @@ main(void) {
|
|||
(void)mem_tree_iter;
|
||||
(void)mem_tree_reverse_iter;
|
||||
(void)mem_tree_destroy;
|
||||
return test_no_reentrancy(
|
||||
test_alloc_max,
|
||||
test_stress,
|
||||
test_alloc_dalloc_batch,
|
||||
test_defer_time,
|
||||
test_purge_no_infinite_loop,
|
||||
test_no_min_purge_interval,
|
||||
test_min_purge_interval,
|
||||
test_purge,
|
||||
test_experimental_max_purge_nhp,
|
||||
test_vectorized_opt_eq_zero);
|
||||
return test_no_reentrancy(test_alloc_max, test_stress,
|
||||
test_alloc_dalloc_batch, test_defer_time,
|
||||
test_purge_no_infinite_loop, test_no_min_purge_interval,
|
||||
test_min_purge_interval, test_purge,
|
||||
test_experimental_max_purge_nhp, test_vectorized_opt_eq_zero);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ TEST_BEGIN(test_hpa_background_thread_a0_initialized) {
|
|||
test_skip_if(!have_background_thread);
|
||||
test_skip_if(san_guard_enabled());
|
||||
|
||||
bool enabled = false;
|
||||
bool enabled = false;
|
||||
size_t sz = sizeof(enabled);
|
||||
int err = mallctl("background_thread", (void *)&enabled, &sz, NULL, 0);
|
||||
expect_d_eq(err, 0, "Unexpected mallctl() failure");
|
||||
|
|
@ -38,7 +38,7 @@ sleep_for_background_thread_interval(void) {
|
|||
static unsigned
|
||||
create_arena(void) {
|
||||
unsigned arena_ind;
|
||||
size_t sz;
|
||||
size_t sz;
|
||||
|
||||
sz = sizeof(unsigned);
|
||||
expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 2),
|
||||
|
|
@ -48,17 +48,17 @@ create_arena(void) {
|
|||
|
||||
static size_t
|
||||
get_empty_ndirty(unsigned arena_ind) {
|
||||
int err;
|
||||
size_t ndirty_huge;
|
||||
size_t ndirty_nonhuge;
|
||||
int err;
|
||||
size_t ndirty_huge;
|
||||
size_t ndirty_nonhuge;
|
||||
uint64_t epoch = 1;
|
||||
size_t sz = sizeof(epoch);
|
||||
err = je_mallctl("epoch", (void *)&epoch, &sz, (void *)&epoch,
|
||||
sizeof(epoch));
|
||||
size_t sz = sizeof(epoch);
|
||||
err = je_mallctl(
|
||||
"epoch", (void *)&epoch, &sz, (void *)&epoch, sizeof(epoch));
|
||||
expect_d_eq(0, err, "Unexpected mallctl() failure");
|
||||
|
||||
size_t mib[6];
|
||||
size_t miblen = sizeof(mib)/sizeof(mib[0]);
|
||||
size_t miblen = sizeof(mib) / sizeof(mib[0]);
|
||||
err = mallctlnametomib(
|
||||
"stats.arenas.0.hpa_shard.empty_slabs.ndirty_nonhuge", mib,
|
||||
&miblen);
|
||||
|
|
@ -70,8 +70,7 @@ get_empty_ndirty(unsigned arena_ind) {
|
|||
expect_d_eq(0, err, "Unexpected mallctlbymib() failure");
|
||||
|
||||
err = mallctlnametomib(
|
||||
"stats.arenas.0.hpa_shard.empty_slabs.ndirty_huge", mib,
|
||||
&miblen);
|
||||
"stats.arenas.0.hpa_shard.empty_slabs.ndirty_huge", mib, &miblen);
|
||||
expect_d_eq(0, err, "Unexpected mallctlnametomib() failure");
|
||||
|
||||
sz = sizeof(ndirty_huge);
|
||||
|
|
@ -85,20 +84,20 @@ get_empty_ndirty(unsigned arena_ind) {
|
|||
static void
|
||||
set_background_thread_enabled(bool enabled) {
|
||||
int err;
|
||||
err = je_mallctl("background_thread", NULL, NULL, &enabled,
|
||||
sizeof(enabled));
|
||||
err = je_mallctl(
|
||||
"background_thread", NULL, NULL, &enabled, sizeof(enabled));
|
||||
expect_d_eq(0, err, "Unexpected mallctl failure");
|
||||
}
|
||||
|
||||
static void
|
||||
wait_until_thread_is_enabled(unsigned arena_id) {
|
||||
tsd_t* tsd = tsd_fetch();
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
|
||||
bool sleeping = false;
|
||||
int iterations = 0;
|
||||
int iterations = 0;
|
||||
do {
|
||||
background_thread_info_t *info =
|
||||
background_thread_info_get(arena_id);
|
||||
background_thread_info_t *info = background_thread_info_get(
|
||||
arena_id);
|
||||
malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
|
||||
malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx);
|
||||
sleeping = background_thread_indefinite_sleep(info);
|
||||
|
|
@ -113,10 +112,8 @@ expect_purging(unsigned arena_ind) {
|
|||
expect_zu_eq(0, empty_ndirty, "Expected arena to start unused.");
|
||||
|
||||
void *ptrs[2];
|
||||
ptrs[0] = mallocx(PAGE,
|
||||
MALLOCX_TCACHE_NONE | MALLOCX_ARENA(arena_ind));
|
||||
ptrs[1] = mallocx(PAGE,
|
||||
MALLOCX_TCACHE_NONE | MALLOCX_ARENA(arena_ind));
|
||||
ptrs[0] = mallocx(PAGE, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(arena_ind));
|
||||
ptrs[1] = mallocx(PAGE, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(arena_ind));
|
||||
|
||||
empty_ndirty = get_empty_ndirty(arena_ind);
|
||||
expect_zu_eq(0, empty_ndirty, "All pages should be active");
|
||||
|
|
@ -151,15 +148,14 @@ expect_deferred_purging(unsigned arena_ind) {
|
|||
*/
|
||||
bool observed_dirty_page = false;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
void *ptr = mallocx(PAGE,
|
||||
MALLOCX_TCACHE_NONE | MALLOCX_ARENA(arena_ind));
|
||||
void *ptr = mallocx(
|
||||
PAGE, MALLOCX_TCACHE_NONE | MALLOCX_ARENA(arena_ind));
|
||||
empty_ndirty = get_empty_ndirty(arena_ind);
|
||||
expect_zu_eq(0, empty_ndirty, "All pages should be active");
|
||||
dallocx(ptr, MALLOCX_TCACHE_NONE);
|
||||
empty_ndirty = get_empty_ndirty(arena_ind);
|
||||
expect_true(empty_ndirty == 0 || empty_ndirty == 1 ||
|
||||
opt_prof, "Unexpected extra dirty page count: %zu",
|
||||
empty_ndirty);
|
||||
expect_true(empty_ndirty == 0 || empty_ndirty == 1 || opt_prof,
|
||||
"Unexpected extra dirty page count: %zu", empty_ndirty);
|
||||
if (empty_ndirty > 0) {
|
||||
observed_dirty_page = true;
|
||||
break;
|
||||
|
|
@ -173,8 +169,8 @@ expect_deferred_purging(unsigned arena_ind) {
|
|||
* time. Retry 100 times max before bailing out.
|
||||
*/
|
||||
unsigned retry = 0;
|
||||
while ((empty_ndirty = get_empty_ndirty(arena_ind)) > 0 &&
|
||||
(retry++ < 100)) {
|
||||
while ((empty_ndirty = get_empty_ndirty(arena_ind)) > 0
|
||||
&& (retry++ < 100)) {
|
||||
sleep_for_background_thread_interval();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,36 +13,35 @@ struct test_data_s {
|
|||
* Must be the first member -- we convert back and forth between the
|
||||
* test_data_t and the hpa_shard_t;
|
||||
*/
|
||||
hpa_shard_t shard;
|
||||
hpa_shard_t shard;
|
||||
hpa_central_t central;
|
||||
base_t *base;
|
||||
base_t *base;
|
||||
edata_cache_t shard_edata_cache;
|
||||
|
||||
emap_t emap;
|
||||
};
|
||||
|
||||
static hpa_shard_opts_t test_hpa_shard_opts_default = {
|
||||
/* slab_max_alloc */
|
||||
ALLOC_MAX,
|
||||
/* hugification_threshold */
|
||||
HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(25),
|
||||
/* deferral_allowed */
|
||||
false,
|
||||
/* hugify_delay_ms */
|
||||
10 * 1000,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1
|
||||
};
|
||||
/* slab_max_alloc */
|
||||
ALLOC_MAX,
|
||||
/* hugification_threshold */
|
||||
HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(25),
|
||||
/* deferral_allowed */
|
||||
false,
|
||||
/* hugify_delay_ms */
|
||||
10 * 1000,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1};
|
||||
|
||||
static hpa_shard_t *
|
||||
create_test_data(const hpa_hooks_t *hooks, hpa_shard_opts_t *opts) {
|
||||
bool err;
|
||||
bool err;
|
||||
base_t *base = base_new(TSDN_NULL, /* ind */ SHARD_IND,
|
||||
&ehooks_default_extent_hooks, /* metadata_use_hooks */ true);
|
||||
assert_ptr_not_null(base, "");
|
||||
|
|
@ -108,7 +107,8 @@ defer_vectorized_purge(void *vec, size_t vlen, size_t nbytes) {
|
|||
}
|
||||
|
||||
static bool defer_vec_purge_didfail = false;
|
||||
static bool defer_vectorized_purge_fail(void *vec, size_t vlen, size_t nbytes) {
|
||||
static bool
|
||||
defer_vectorized_purge_fail(void *vec, size_t vlen, size_t nbytes) {
|
||||
(void)vec;
|
||||
(void)vlen;
|
||||
(void)nbytes;
|
||||
|
|
@ -141,8 +141,7 @@ defer_test_ms_since(nstime_t *past_time) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_vectorized_failure_fallback) {
|
||||
test_skip_if(!hpa_supported() ||
|
||||
(opt_process_madvise_max_batch == 0));
|
||||
test_skip_if(!hpa_supported() || (opt_process_madvise_max_batch == 0));
|
||||
|
||||
hpa_hooks_t hooks;
|
||||
hooks.map = &defer_test_map;
|
||||
|
|
@ -166,8 +165,8 @@ TEST_BEGIN(test_vectorized_failure_fallback) {
|
|||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
false, false, &deferred_work_generated);
|
||||
edata_t *edata = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false, false,
|
||||
false, &deferred_work_generated);
|
||||
expect_ptr_not_null(edata, "Unexpected null edata");
|
||||
pai_dalloc(tsdn, &shard->pai, edata, &deferred_work_generated);
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -181,9 +180,8 @@ TEST_BEGIN(test_vectorized_failure_fallback) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_more_regions_purged_from_one_page) {
|
||||
test_skip_if(!hpa_supported() ||
|
||||
(opt_process_madvise_max_batch == 0) ||
|
||||
HUGEPAGE_PAGES <= 4);
|
||||
test_skip_if(!hpa_supported() || (opt_process_madvise_max_batch == 0)
|
||||
|| HUGEPAGE_PAGES <= 4);
|
||||
|
||||
hpa_hooks_t hooks;
|
||||
hooks.map = &defer_test_map;
|
||||
|
|
@ -208,7 +206,7 @@ TEST_BEGIN(test_more_regions_purged_from_one_page) {
|
|||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
enum {NALLOCS = 8 * HUGEPAGE_PAGES};
|
||||
enum { NALLOCS = 8 * HUGEPAGE_PAGES };
|
||||
edata_t *edatas[NALLOCS];
|
||||
for (int i = 0; i < NALLOCS; i++) {
|
||||
edatas[i] = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
|
|
@ -249,12 +247,10 @@ TEST_BEGIN(test_more_regions_purged_from_one_page) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
size_t
|
||||
hpa_purge_max_batch_size_for_test_set(size_t new_size);
|
||||
size_t hpa_purge_max_batch_size_for_test_set(size_t new_size);
|
||||
TEST_BEGIN(test_more_pages_than_batch_page_size) {
|
||||
test_skip_if(!hpa_supported() ||
|
||||
(opt_process_madvise_max_batch == 0) ||
|
||||
HUGEPAGE_PAGES <= 4);
|
||||
test_skip_if(!hpa_supported() || (opt_process_madvise_max_batch == 0)
|
||||
|| HUGEPAGE_PAGES <= 4);
|
||||
|
||||
size_t old_page_batch = hpa_purge_max_batch_size_for_test_set(1);
|
||||
|
||||
|
|
@ -281,7 +277,7 @@ TEST_BEGIN(test_more_pages_than_batch_page_size) {
|
|||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
enum {NALLOCS = 8 * HUGEPAGE_PAGES};
|
||||
enum { NALLOCS = 8 * HUGEPAGE_PAGES };
|
||||
edata_t *edatas[NALLOCS];
|
||||
for (int i = 0; i < NALLOCS; i++) {
|
||||
edatas[i] = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
|
|
@ -289,8 +285,8 @@ TEST_BEGIN(test_more_pages_than_batch_page_size) {
|
|||
expect_ptr_not_null(edatas[i], "Unexpected null edata");
|
||||
}
|
||||
for (int i = 0; i < 3 * (int)HUGEPAGE_PAGES; i++) {
|
||||
pai_dalloc(tsdn, &shard->pai, edatas[i],
|
||||
&deferred_work_generated);
|
||||
pai_dalloc(
|
||||
tsdn, &shard->pai, edatas[i], &deferred_work_generated);
|
||||
}
|
||||
|
||||
hpa_shard_do_deferred_work(tsdn, shard);
|
||||
|
|
@ -321,8 +317,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_vectorized_failure_fallback,
|
||||
return test_no_reentrancy(test_vectorized_failure_fallback,
|
||||
test_more_regions_purged_from_one_page,
|
||||
test_more_pages_than_batch_page_size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,36 +13,35 @@ struct test_data_s {
|
|||
* Must be the first member -- we convert back and forth between the
|
||||
* test_data_t and the hpa_shard_t;
|
||||
*/
|
||||
hpa_shard_t shard;
|
||||
hpa_shard_t shard;
|
||||
hpa_central_t central;
|
||||
base_t *base;
|
||||
base_t *base;
|
||||
edata_cache_t shard_edata_cache;
|
||||
|
||||
emap_t emap;
|
||||
};
|
||||
|
||||
static hpa_shard_opts_t test_hpa_shard_opts_default = {
|
||||
/* slab_max_alloc */
|
||||
ALLOC_MAX,
|
||||
/* hugification_threshold */
|
||||
HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(25),
|
||||
/* deferral_allowed */
|
||||
false,
|
||||
/* hugify_delay_ms */
|
||||
10 * 1000,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1
|
||||
};
|
||||
/* slab_max_alloc */
|
||||
ALLOC_MAX,
|
||||
/* hugification_threshold */
|
||||
HUGEPAGE,
|
||||
/* dirty_mult */
|
||||
FXP_INIT_PERCENT(25),
|
||||
/* deferral_allowed */
|
||||
false,
|
||||
/* hugify_delay_ms */
|
||||
10 * 1000,
|
||||
/* hugify_sync */
|
||||
false,
|
||||
/* min_purge_interval_ms */
|
||||
5 * 1000,
|
||||
/* experimental_max_purge_nhp */
|
||||
-1};
|
||||
|
||||
static hpa_shard_t *
|
||||
create_test_data(const hpa_hooks_t *hooks, hpa_shard_opts_t *opts) {
|
||||
bool err;
|
||||
bool err;
|
||||
base_t *base = base_new(TSDN_NULL, /* ind */ SHARD_IND,
|
||||
&ehooks_default_extent_hooks, /* metadata_use_hooks */ true);
|
||||
assert_ptr_not_null(base, "");
|
||||
|
|
@ -132,8 +131,8 @@ defer_test_ms_since(nstime_t *past_time) {
|
|||
}
|
||||
|
||||
TEST_BEGIN(test_vectorized_purge) {
|
||||
test_skip_if(!hpa_supported() ||
|
||||
opt_process_madvise_max_batch == 0 || HUGEPAGE_PAGES <= 4);
|
||||
test_skip_if(!hpa_supported() || opt_process_madvise_max_batch == 0
|
||||
|| HUGEPAGE_PAGES <= 4);
|
||||
assert(opt_process_madvise_max_batch == 64);
|
||||
|
||||
hpa_hooks_t hooks;
|
||||
|
|
@ -159,7 +158,7 @@ TEST_BEGIN(test_vectorized_purge) {
|
|||
nstime_init(&defer_curtime, 0);
|
||||
tsdn_t *tsdn = tsd_tsdn(tsd_fetch());
|
||||
|
||||
enum {NALLOCS = 8 * HUGEPAGE_PAGES};
|
||||
enum { NALLOCS = 8 * HUGEPAGE_PAGES };
|
||||
edata_t *edatas[NALLOCS];
|
||||
for (int i = 0; i < NALLOCS; i++) {
|
||||
edatas[i] = pai_alloc(tsdn, &shard->pai, PAGE, PAGE, false,
|
||||
|
|
@ -192,6 +191,5 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_vectorized_purge);
|
||||
return test_no_reentrancy(test_vectorized_purge);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,23 +69,25 @@ TEST_BEGIN(test_purge_simple) {
|
|||
|
||||
hpdata_alloc_allowed_set(&hpdata, false);
|
||||
hpdata_purge_state_t purge_state;
|
||||
size_t nranges;
|
||||
size_t nranges;
|
||||
size_t to_purge = hpdata_purge_begin(&hpdata, &purge_state, &nranges);
|
||||
expect_zu_eq(HUGEPAGE_PAGES / 4, to_purge, "");
|
||||
expect_zu_eq(1, nranges, "All dirty pages in a single range");
|
||||
|
||||
void *purge_addr;
|
||||
void *purge_addr;
|
||||
size_t purge_size;
|
||||
bool got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
bool got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_true(got_result, "");
|
||||
expect_ptr_eq(HPDATA_ADDR, purge_addr, "");
|
||||
expect_zu_eq(HUGEPAGE_PAGES / 4 * PAGE, purge_size, "");
|
||||
|
||||
got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
expect_false(got_result, "Unexpected additional purge range: "
|
||||
"extent at %p of size %zu", purge_addr, purge_size);
|
||||
got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_false(got_result,
|
||||
"Unexpected additional purge range: "
|
||||
"extent at %p of size %zu",
|
||||
purge_addr, purge_size);
|
||||
|
||||
hpdata_purge_end(&hpdata, &purge_state);
|
||||
expect_zu_eq(hpdata_ntouched_get(&hpdata), HUGEPAGE_PAGES / 4, "");
|
||||
|
|
@ -102,7 +104,8 @@ TEST_BEGIN(test_purge_intervening_dalloc) {
|
|||
hpdata_init(&hpdata, HPDATA_ADDR, HPDATA_AGE);
|
||||
|
||||
/* Allocate the first 3/4 of the pages. */
|
||||
void *alloc = hpdata_reserve_alloc(&hpdata, 3 * HUGEPAGE_PAGES / 4 * PAGE);
|
||||
void *alloc = hpdata_reserve_alloc(
|
||||
&hpdata, 3 * HUGEPAGE_PAGES / 4 * PAGE);
|
||||
expect_ptr_eq(alloc, HPDATA_ADDR, "");
|
||||
|
||||
/* Free the first 1/4 and the third 1/4 of the pages. */
|
||||
|
|
@ -115,16 +118,16 @@ TEST_BEGIN(test_purge_intervening_dalloc) {
|
|||
|
||||
hpdata_alloc_allowed_set(&hpdata, false);
|
||||
hpdata_purge_state_t purge_state;
|
||||
size_t nranges;
|
||||
size_t nranges;
|
||||
size_t to_purge = hpdata_purge_begin(&hpdata, &purge_state, &nranges);
|
||||
expect_zu_eq(HUGEPAGE_PAGES / 2, to_purge, "");
|
||||
expect_zu_eq(2, nranges, "First quarter and last half");
|
||||
|
||||
void *purge_addr;
|
||||
void *purge_addr;
|
||||
size_t purge_size;
|
||||
/* First purge. */
|
||||
bool got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
bool got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_true(got_result, "");
|
||||
expect_ptr_eq(HPDATA_ADDR, purge_addr, "");
|
||||
expect_zu_eq(HUGEPAGE_PAGES / 4 * PAGE, purge_size, "");
|
||||
|
|
@ -135,18 +138,20 @@ TEST_BEGIN(test_purge_intervening_dalloc) {
|
|||
HUGEPAGE_PAGES / 4 * PAGE);
|
||||
|
||||
/* Now continue purging. */
|
||||
got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_true(got_result, "");
|
||||
expect_ptr_eq(
|
||||
(void *)((uintptr_t)alloc + 2 * HUGEPAGE_PAGES / 4 * PAGE),
|
||||
purge_addr, "");
|
||||
expect_zu_ge(HUGEPAGE_PAGES / 4 * PAGE, purge_size, "");
|
||||
|
||||
got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
expect_false(got_result, "Unexpected additional purge range: "
|
||||
"extent at %p of size %zu", purge_addr, purge_size);
|
||||
got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_false(got_result,
|
||||
"Unexpected additional purge range: "
|
||||
"extent at %p of size %zu",
|
||||
purge_addr, purge_size);
|
||||
|
||||
hpdata_purge_end(&hpdata, &purge_state);
|
||||
|
||||
|
|
@ -155,19 +160,20 @@ TEST_BEGIN(test_purge_intervening_dalloc) {
|
|||
TEST_END
|
||||
|
||||
TEST_BEGIN(test_purge_over_retained) {
|
||||
void *purge_addr;
|
||||
void *purge_addr;
|
||||
size_t purge_size;
|
||||
|
||||
hpdata_t hpdata;
|
||||
hpdata_init(&hpdata, HPDATA_ADDR, HPDATA_AGE);
|
||||
|
||||
/* Allocate the first 3/4 of the pages. */
|
||||
void *alloc = hpdata_reserve_alloc(&hpdata, 3 * HUGEPAGE_PAGES / 4 * PAGE);
|
||||
void *alloc = hpdata_reserve_alloc(
|
||||
&hpdata, 3 * HUGEPAGE_PAGES / 4 * PAGE);
|
||||
expect_ptr_eq(alloc, HPDATA_ADDR, "");
|
||||
|
||||
/* Free the second quarter. */
|
||||
void *second_quarter =
|
||||
(void *)((uintptr_t)alloc + HUGEPAGE_PAGES / 4 * PAGE);
|
||||
void *second_quarter = (void *)((uintptr_t)alloc
|
||||
+ HUGEPAGE_PAGES / 4 * PAGE);
|
||||
hpdata_unreserve(&hpdata, second_quarter, HUGEPAGE_PAGES / 4 * PAGE);
|
||||
|
||||
expect_zu_eq(hpdata_ntouched_get(&hpdata), 3 * HUGEPAGE_PAGES / 4, "");
|
||||
|
|
@ -175,21 +181,24 @@ TEST_BEGIN(test_purge_over_retained) {
|
|||
/* Purge the second quarter. */
|
||||
hpdata_alloc_allowed_set(&hpdata, false);
|
||||
hpdata_purge_state_t purge_state;
|
||||
size_t nranges;
|
||||
size_t to_purge_dirty = hpdata_purge_begin(&hpdata, &purge_state, &nranges);
|
||||
size_t nranges;
|
||||
size_t to_purge_dirty = hpdata_purge_begin(
|
||||
&hpdata, &purge_state, &nranges);
|
||||
expect_zu_eq(HUGEPAGE_PAGES / 4, to_purge_dirty, "");
|
||||
expect_zu_eq(1, nranges, "Second quarter only");
|
||||
|
||||
bool got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
bool got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_true(got_result, "");
|
||||
expect_ptr_eq(second_quarter, purge_addr, "");
|
||||
expect_zu_eq(HUGEPAGE_PAGES / 4 * PAGE, purge_size, "");
|
||||
|
||||
got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
expect_false(got_result, "Unexpected additional purge range: "
|
||||
"extent at %p of size %zu", purge_addr, purge_size);
|
||||
got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_false(got_result,
|
||||
"Unexpected additional purge range: "
|
||||
"extent at %p of size %zu",
|
||||
purge_addr, purge_size);
|
||||
hpdata_purge_end(&hpdata, &purge_state);
|
||||
|
||||
expect_zu_eq(hpdata_ntouched_get(&hpdata), HUGEPAGE_PAGES / 2, "");
|
||||
|
|
@ -209,16 +218,18 @@ TEST_BEGIN(test_purge_over_retained) {
|
|||
expect_zu_eq(HUGEPAGE_PAGES / 2, to_purge_dirty, "");
|
||||
expect_zu_eq(1, nranges, "Single range expected");
|
||||
|
||||
got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_true(got_result, "");
|
||||
expect_ptr_eq(HPDATA_ADDR, purge_addr, "");
|
||||
expect_zu_eq(3 * HUGEPAGE_PAGES / 4 * PAGE, purge_size, "");
|
||||
|
||||
got_result = hpdata_purge_next(&hpdata, &purge_state, &purge_addr,
|
||||
&purge_size);
|
||||
expect_false(got_result, "Unexpected additional purge range: "
|
||||
"extent at %p of size %zu", purge_addr, purge_size);
|
||||
got_result = hpdata_purge_next(
|
||||
&hpdata, &purge_state, &purge_addr, &purge_size);
|
||||
expect_false(got_result,
|
||||
"Unexpected additional purge range: "
|
||||
"extent at %p of size %zu",
|
||||
purge_addr, purge_size);
|
||||
hpdata_purge_end(&hpdata, &purge_state);
|
||||
|
||||
expect_zu_eq(hpdata_ntouched_get(&hpdata), 0, "");
|
||||
|
|
@ -241,11 +252,9 @@ TEST_BEGIN(test_hugify) {
|
|||
}
|
||||
TEST_END
|
||||
|
||||
int main(void) {
|
||||
return test_no_reentrancy(
|
||||
test_reserve_alloc,
|
||||
test_purge_simple,
|
||||
test_purge_intervening_dalloc,
|
||||
test_purge_over_retained,
|
||||
int
|
||||
main(void) {
|
||||
return test_no_reentrancy(test_reserve_alloc, test_purge_simple,
|
||||
test_purge_intervening_dalloc, test_purge_over_retained,
|
||||
test_hugify);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,40 @@ const char *malloc_conf = "oversize_threshold:2097152";
|
|||
|
||||
TEST_BEGIN(huge_bind_thread) {
|
||||
unsigned arena1, arena2;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
|
||||
/* Bind to a manual arena. */
|
||||
expect_d_eq(mallctl("arenas.create", &arena1, &sz, NULL, 0), 0,
|
||||
"Failed to create arena");
|
||||
expect_d_eq(mallctl("thread.arena", NULL, NULL, &arena1,
|
||||
sizeof(arena1)), 0, "Fail to bind thread");
|
||||
expect_d_eq(
|
||||
mallctl("thread.arena", NULL, NULL, &arena1, sizeof(arena1)), 0,
|
||||
"Fail to bind thread");
|
||||
|
||||
void *ptr = mallocx(HUGE_SZ, 0);
|
||||
expect_ptr_not_null(ptr, "Fail to allocate huge size");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr,
|
||||
sizeof(ptr)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr, sizeof(ptr)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_eq(arena1, arena2, "Wrong arena used after binding");
|
||||
dallocx(ptr, 0);
|
||||
|
||||
/* Switch back to arena 0. */
|
||||
test_skip_if(have_percpu_arena &&
|
||||
PERCPU_ARENA_ENABLED(opt_percpu_arena));
|
||||
test_skip_if(
|
||||
have_percpu_arena && PERCPU_ARENA_ENABLED(opt_percpu_arena));
|
||||
arena2 = 0;
|
||||
expect_d_eq(mallctl("thread.arena", NULL, NULL, &arena2,
|
||||
sizeof(arena2)), 0, "Fail to bind thread");
|
||||
expect_d_eq(
|
||||
mallctl("thread.arena", NULL, NULL, &arena2, sizeof(arena2)), 0,
|
||||
"Fail to bind thread");
|
||||
ptr = mallocx(SMALL_SZ, MALLOCX_TCACHE_NONE);
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr,
|
||||
sizeof(ptr)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr, sizeof(ptr)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_eq(arena2, 0, "Wrong arena used after binding");
|
||||
dallocx(ptr, MALLOCX_TCACHE_NONE);
|
||||
|
||||
/* Then huge allocation should use the huge arena. */
|
||||
ptr = mallocx(HUGE_SZ, 0);
|
||||
expect_ptr_not_null(ptr, "Fail to allocate huge size");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr,
|
||||
sizeof(ptr)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr, sizeof(ptr)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_ne(arena2, 0, "Wrong arena used after binding");
|
||||
expect_u_ne(arena1, arena2, "Wrong arena used after binding");
|
||||
dallocx(ptr, 0);
|
||||
|
|
@ -48,25 +50,26 @@ TEST_END
|
|||
|
||||
TEST_BEGIN(huge_mallocx) {
|
||||
unsigned arena1, arena2;
|
||||
size_t sz = sizeof(unsigned);
|
||||
size_t sz = sizeof(unsigned);
|
||||
|
||||
expect_d_eq(mallctl("arenas.create", &arena1, &sz, NULL, 0), 0,
|
||||
"Failed to create arena");
|
||||
void *huge = mallocx(HUGE_SZ, MALLOCX_ARENA(arena1));
|
||||
expect_ptr_not_null(huge, "Fail to allocate huge size");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &huge,
|
||||
sizeof(huge)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &huge, sizeof(huge)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_eq(arena1, arena2, "Wrong arena used for mallocx");
|
||||
dallocx(huge, MALLOCX_ARENA(arena1));
|
||||
|
||||
void *huge2 = mallocx(HUGE_SZ, 0);
|
||||
expect_ptr_not_null(huge, "Fail to allocate huge size");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &huge2,
|
||||
sizeof(huge2)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(
|
||||
mallctl("arenas.lookup", &arena2, &sz, &huge2, sizeof(huge2)), 0,
|
||||
"Unexpected mallctl() failure");
|
||||
expect_u_ne(arena1, arena2,
|
||||
"Huge allocation should not come from the manual arena.");
|
||||
expect_u_ne(arena2, 0,
|
||||
"Huge allocation should not come from the arena 0.");
|
||||
expect_u_ne(
|
||||
arena2, 0, "Huge allocation should not come from the arena 0.");
|
||||
dallocx(huge2, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
|
@ -82,30 +85,27 @@ TEST_BEGIN(huge_allocation) {
|
|||
expect_u_gt(arena1, 0, "Huge allocation should not come from arena 0");
|
||||
dallocx(ptr, 0);
|
||||
|
||||
test_skip_if(have_percpu_arena &&
|
||||
PERCPU_ARENA_ENABLED(opt_percpu_arena));
|
||||
test_skip_if(
|
||||
have_percpu_arena && PERCPU_ARENA_ENABLED(opt_percpu_arena));
|
||||
|
||||
ptr = mallocx(HUGE_SZ >> 1, 0);
|
||||
expect_ptr_not_null(ptr, "Fail to allocate half huge size");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr,
|
||||
sizeof(ptr)), 0, "Unexpected mallctl() failure");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr, sizeof(ptr)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_ne(arena1, arena2, "Wrong arena used for half huge");
|
||||
dallocx(ptr, 0);
|
||||
|
||||
ptr = mallocx(SMALL_SZ, MALLOCX_TCACHE_NONE);
|
||||
expect_ptr_not_null(ptr, "Fail to allocate small size");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr,
|
||||
sizeof(ptr)), 0, "Unexpected mallctl() failure");
|
||||
expect_u_ne(arena1, arena2,
|
||||
"Huge and small should be from different arenas");
|
||||
expect_d_eq(mallctl("arenas.lookup", &arena2, &sz, &ptr, sizeof(ptr)),
|
||||
0, "Unexpected mallctl() failure");
|
||||
expect_u_ne(
|
||||
arena1, arena2, "Huge and small should be from different arenas");
|
||||
dallocx(ptr, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
huge_allocation,
|
||||
huge_mallocx,
|
||||
huge_bind_thread);
|
||||
return test(huge_allocation, huge_mallocx, huge_bind_thread);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,30 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define TEST_UTIL_EINVAL(node, a, b, c, d, why_inval) do { \
|
||||
assert_d_eq(mallctl("experimental.utilization." node, \
|
||||
a, b, c, d), EINVAL, "Should fail when " why_inval); \
|
||||
assert_zu_eq(out_sz, out_sz_ref, \
|
||||
"Output size touched when given invalid arguments"); \
|
||||
assert_d_eq(memcmp(out, out_ref, out_sz_ref), 0, \
|
||||
"Output content touched when given invalid arguments"); \
|
||||
} while (0)
|
||||
#define TEST_UTIL_EINVAL(node, a, b, c, d, why_inval) \
|
||||
do { \
|
||||
assert_d_eq( \
|
||||
mallctl("experimental.utilization." node, a, b, c, d), \
|
||||
EINVAL, "Should fail when " why_inval); \
|
||||
assert_zu_eq(out_sz, out_sz_ref, \
|
||||
"Output size touched when given invalid arguments"); \
|
||||
assert_d_eq(memcmp(out, out_ref, out_sz_ref), 0, \
|
||||
"Output content touched when given invalid arguments"); \
|
||||
} while (0)
|
||||
|
||||
#define TEST_UTIL_QUERY_EINVAL(a, b, c, d, why_inval) \
|
||||
#define TEST_UTIL_QUERY_EINVAL(a, b, c, d, why_inval) \
|
||||
TEST_UTIL_EINVAL("query", a, b, c, d, why_inval)
|
||||
#define TEST_UTIL_BATCH_EINVAL(a, b, c, d, why_inval) \
|
||||
#define TEST_UTIL_BATCH_EINVAL(a, b, c, d, why_inval) \
|
||||
TEST_UTIL_EINVAL("batch_query", a, b, c, d, why_inval)
|
||||
|
||||
#define TEST_UTIL_VALID(node) do { \
|
||||
assert_d_eq(mallctl("experimental.utilization." node, \
|
||||
out, &out_sz, in, in_sz), 0, \
|
||||
"Should return 0 on correct arguments"); \
|
||||
expect_zu_eq(out_sz, out_sz_ref, "incorrect output size"); \
|
||||
expect_d_ne(memcmp(out, out_ref, out_sz_ref), 0, \
|
||||
"Output content should be changed"); \
|
||||
} while (0)
|
||||
#define TEST_UTIL_VALID(node) \
|
||||
do { \
|
||||
assert_d_eq(mallctl("experimental.utilization." node, out, \
|
||||
&out_sz, in, in_sz), \
|
||||
0, "Should return 0 on correct arguments"); \
|
||||
expect_zu_eq(out_sz, out_sz_ref, "incorrect output size"); \
|
||||
expect_d_ne(memcmp(out, out_ref, out_sz_ref), 0, \
|
||||
"Output content should be changed"); \
|
||||
} while (0)
|
||||
|
||||
#define TEST_UTIL_BATCH_VALID TEST_UTIL_VALID("batch_query")
|
||||
|
||||
|
|
@ -34,21 +37,19 @@ TEST_BEGIN(test_query) {
|
|||
* numerically unrelated to any size boundaries.
|
||||
*/
|
||||
for (sz = 7; sz <= TEST_MAX_SIZE && sz <= SC_LARGE_MAXCLASS;
|
||||
sz += (sz <= SC_SMALL_MAXCLASS ? 1009 : 99989)) {
|
||||
void *p = mallocx(sz, 0);
|
||||
sz += (sz <= SC_SMALL_MAXCLASS ? 1009 : 99989)) {
|
||||
void *p = mallocx(sz, 0);
|
||||
void **in = &p;
|
||||
size_t in_sz = sizeof(const void *);
|
||||
size_t out_sz = sizeof(void *) + sizeof(size_t) * 5;
|
||||
void *out = mallocx(out_sz, 0);
|
||||
void *out_ref = mallocx(out_sz, 0);
|
||||
void *out = mallocx(out_sz, 0);
|
||||
void *out_ref = mallocx(out_sz, 0);
|
||||
size_t out_sz_ref = out_sz;
|
||||
|
||||
assert_ptr_not_null(p,
|
||||
"test pointer allocation failed");
|
||||
assert_ptr_not_null(out,
|
||||
"test output allocation failed");
|
||||
assert_ptr_not_null(out_ref,
|
||||
"test reference output allocation failed");
|
||||
assert_ptr_not_null(p, "test pointer allocation failed");
|
||||
assert_ptr_not_null(out, "test output allocation failed");
|
||||
assert_ptr_not_null(
|
||||
out_ref, "test reference output allocation failed");
|
||||
|
||||
#define SLABCUR_READ(out) (*(void **)out)
|
||||
#define COUNTS(out) ((size_t *)((void **)out + 1))
|
||||
|
|
@ -64,21 +65,18 @@ TEST_BEGIN(test_query) {
|
|||
memcpy(out_ref, out, out_sz);
|
||||
|
||||
/* Test invalid argument(s) errors */
|
||||
TEST_UTIL_QUERY_EINVAL(NULL, &out_sz, in, in_sz,
|
||||
"old is NULL");
|
||||
TEST_UTIL_QUERY_EINVAL(out, NULL, in, in_sz,
|
||||
"oldlenp is NULL");
|
||||
TEST_UTIL_QUERY_EINVAL(out, &out_sz, NULL, in_sz,
|
||||
"newp is NULL");
|
||||
TEST_UTIL_QUERY_EINVAL(out, &out_sz, in, 0,
|
||||
"newlen is zero");
|
||||
TEST_UTIL_QUERY_EINVAL(NULL, &out_sz, in, in_sz, "old is NULL");
|
||||
TEST_UTIL_QUERY_EINVAL(out, NULL, in, in_sz, "oldlenp is NULL");
|
||||
TEST_UTIL_QUERY_EINVAL(
|
||||
out, &out_sz, NULL, in_sz, "newp is NULL");
|
||||
TEST_UTIL_QUERY_EINVAL(out, &out_sz, in, 0, "newlen is zero");
|
||||
in_sz -= 1;
|
||||
TEST_UTIL_QUERY_EINVAL(out, &out_sz, in, in_sz,
|
||||
"invalid newlen");
|
||||
TEST_UTIL_QUERY_EINVAL(
|
||||
out, &out_sz, in, in_sz, "invalid newlen");
|
||||
in_sz += 1;
|
||||
out_sz_ref = out_sz -= 2 * sizeof(size_t);
|
||||
TEST_UTIL_QUERY_EINVAL(out, &out_sz, in, in_sz,
|
||||
"invalid *oldlenp");
|
||||
TEST_UTIL_QUERY_EINVAL(
|
||||
out, &out_sz, in, in_sz, "invalid *oldlenp");
|
||||
out_sz_ref = out_sz += 2 * sizeof(size_t);
|
||||
|
||||
/* Examine output for valid call */
|
||||
|
|
@ -100,8 +98,9 @@ TEST_BEGIN(test_query) {
|
|||
"Extent region count exceeded size");
|
||||
expect_zu_ne(NREGS_READ(out), 0,
|
||||
"Extent region count must be positive");
|
||||
expect_true(NFREE_READ(out) == 0 || (SLABCUR_READ(out)
|
||||
!= NULL && SLABCUR_READ(out) <= p),
|
||||
expect_true(NFREE_READ(out) == 0
|
||||
|| (SLABCUR_READ(out) != NULL
|
||||
&& SLABCUR_READ(out) <= p),
|
||||
"Allocation should follow first fit principle");
|
||||
|
||||
if (config_stats) {
|
||||
|
|
@ -117,8 +116,8 @@ TEST_BEGIN(test_query) {
|
|||
BIN_NREGS_READ(out),
|
||||
"Extent region count exceeded "
|
||||
"bin region count");
|
||||
expect_zu_eq(BIN_NREGS_READ(out)
|
||||
% NREGS_READ(out), 0,
|
||||
expect_zu_eq(
|
||||
BIN_NREGS_READ(out) % NREGS_READ(out), 0,
|
||||
"Bin region count isn't a multiple of "
|
||||
"extent region count");
|
||||
expect_zu_le(
|
||||
|
|
@ -171,10 +170,10 @@ TEST_BEGIN(test_batch) {
|
|||
* numerically unrelated to any size boundaries.
|
||||
*/
|
||||
for (sz = 17; sz <= TEST_MAX_SIZE && sz <= SC_LARGE_MAXCLASS;
|
||||
sz += (sz <= SC_SMALL_MAXCLASS ? 1019 : 99991)) {
|
||||
void *p = mallocx(sz, 0);
|
||||
void *q = mallocx(sz, 0);
|
||||
void *in[] = {p, q};
|
||||
sz += (sz <= SC_SMALL_MAXCLASS ? 1019 : 99991)) {
|
||||
void *p = mallocx(sz, 0);
|
||||
void *q = mallocx(sz, 0);
|
||||
void *in[] = {p, q};
|
||||
size_t in_sz = sizeof(const void *) * 2;
|
||||
size_t out[] = {-1, -1, -1, -1, -1, -1};
|
||||
size_t out_sz = sizeof(size_t) * 6;
|
||||
|
|
@ -185,17 +184,14 @@ TEST_BEGIN(test_batch) {
|
|||
assert_ptr_not_null(q, "test pointer allocation failed");
|
||||
|
||||
/* Test invalid argument(s) errors */
|
||||
TEST_UTIL_BATCH_EINVAL(NULL, &out_sz, in, in_sz,
|
||||
"old is NULL");
|
||||
TEST_UTIL_BATCH_EINVAL(out, NULL, in, in_sz,
|
||||
"oldlenp is NULL");
|
||||
TEST_UTIL_BATCH_EINVAL(out, &out_sz, NULL, in_sz,
|
||||
"newp is NULL");
|
||||
TEST_UTIL_BATCH_EINVAL(out, &out_sz, in, 0,
|
||||
"newlen is zero");
|
||||
TEST_UTIL_BATCH_EINVAL(NULL, &out_sz, in, in_sz, "old is NULL");
|
||||
TEST_UTIL_BATCH_EINVAL(out, NULL, in, in_sz, "oldlenp is NULL");
|
||||
TEST_UTIL_BATCH_EINVAL(
|
||||
out, &out_sz, NULL, in_sz, "newp is NULL");
|
||||
TEST_UTIL_BATCH_EINVAL(out, &out_sz, in, 0, "newlen is zero");
|
||||
in_sz -= 1;
|
||||
TEST_UTIL_BATCH_EINVAL(out, &out_sz, in, in_sz,
|
||||
"newlen is not an exact multiple");
|
||||
TEST_UTIL_BATCH_EINVAL(
|
||||
out, &out_sz, in, in_sz, "newlen is not an exact multiple");
|
||||
in_sz += 1;
|
||||
out_sz_ref = out_sz -= 2 * sizeof(size_t);
|
||||
TEST_UTIL_BATCH_EINVAL(out, &out_sz, in, in_sz,
|
||||
|
|
@ -206,8 +202,8 @@ TEST_BEGIN(test_batch) {
|
|||
"*oldlenp and newlen do not match");
|
||||
in_sz += sizeof(const void *);
|
||||
|
||||
/* Examine output for valid calls */
|
||||
#define TEST_EQUAL_REF(i, message) \
|
||||
/* Examine output for valid calls */
|
||||
#define TEST_EQUAL_REF(i, message) \
|
||||
assert_d_eq(memcmp(out + (i) * 3, out_ref + (i) * 3, 3), 0, message)
|
||||
|
||||
#define NFREE_READ(out, i) out[(i) * 3]
|
||||
|
|
@ -238,8 +234,8 @@ TEST_BEGIN(test_batch) {
|
|||
expect_zu_eq(NREGS_READ(out, 0), 1,
|
||||
"Extent region count should be one");
|
||||
}
|
||||
TEST_EQUAL_REF(1,
|
||||
"Should not overwrite content beyond what's needed");
|
||||
TEST_EQUAL_REF(
|
||||
1, "Should not overwrite content beyond what's needed");
|
||||
in_sz *= 2;
|
||||
out_sz_ref = out_sz *= 2;
|
||||
|
||||
|
|
|
|||
107
test/unit/junk.c
107
test/unit/junk.c
|
|
@ -1,9 +1,9 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define arraylen(arr) (sizeof(arr)/sizeof(arr[0]))
|
||||
#define arraylen(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
static size_t ptr_ind;
|
||||
static void *volatile ptrs[100];
|
||||
static void *last_junked_ptr;
|
||||
static void *last_junked_ptr;
|
||||
static size_t last_junked_usize;
|
||||
|
||||
static void
|
||||
|
|
@ -21,17 +21,17 @@ test_junk(void *ptr, size_t usize) {
|
|||
|
||||
static void
|
||||
do_allocs(size_t size, bool zero, size_t lg_align) {
|
||||
#define JUNK_ALLOC(...) \
|
||||
do { \
|
||||
assert(ptr_ind + 1 < arraylen(ptrs)); \
|
||||
void *ptr = __VA_ARGS__; \
|
||||
assert_ptr_not_null(ptr, ""); \
|
||||
ptrs[ptr_ind++] = ptr; \
|
||||
if (opt_junk_alloc && !zero) { \
|
||||
expect_ptr_eq(ptr, last_junked_ptr, ""); \
|
||||
expect_zu_eq(last_junked_usize, \
|
||||
TEST_MALLOC_SIZE(ptr), ""); \
|
||||
} \
|
||||
#define JUNK_ALLOC(...) \
|
||||
do { \
|
||||
assert(ptr_ind + 1 < arraylen(ptrs)); \
|
||||
void *ptr = __VA_ARGS__; \
|
||||
assert_ptr_not_null(ptr, ""); \
|
||||
ptrs[ptr_ind++] = ptr; \
|
||||
if (opt_junk_alloc && !zero) { \
|
||||
expect_ptr_eq(ptr, last_junked_ptr, ""); \
|
||||
expect_zu_eq( \
|
||||
last_junked_usize, TEST_MALLOC_SIZE(ptr), ""); \
|
||||
} \
|
||||
} while (0)
|
||||
if (!zero && lg_align == 0) {
|
||||
JUNK_ALLOC(malloc(size));
|
||||
|
|
@ -51,21 +51,20 @@ do_allocs(size_t size, bool zero, size_t lg_align) {
|
|||
#endif
|
||||
int zero_flag = zero ? MALLOCX_ZERO : 0;
|
||||
JUNK_ALLOC(mallocx(size, zero_flag | MALLOCX_LG_ALIGN(lg_align)));
|
||||
JUNK_ALLOC(mallocx(size, zero_flag | MALLOCX_LG_ALIGN(lg_align)
|
||||
| MALLOCX_TCACHE_NONE));
|
||||
JUNK_ALLOC(mallocx(size,
|
||||
zero_flag | MALLOCX_LG_ALIGN(lg_align) | MALLOCX_TCACHE_NONE));
|
||||
if (lg_align >= LG_SIZEOF_PTR) {
|
||||
void *memalign_result;
|
||||
int err = posix_memalign(&memalign_result, (1 << lg_align),
|
||||
size);
|
||||
int err = posix_memalign(
|
||||
&memalign_result, (1 << lg_align), size);
|
||||
assert_d_eq(err, 0, "");
|
||||
JUNK_ALLOC(memalign_result);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_junk_alloc_free) {
|
||||
bool zerovals[] = {false, true};
|
||||
size_t sizevals[] = {
|
||||
1, 8, 100, 1000, 100*1000
|
||||
bool zerovals[] = {false, true};
|
||||
size_t sizevals[] = {1, 8, 100, 1000, 100 * 1000
|
||||
/*
|
||||
* Memory allocation failure is a real possibility in 32-bit mode.
|
||||
* Rather than try to check in the face of resource exhaustion, we just
|
||||
|
|
@ -75,49 +74,49 @@ TEST_BEGIN(test_junk_alloc_free) {
|
|||
* mechanisms; but this is in fact the case.
|
||||
*/
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
, 10 * 1000 * 1000
|
||||
,
|
||||
10 * 1000 * 1000
|
||||
#endif
|
||||
};
|
||||
size_t lg_alignvals[] = {
|
||||
0, 4, 10, 15, 16, LG_PAGE
|
||||
size_t lg_alignvals[] = {0, 4, 10, 15, 16, LG_PAGE
|
||||
#if LG_SIZEOF_PTR == 3
|
||||
, 20, 24
|
||||
,
|
||||
20, 24
|
||||
#endif
|
||||
};
|
||||
|
||||
#define JUNK_FREE(...) \
|
||||
do { \
|
||||
do_allocs(size, zero, lg_align); \
|
||||
for (size_t n = 0; n < ptr_ind; n++) { \
|
||||
void *ptr = ptrs[n]; \
|
||||
__VA_ARGS__; \
|
||||
if (opt_junk_free) { \
|
||||
assert_ptr_eq(ptr, last_junked_ptr, \
|
||||
""); \
|
||||
assert_zu_eq(usize, last_junked_usize, \
|
||||
""); \
|
||||
} \
|
||||
reset(); \
|
||||
} \
|
||||
#define JUNK_FREE(...) \
|
||||
do { \
|
||||
do_allocs(size, zero, lg_align); \
|
||||
for (size_t n = 0; n < ptr_ind; n++) { \
|
||||
void *ptr = ptrs[n]; \
|
||||
__VA_ARGS__; \
|
||||
if (opt_junk_free) { \
|
||||
assert_ptr_eq(ptr, last_junked_ptr, ""); \
|
||||
assert_zu_eq(usize, last_junked_usize, ""); \
|
||||
} \
|
||||
reset(); \
|
||||
} \
|
||||
} while (0)
|
||||
for (size_t i = 0; i < arraylen(zerovals); i++) {
|
||||
for (size_t j = 0; j < arraylen(sizevals); j++) {
|
||||
for (size_t k = 0; k < arraylen(lg_alignvals); k++) {
|
||||
bool zero = zerovals[i];
|
||||
bool zero = zerovals[i];
|
||||
size_t size = sizevals[j];
|
||||
size_t lg_align = lg_alignvals[k];
|
||||
size_t usize = nallocx(size,
|
||||
MALLOCX_LG_ALIGN(lg_align));
|
||||
size_t usize = nallocx(
|
||||
size, MALLOCX_LG_ALIGN(lg_align));
|
||||
|
||||
JUNK_FREE(free(ptr));
|
||||
JUNK_FREE(dallocx(ptr, 0));
|
||||
JUNK_FREE(dallocx(ptr, MALLOCX_TCACHE_NONE));
|
||||
JUNK_FREE(dallocx(ptr, MALLOCX_LG_ALIGN(
|
||||
lg_align)));
|
||||
JUNK_FREE(sdallocx(ptr, usize, MALLOCX_LG_ALIGN(
|
||||
lg_align)));
|
||||
JUNK_FREE(
|
||||
dallocx(ptr, MALLOCX_LG_ALIGN(lg_align)));
|
||||
JUNK_FREE(sdallocx(
|
||||
ptr, usize, MALLOCX_LG_ALIGN(lg_align)));
|
||||
JUNK_FREE(sdallocx(ptr, usize,
|
||||
MALLOCX_TCACHE_NONE | MALLOCX_LG_ALIGN(lg_align)));
|
||||
MALLOCX_TCACHE_NONE
|
||||
| MALLOCX_LG_ALIGN(lg_align)));
|
||||
if (opt_zero_realloc_action
|
||||
== zero_realloc_action_free) {
|
||||
JUNK_FREE(realloc(ptr, 0));
|
||||
|
|
@ -138,24 +137,24 @@ TEST_BEGIN(test_realloc_expand) {
|
|||
ptr = malloc(SC_SMALL_MAXCLASS);
|
||||
expanded = realloc(ptr, SC_LARGE_MINCLASS);
|
||||
expect_ptr_eq(last_junked_ptr, &expanded[SC_SMALL_MAXCLASS], "");
|
||||
expect_zu_eq(last_junked_usize,
|
||||
SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
expect_zu_eq(
|
||||
last_junked_usize, SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
free(expanded);
|
||||
|
||||
/* rallocx(..., 0) */
|
||||
ptr = malloc(SC_SMALL_MAXCLASS);
|
||||
expanded = rallocx(ptr, SC_LARGE_MINCLASS, 0);
|
||||
expect_ptr_eq(last_junked_ptr, &expanded[SC_SMALL_MAXCLASS], "");
|
||||
expect_zu_eq(last_junked_usize,
|
||||
SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
expect_zu_eq(
|
||||
last_junked_usize, SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
free(expanded);
|
||||
|
||||
/* rallocx(..., nonzero) */
|
||||
ptr = malloc(SC_SMALL_MAXCLASS);
|
||||
expanded = rallocx(ptr, SC_LARGE_MINCLASS, MALLOCX_TCACHE_NONE);
|
||||
expect_ptr_eq(last_junked_ptr, &expanded[SC_SMALL_MAXCLASS], "");
|
||||
expect_zu_eq(last_junked_usize,
|
||||
SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
expect_zu_eq(
|
||||
last_junked_usize, SC_LARGE_MINCLASS - SC_SMALL_MAXCLASS, "");
|
||||
free(expanded);
|
||||
|
||||
/* rallocx(..., MALLOCX_ZERO) */
|
||||
|
|
@ -189,7 +188,5 @@ main(void) {
|
|||
* We check the last pointer junked. If a reentrant call happens, that
|
||||
* might be an internal allocation.
|
||||
*/
|
||||
return test_no_reentrancy(
|
||||
test_junk_alloc_free,
|
||||
test_realloc_expand);
|
||||
return test_no_reentrancy(test_junk_alloc_free, test_realloc_expand);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,16 +18,13 @@ expect_no_logging(const char *names) {
|
|||
int count = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(log_l1)
|
||||
count++;
|
||||
log_do_begin(log_l1) count++;
|
||||
log_do_end(log_l1)
|
||||
|
||||
log_do_begin(log_l2)
|
||||
count++;
|
||||
log_do_begin(log_l2) count++;
|
||||
log_do_end(log_l2)
|
||||
|
||||
log_do_begin(log_l2_a)
|
||||
count++;
|
||||
log_do_begin(log_l2_a) count++;
|
||||
log_do_end(log_l2_a)
|
||||
}
|
||||
expect_d_eq(count, 0, "Disabled logging not ignored!");
|
||||
|
|
@ -57,8 +54,7 @@ TEST_BEGIN(test_log_enabled_direct) {
|
|||
count = 0;
|
||||
update_log_var_names("l1");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(log_l1)
|
||||
count++;
|
||||
log_do_begin(log_l1) count++;
|
||||
log_do_end(log_l1)
|
||||
}
|
||||
expect_d_eq(count, 10, "Mis-logged!");
|
||||
|
|
@ -66,8 +62,7 @@ TEST_BEGIN(test_log_enabled_direct) {
|
|||
count = 0;
|
||||
update_log_var_names("l1.a");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(log_l1_a)
|
||||
count++;
|
||||
log_do_begin(log_l1_a) count++;
|
||||
log_do_end(log_l1_a)
|
||||
}
|
||||
expect_d_eq(count, 10, "Mis-logged!");
|
||||
|
|
@ -75,12 +70,10 @@ TEST_BEGIN(test_log_enabled_direct) {
|
|||
count = 0;
|
||||
update_log_var_names("l1.a|abc|l2|def");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(log_l1_a)
|
||||
count++;
|
||||
log_do_begin(log_l1_a) count++;
|
||||
log_do_end(log_l1_a)
|
||||
|
||||
log_do_begin(log_l2)
|
||||
count++;
|
||||
log_do_begin(log_l2) count++;
|
||||
log_do_end(log_l2)
|
||||
}
|
||||
expect_d_eq(count, 20, "Mis-logged!");
|
||||
|
|
@ -108,28 +101,22 @@ TEST_BEGIN(test_log_enabled_indirect) {
|
|||
/* 4 are on total, so should sum to 40. */
|
||||
int count = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(log_l1)
|
||||
count++;
|
||||
log_do_begin(log_l1) count++;
|
||||
log_do_end(log_l1)
|
||||
|
||||
log_do_begin(log_l1a)
|
||||
count++;
|
||||
log_do_begin(log_l1a) count++;
|
||||
log_do_end(log_l1a)
|
||||
|
||||
log_do_begin(log_l1_a)
|
||||
count++;
|
||||
log_do_begin(log_l1_a) count++;
|
||||
log_do_end(log_l1_a)
|
||||
|
||||
log_do_begin(log_l2_a)
|
||||
count++;
|
||||
log_do_begin(log_l2_a) count++;
|
||||
log_do_end(log_l2_a)
|
||||
|
||||
log_do_begin(log_l2_b_a)
|
||||
count++;
|
||||
log_do_begin(log_l2_b_a) count++;
|
||||
log_do_end(log_l2_b_a)
|
||||
|
||||
log_do_begin(log_l2_b_b)
|
||||
count++;
|
||||
log_do_begin(log_l2_b_b) count++;
|
||||
log_do_end(log_l2_b_b)
|
||||
}
|
||||
|
||||
|
|
@ -147,12 +134,10 @@ TEST_BEGIN(test_log_enabled_global) {
|
|||
|
||||
int count = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(log_l1)
|
||||
count++;
|
||||
log_do_begin(log_l1) count++;
|
||||
log_do_end(log_l1)
|
||||
|
||||
log_do_begin(log_l2_a_a)
|
||||
count++;
|
||||
log_do_begin(log_l2_a_a) count++;
|
||||
log_do_end(log_l2_a_a)
|
||||
}
|
||||
expect_d_eq(count, 20, "Mis-logged!");
|
||||
|
|
@ -167,8 +152,7 @@ TEST_BEGIN(test_logs_if_no_init) {
|
|||
|
||||
int count = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log_do_begin(l)
|
||||
count++;
|
||||
log_do_begin(l) count++;
|
||||
log_do_end(l)
|
||||
}
|
||||
expect_d_eq(count, 0, "Logging shouldn't happen if not initialized.");
|
||||
|
|
@ -188,11 +172,7 @@ TEST_END
|
|||
|
||||
int
|
||||
main(void) {
|
||||
return test(
|
||||
test_log_disabled,
|
||||
test_log_enabled_direct,
|
||||
test_log_enabled_indirect,
|
||||
test_log_enabled_global,
|
||||
test_logs_if_no_init,
|
||||
test_log_only_format_string);
|
||||
return test(test_log_disabled, test_log_enabled_direct,
|
||||
test_log_enabled_indirect, test_log_enabled_global,
|
||||
test_logs_if_no_init, test_log_only_format_string);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue