Add alignment tests for prof stats

This commit is contained in:
Yinan Zhang 2020-08-26 16:48:59 -07:00
parent 54f3351f1f
commit 4352cbc21c

View File

@ -1,8 +1,10 @@
#include "test/jemalloc_test.h" #include "test/jemalloc_test.h"
static void
test_wrapper(szind_t ind) {
#define N_PTRS 3 #define N_PTRS 3
static void
test_combinations(szind_t ind, size_t sizes_array[N_PTRS],
int flags_array[N_PTRS]) {
#define MALLCTL_STR_LEN 64 #define MALLCTL_STR_LEN 64
assert(opt_prof && opt_prof_stats); assert(opt_prof && opt_prof_stats);
@ -36,10 +38,12 @@ test_wrapper(szind_t ind) {
uint64_t accum_req_sum = 0; uint64_t accum_req_sum = 0;
uint64_t accum_count = 0; uint64_t accum_count = 0;
for (size_t i = 0, sz = sz_index2size(ind) - N_PTRS; i < N_PTRS; for (size_t i = 0; i < N_PTRS; ++i) {
++i, ++sz) { size_t sz = sizes_array[i];
void *p = malloc(sz); int flags = flags_array[i];
void *p = mallocx(sz, flags);
assert_ptr_not_null(p, "malloc() failed"); assert_ptr_not_null(p, "malloc() failed");
assert(malloc_usable_size(p) == sz_index2size(ind));
ptrs[i] = p; ptrs[i] = p;
live_req_sum += sz; live_req_sum += sz;
live_count++; live_count++;
@ -61,9 +65,10 @@ test_wrapper(szind_t ind) {
accum_count, ""); accum_count, "");
} }
for (size_t i = 0, sz = sz_index2size(ind) - N_PTRS; i < N_PTRS; for (size_t i = 0; i < N_PTRS; ++i) {
++i, ++sz) { size_t sz = sizes_array[i];
free(ptrs[i]); int flags = flags_array[i];
sdallocx(ptrs[i], sz, flags);
live_req_sum -= sz; live_req_sum -= sz;
live_count--; live_count--;
uint64_t live_stats[2]; uint64_t live_stats[2];
@ -82,22 +87,65 @@ test_wrapper(szind_t ind) {
accum_count, ""); accum_count, "");
} }
#undef MALLCTL_STR_LEN #undef MALLCTL_STR_LEN
#undef N_PTRS }
static void
test_szind_wrapper(szind_t ind) {
size_t sizes_array[N_PTRS];
int flags_array[N_PTRS];
for (size_t i = 0, sz = sz_index2size(ind) - N_PTRS; i < N_PTRS;
++i, ++sz) {
sizes_array[i] = sz;
flags_array[i] = 0;
}
test_combinations(ind, sizes_array, flags_array);
} }
TEST_BEGIN(test_prof_stats) { TEST_BEGIN(test_prof_stats) {
test_skip_if(!config_prof); test_skip_if(!config_prof);
test_wrapper(0); test_szind_wrapper(0);
test_wrapper(1); test_szind_wrapper(1);
test_wrapper(2); test_szind_wrapper(2);
test_wrapper(SC_NBINS); test_szind_wrapper(SC_NBINS);
test_wrapper(SC_NBINS + 1); test_szind_wrapper(SC_NBINS + 1);
test_wrapper(SC_NBINS + 2); test_szind_wrapper(SC_NBINS + 2);
}
TEST_END
static void
test_szind_aligned_wrapper(szind_t ind, unsigned lg_align) {
size_t sizes_array[N_PTRS];
int flags_array[N_PTRS];
int flags = MALLOCX_LG_ALIGN(lg_align);
for (size_t i = 0, sz = sz_index2size(ind) - N_PTRS; i < N_PTRS;
++i, ++sz) {
sizes_array[i] = sz;
flags_array[i] = flags;
}
test_combinations(
sz_size2index(sz_sa2u(sz_index2size(ind), 1 << lg_align)),
sizes_array, flags_array);
}
TEST_BEGIN(test_prof_stats_aligned) {
test_skip_if(!config_prof);
for (szind_t ind = 0; ind < 10; ++ind) {
for (unsigned lg_align = 0; lg_align < 10; ++lg_align) {
test_szind_aligned_wrapper(ind, lg_align);
}
}
for (szind_t ind = SC_NBINS - 5; ind < SC_NBINS + 5; ++ind) {
for (unsigned lg_align = SC_LG_LARGE_MINCLASS - 5;
lg_align < SC_LG_LARGE_MINCLASS + 5; ++lg_align) {
test_szind_aligned_wrapper(ind, lg_align);
}
}
} }
TEST_END TEST_END
int int
main(void) { main(void) {
return test( return test(
test_prof_stats); test_prof_stats,
test_prof_stats_aligned);
} }