summaryrefslogtreecommitdiffstats
path: root/test/integration/mallocx.c
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2017-06-13 19:49:58 (GMT)
committerJason Evans <jasone@canonware.com>2017-06-13 19:51:09 (GMT)
commit5018fe3f0979b7f9db9930accdf7ee31071fd703 (patch)
tree894055b5ff4ccde3d9d782861d45af4664f12ad2 /test/integration/mallocx.c
parent04380e79f1e2428bd0ad000bbc6e3d2dfc6b66a5 (diff)
parentba29113e5a58caeb6b4a65b1db6d8efae79cae45 (diff)
downloadjemalloc-5.0.0.zip
jemalloc-5.0.0.tar.gz
jemalloc-5.0.0.tar.bz2
Merge branch 'dev'5.0.0
Diffstat (limited to 'test/integration/mallocx.c')
-rw-r--r--test/integration/mallocx.c80
1 files changed, 35 insertions, 45 deletions
diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c
index 5a9058d..b0b5cda 100644
--- a/test/integration/mallocx.c
+++ b/test/integration/mallocx.c
@@ -1,8 +1,7 @@
#include "test/jemalloc_test.h"
static unsigned
-get_nsizes_impl(const char *cmd)
-{
+get_nsizes_impl(const char *cmd) {
unsigned ret;
size_t z;
@@ -10,19 +9,16 @@ get_nsizes_impl(const char *cmd)
assert_d_eq(mallctl(cmd, (void *)&ret, &z, NULL, 0), 0,
"Unexpected mallctl(\"%s\", ...) failure", cmd);
- return (ret);
+ return ret;
}
static unsigned
-get_nhuge(void)
-{
-
- return (get_nsizes_impl("arenas.nhchunks"));
+get_nlarge(void) {
+ return get_nsizes_impl("arenas.nlextents");
}
static size_t
-get_size_impl(const char *cmd, size_t ind)
-{
+get_size_impl(const char *cmd, size_t ind) {
size_t ret;
size_t z;
size_t mib[4];
@@ -36,14 +32,12 @@ get_size_impl(const char *cmd, size_t ind)
assert_d_eq(mallctlbymib(mib, miblen, (void *)&ret, &z, NULL, 0),
0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
- return (ret);
+ return ret;
}
static size_t
-get_huge_size(size_t ind)
-{
-
- return (get_size_impl("arenas.hchunk.0.size", ind));
+get_large_size(size_t ind) {
+ return get_size_impl("arenas.lextent.0.size", ind);
}
/*
@@ -52,21 +46,18 @@ get_huge_size(size_t ind)
* potential OOM on e.g. 32-bit Windows.
*/
static void
-purge(void)
-{
-
+purge(void) {
assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
"Unexpected mallctl error");
}
-TEST_BEGIN(test_overflow)
-{
- size_t hugemax;
+TEST_BEGIN(test_overflow) {
+ size_t largemax;
- hugemax = get_huge_size(get_nhuge()-1);
+ largemax = get_large_size(get_nlarge()-1);
- assert_ptr_null(mallocx(hugemax+1, 0),
- "Expected OOM for mallocx(size=%#zx, 0)", hugemax+1);
+ assert_ptr_null(mallocx(largemax+1, 0),
+ "Expected OOM for mallocx(size=%#zx, 0)", largemax+1);
assert_ptr_null(mallocx(ZU(PTRDIFF_MAX)+1, 0),
"Expected OOM for mallocx(size=%#zx, 0)", ZU(PTRDIFF_MAX)+1);
@@ -80,9 +71,8 @@ TEST_BEGIN(test_overflow)
}
TEST_END
-TEST_BEGIN(test_oom)
-{
- size_t hugemax;
+TEST_BEGIN(test_oom) {
+ size_t largemax;
bool oom;
void *ptrs[3];
unsigned i;
@@ -91,19 +81,21 @@ TEST_BEGIN(test_oom)
* It should be impossible to allocate three objects that each consume
* nearly half the virtual address space.
*/
- hugemax = get_huge_size(get_nhuge()-1);
+ largemax = get_large_size(get_nlarge()-1);
oom = false;
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
- ptrs[i] = mallocx(hugemax, 0);
- if (ptrs[i] == NULL)
+ ptrs[i] = mallocx(largemax, 0);
+ if (ptrs[i] == NULL) {
oom = true;
+ }
}
assert_true(oom,
"Expected OOM during series of calls to mallocx(size=%zu, 0)",
- hugemax);
+ largemax);
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
- if (ptrs[i] != NULL)
+ if (ptrs[i] != NULL) {
dallocx(ptrs[i], 0);
+ }
}
purge();
@@ -121,9 +113,8 @@ TEST_BEGIN(test_oom)
}
TEST_END
-TEST_BEGIN(test_basic)
-{
-#define MAXSZ (((size_t)1) << 23)
+TEST_BEGIN(test_basic) {
+#define MAXSZ (((size_t)1) << 23)
size_t sz;
for (sz = 1; sz < MAXSZ; sz = nallocx(sz, 0) + 1) {
@@ -159,16 +150,16 @@ TEST_BEGIN(test_basic)
}
TEST_END
-TEST_BEGIN(test_alignment_and_size)
-{
-#define MAXALIGN (((size_t)1) << 23)
-#define NITER 4
+TEST_BEGIN(test_alignment_and_size) {
+#define MAXALIGN (((size_t)1) << 23)
+#define NITER 4
size_t nsz, rsz, sz, alignment, total;
unsigned i;
void *ps[NITER];
- for (i = 0; i < NITER; i++)
+ for (i = 0; i < NITER; i++) {
ps[i] = NULL;
+ }
for (alignment = 8;
alignment <= MAXALIGN;
@@ -201,8 +192,9 @@ TEST_BEGIN(test_alignment_and_size)
" alignment=%zu, size=%zu", ps[i],
alignment, sz);
total += rsz;
- if (total >= (MAXALIGN << 1))
+ if (total >= (MAXALIGN << 1)) {
break;
+ }
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
@@ -219,12 +211,10 @@ TEST_BEGIN(test_alignment_and_size)
TEST_END
int
-main(void)
-{
-
- return (test(
+main(void) {
+ return test(
test_overflow,
test_oom,
test_basic,
- test_alignment_and_size));
+ test_alignment_and_size);
}