redict/deps/jemalloc/test/integration/sdallocx.c

56 lines
1.0 KiB
C
Raw Normal View History

2015-10-06 10:18:30 -04:00
#include "test/jemalloc_test.h"
2018-05-24 11:17:37 -04:00
#define MAXALIGN (((size_t)1) << 22)
#define NITER 3
2015-10-06 10:18:30 -04:00
2018-05-24 11:17:37 -04:00
TEST_BEGIN(test_basic) {
2015-10-06 10:18:30 -04:00
void *ptr = mallocx(64, 0);
sdallocx(ptr, 64, 0);
}
TEST_END
2018-05-24 11:17:37 -04:00
TEST_BEGIN(test_alignment_and_size) {
2015-10-06 10:18:30 -04:00
size_t nsz, sz, alignment, total;
unsigned i;
void *ps[NITER];
2018-05-24 11:17:37 -04:00
for (i = 0; i < NITER; i++) {
2015-10-06 10:18:30 -04:00
ps[i] = NULL;
2018-05-24 11:17:37 -04:00
}
2015-10-06 10:18:30 -04:00
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 (i = 0; i < NITER; i++) {
nsz = nallocx(sz, MALLOCX_ALIGN(alignment) |
MALLOCX_ZERO);
ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) |
MALLOCX_ZERO);
total += nsz;
2018-05-24 11:17:37 -04:00
if (total >= (MAXALIGN << 1)) {
2015-10-06 10:18:30 -04:00
break;
2018-05-24 11:17:37 -04:00
}
2015-10-06 10:18:30 -04:00
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
sdallocx(ps[i], sz,
MALLOCX_ALIGN(alignment));
ps[i] = NULL;
}
}
}
}
}
TEST_END
int
2018-05-24 11:17:37 -04:00
main(void) {
return test_no_reentrancy(
2015-10-06 10:18:30 -04:00
test_basic,
2018-05-24 11:17:37 -04:00
test_alignment_and_size);
2015-10-06 10:18:30 -04:00
}