summaryrefslogtreecommitdiffstats
path: root/test/integration
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2016-05-04 00:34:40 (GMT)
committerJason Evans <jasone@canonware.com>2016-05-04 00:34:40 (GMT)
commite02b83cc5e3c4d30f93dba945162e3aa58d962d6 (patch)
treedc1cf37bd624061c6351ea3a78f993d2a19310ac /test/integration
parentdf900dbfaf4835d3efc06d771535f3e781544913 (diff)
parent2e5eb21184cccabc829265b5f5237f3c13563be6 (diff)
downloadjemalloc-4.1.1.zip
jemalloc-4.1.1.tar.gz
jemalloc-4.1.1.tar.bz2
Merge branch.4.1.1
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/chunk.c73
-rw-r--r--test/integration/mallocx.c31
2 files changed, 63 insertions, 41 deletions
diff --git a/test/integration/chunk.c b/test/integration/chunk.c
index af1c9a5..ff9bf96 100644
--- a/test/integration/chunk.c
+++ b/test/integration/chunk.c
@@ -121,6 +121,10 @@ TEST_BEGIN(test_chunk)
{
void *p;
size_t old_size, new_size, large0, large1, huge0, huge1, huge2, sz;
+ unsigned arena_ind;
+ int flags;
+ size_t hooks_mib[3], purge_mib[3];
+ size_t hooks_miblen, purge_miblen;
chunk_hooks_t new_hooks = {
chunk_alloc,
chunk_dalloc,
@@ -132,10 +136,19 @@ TEST_BEGIN(test_chunk)
};
bool xallocx_success_a, xallocx_success_b, xallocx_success_c;
+ sz = sizeof(unsigned);
+ assert_d_eq(mallctl("arenas.extend", &arena_ind, &sz, NULL, 0), 0,
+ "Unexpected mallctl() failure");
+ flags = MALLOCX_ARENA(arena_ind) | MALLOCX_TCACHE_NONE;
+
/* Install custom chunk hooks. */
+ hooks_miblen = sizeof(hooks_mib)/sizeof(size_t);
+ assert_d_eq(mallctlnametomib("arena.0.chunk_hooks", hooks_mib,
+ &hooks_miblen), 0, "Unexpected mallctlnametomib() failure");
+ hooks_mib[1] = (size_t)arena_ind;
old_size = sizeof(chunk_hooks_t);
new_size = sizeof(chunk_hooks_t);
- assert_d_eq(mallctl("arena.0.chunk_hooks", &old_hooks, &old_size,
+ assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, &old_hooks, &old_size,
&new_hooks, new_size), 0, "Unexpected chunk_hooks error");
orig_hooks = old_hooks;
assert_ptr_ne(old_hooks.alloc, chunk_alloc, "Unexpected alloc error");
@@ -165,45 +178,49 @@ TEST_BEGIN(test_chunk)
"Unexpected arenas.hchunk.2.size failure");
/* Test dalloc/decommit/purge cascade. */
+ purge_miblen = sizeof(purge_mib)/sizeof(size_t);
+ assert_d_eq(mallctlnametomib("arena.0.purge", purge_mib, &purge_miblen),
+ 0, "Unexpected mallctlnametomib() failure");
+ purge_mib[1] = (size_t)arena_ind;
do_dalloc = false;
do_decommit = false;
- p = mallocx(huge0 * 2, 0);
+ p = mallocx(huge0 * 2, flags);
assert_ptr_not_null(p, "Unexpected mallocx() error");
did_dalloc = false;
did_decommit = false;
did_purge = false;
did_split = false;
- xallocx_success_a = (xallocx(p, huge0, 0, 0) == huge0);
- assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
- "Unexpected arena.0.purge error");
+ xallocx_success_a = (xallocx(p, huge0, 0, flags) == huge0);
+ assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0),
+ 0, "Unexpected arena.%u.purge error", arena_ind);
if (xallocx_success_a) {
assert_true(did_dalloc, "Expected dalloc");
assert_false(did_decommit, "Unexpected decommit");
assert_true(did_purge, "Expected purge");
}
assert_true(did_split, "Expected split");
- dallocx(p, 0);
+ dallocx(p, flags);
do_dalloc = true;
/* Test decommit/commit and observe split/merge. */
do_dalloc = false;
do_decommit = true;
- p = mallocx(huge0 * 2, 0);
+ p = mallocx(huge0 * 2, flags);
assert_ptr_not_null(p, "Unexpected mallocx() error");
did_decommit = false;
did_commit = false;
did_split = false;
did_merge = false;
- xallocx_success_b = (xallocx(p, huge0, 0, 0) == huge0);
- assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
- "Unexpected arena.0.purge error");
+ xallocx_success_b = (xallocx(p, huge0, 0, flags) == huge0);
+ assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0),
+ 0, "Unexpected arena.%u.purge error", arena_ind);
if (xallocx_success_b)
assert_true(did_split, "Expected split");
- xallocx_success_c = (xallocx(p, huge0 * 2, 0, 0) == huge0 * 2);
+ xallocx_success_c = (xallocx(p, huge0 * 2, 0, flags) == huge0 * 2);
assert_b_eq(did_decommit, did_commit, "Expected decommit/commit match");
if (xallocx_success_b && xallocx_success_c)
assert_true(did_merge, "Expected merge");
- dallocx(p, 0);
+ dallocx(p, flags);
do_dalloc = true;
do_decommit = false;
@@ -214,42 +231,42 @@ TEST_BEGIN(test_chunk)
* successful xallocx() from size=huge2 to size=huge1 is
* guaranteed to leave trailing purgeable memory.
*/
- p = mallocx(huge2, 0);
+ p = mallocx(huge2, flags);
assert_ptr_not_null(p, "Unexpected mallocx() error");
did_purge = false;
- assert_zu_eq(xallocx(p, huge1, 0, 0), huge1,
+ assert_zu_eq(xallocx(p, huge1, 0, flags), huge1,
"Unexpected xallocx() failure");
assert_true(did_purge, "Expected purge");
- dallocx(p, 0);
+ dallocx(p, flags);
}
/* Test decommit for large allocations. */
do_decommit = true;
- p = mallocx(large1, 0);
+ p = mallocx(large1, flags);
assert_ptr_not_null(p, "Unexpected mallocx() error");
- assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
- "Unexpected arena.0.purge error");
+ assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0),
+ 0, "Unexpected arena.%u.purge error", arena_ind);
did_decommit = false;
- assert_zu_eq(xallocx(p, large0, 0, 0), large0,
+ assert_zu_eq(xallocx(p, large0, 0, flags), large0,
"Unexpected xallocx() failure");
- assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
- "Unexpected arena.0.purge error");
+ assert_d_eq(mallctlbymib(purge_mib, purge_miblen, NULL, NULL, NULL, 0),
+ 0, "Unexpected arena.%u.purge error", arena_ind);
did_commit = false;
- assert_zu_eq(xallocx(p, large1, 0, 0), large1,
+ assert_zu_eq(xallocx(p, large1, 0, flags), large1,
"Unexpected xallocx() failure");
assert_b_eq(did_decommit, did_commit, "Expected decommit/commit match");
- dallocx(p, 0);
+ dallocx(p, flags);
do_decommit = false;
/* Make sure non-huge allocation succeeds. */
- p = mallocx(42, 0);
+ p = mallocx(42, flags);
assert_ptr_not_null(p, "Unexpected mallocx() error");
- dallocx(p, 0);
+ dallocx(p, flags);
/* Restore chunk hooks. */
- assert_d_eq(mallctl("arena.0.chunk_hooks", NULL, NULL, &old_hooks,
- new_size), 0, "Unexpected chunk_hooks error");
- assert_d_eq(mallctl("arena.0.chunk_hooks", &old_hooks, &old_size,
+ assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, NULL, NULL,
+ &old_hooks, new_size), 0, "Unexpected chunk_hooks error");
+ assert_d_eq(mallctlbymib(hooks_mib, hooks_miblen, &old_hooks, &old_size,
NULL, 0), 0, "Unexpected chunk_hooks error");
assert_ptr_eq(old_hooks.alloc, orig_hooks.alloc,
"Unexpected alloc error");
diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c
index 42eee10..c185cc6 100644
--- a/test/integration/mallocx.c
+++ b/test/integration/mallocx.c
@@ -70,22 +70,27 @@ TEST_END
TEST_BEGIN(test_oom)
{
size_t hugemax, size, alignment;
-
- hugemax = get_huge_size(get_nhuge()-1);
+ bool oom;
+ void *ptrs[3];
+ unsigned i;
/*
- * It should be impossible to allocate two objects that each consume
- * more than half the virtual address space.
+ * It should be impossible to allocate three objects that each consume
+ * nearly half the virtual address space.
*/
- {
- void *p;
-
- p = mallocx(hugemax, 0);
- if (p != NULL) {
- assert_ptr_null(mallocx(hugemax, 0),
- "Expected OOM for mallocx(size=%#zx, 0)", hugemax);
- dallocx(p, 0);
- }
+ hugemax = get_huge_size(get_nhuge()-1);
+ oom = false;
+ for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
+ ptrs[i] = mallocx(hugemax, 0);
+ if (ptrs[i] == NULL)
+ oom = true;
+ }
+ assert_true(oom,
+ "Expected OOM during series of calls to mallocx(size=%zu, 0)",
+ hugemax);
+ for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
+ if (ptrs[i] != NULL)
+ dallocx(ptrs[i], 0);
}
#if LG_SIZEOF_PTR == 3