summaryrefslogtreecommitdiffstats
path: root/test/unit/pack.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/pack.c')
-rw-r--r--test/unit/pack.c96
1 files changed, 29 insertions, 67 deletions
diff --git a/test/unit/pack.c b/test/unit/pack.c
index 991faa6..edfc548 100644
--- a/test/unit/pack.c
+++ b/test/unit/pack.c
@@ -4,21 +4,20 @@
* Size class that is a divisor of the page size, ideally 4+ regions per run.
*/
#if LG_PAGE <= 14
-#define SZ (ZU(1) << (LG_PAGE - 2))
+#define SZ (ZU(1) << (LG_PAGE - 2))
#else
-#define SZ 4096
+#define SZ ZU(4096)
#endif
/*
- * Number of chunks to consume at high water mark. Should be at least 2 so that
+ * Number of slabs to consume at high water mark. Should be at least 2 so that
* if mmap()ed memory grows downward, downward growth of mmap()ed memory is
* tested.
*/
-#define NCHUNKS 8
+#define NSLABS 8
static unsigned
-binind_compute(void)
-{
+binind_compute(void) {
size_t sz;
unsigned nbins, i;
@@ -38,17 +37,17 @@ binind_compute(void)
sz = sizeof(size);
assert_d_eq(mallctlbymib(mib, miblen, (void *)&size, &sz, NULL,
0), 0, "Unexpected mallctlbymib failure");
- if (size == SZ)
- return (i);
+ if (size == SZ) {
+ return i;
+ }
}
test_fail("Unable to compute nregs_per_run");
- return (0);
+ return 0;
}
static size_t
-nregs_per_run_compute(void)
-{
+nregs_per_run_compute(void) {
uint32_t nregs;
size_t sz;
unsigned binind = binind_compute();
@@ -61,57 +60,23 @@ nregs_per_run_compute(void)
sz = sizeof(nregs);
assert_d_eq(mallctlbymib(mib, miblen, (void *)&nregs, &sz, NULL,
0), 0, "Unexpected mallctlbymib failure");
- return (nregs);
-}
-
-static size_t
-npages_per_run_compute(void)
-{
- size_t sz;
- unsigned binind = binind_compute();
- size_t mib[4];
- size_t miblen = sizeof(mib)/sizeof(size_t);
- size_t run_size;
-
- assert_d_eq(mallctlnametomib("arenas.bin.0.run_size", mib, &miblen), 0,
- "Unexpected mallctlnametomb failure");
- mib[2] = (size_t)binind;
- sz = sizeof(run_size);
- assert_d_eq(mallctlbymib(mib, miblen, (void *)&run_size, &sz, NULL,
- 0), 0, "Unexpected mallctlbymib failure");
- return (run_size >> LG_PAGE);
-}
-
-static size_t
-npages_per_chunk_compute(void)
-{
-
- return ((chunksize >> LG_PAGE) - map_bias);
-}
-
-static size_t
-nruns_per_chunk_compute(void)
-{
-
- return (npages_per_chunk_compute() / npages_per_run_compute());
+ return nregs;
}
static unsigned
-arenas_extend_mallctl(void)
-{
+arenas_create_mallctl(void) {
unsigned arena_ind;
size_t sz;
sz = sizeof(arena_ind);
- assert_d_eq(mallctl("arenas.extend", (void *)&arena_ind, &sz, NULL, 0),
- 0, "Error in arenas.extend");
+ assert_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0),
+ 0, "Error in arenas.create");
- return (arena_ind);
+ return arena_ind;
}
static void
-arena_reset_mallctl(unsigned arena_ind)
-{
+arena_reset_mallctl(unsigned arena_ind) {
size_t mib[3];
size_t miblen = sizeof(mib)/sizeof(size_t);
@@ -122,18 +87,15 @@ arena_reset_mallctl(unsigned arena_ind)
"Unexpected mallctlbymib() failure");
}
-TEST_BEGIN(test_pack)
-{
- unsigned arena_ind = arenas_extend_mallctl();
+TEST_BEGIN(test_pack) {
+ unsigned arena_ind = arenas_create_mallctl();
size_t nregs_per_run = nregs_per_run_compute();
- size_t nruns_per_chunk = nruns_per_chunk_compute();
- size_t nruns = nruns_per_chunk * NCHUNKS;
- size_t nregs = nregs_per_run * nruns;
+ size_t nregs = nregs_per_run * NSLABS;
VARIABLE_ARRAY(void *, ptrs, nregs);
size_t i, j, offset;
/* Fill matrix. */
- for (i = offset = 0; i < nruns; i++) {
+ for (i = offset = 0; i < NSLABS; i++) {
for (j = 0; j < nregs_per_run; j++) {
void *p = mallocx(SZ, MALLOCX_ARENA(arena_ind) |
MALLOCX_TCACHE_NONE);
@@ -152,12 +114,13 @@ TEST_BEGIN(test_pack)
*/
offset = 0;
for (i = offset = 0;
- i < nruns;
+ i < NSLABS;
i++, offset = (offset + 1) % nregs_per_run) {
for (j = 0; j < nregs_per_run; j++) {
void *p = ptrs[(i * nregs_per_run) + j];
- if (offset == j)
+ if (offset == j) {
continue;
+ }
dallocx(p, MALLOCX_ARENA(arena_ind) |
MALLOCX_TCACHE_NONE);
}
@@ -169,13 +132,14 @@ TEST_BEGIN(test_pack)
*/
offset = 0;
for (i = offset = 0;
- i < nruns;
+ i < NSLABS;
i++, offset = (offset + 1) % nregs_per_run) {
for (j = 0; j < nregs_per_run; j++) {
void *p;
- if (offset == j)
+ if (offset == j) {
continue;
+ }
p = mallocx(SZ, MALLOCX_ARENA(arena_ind) |
MALLOCX_TCACHE_NONE);
assert_ptr_eq(p, ptrs[(i * nregs_per_run) + j],
@@ -190,9 +154,7 @@ TEST_BEGIN(test_pack)
TEST_END
int
-main(void)
-{
-
- return (test(
- test_pack));
+main(void) {
+ return test(
+ test_pack);
}