summaryrefslogtreecommitdiff
path: root/deps/jemalloc/test/integration/posix_memalign.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/jemalloc/test/integration/posix_memalign.c')
-rw-r--r--deps/jemalloc/test/integration/posix_memalign.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/deps/jemalloc/test/integration/posix_memalign.c b/deps/jemalloc/test/integration/posix_memalign.c
index 19741c6cb..2c2726de8 100644
--- a/deps/jemalloc/test/integration/posix_memalign.c
+++ b/deps/jemalloc/test/integration/posix_memalign.c
@@ -1,12 +1,19 @@
#include "test/jemalloc_test.h"
-#define CHUNK 0x400000
-/* #define MAXALIGN ((size_t)UINT64_C(0x80000000000)) */
-#define MAXALIGN ((size_t)0x2000000LU)
-#define NITER 4
+#define MAXALIGN (((size_t)1) << 23)
-TEST_BEGIN(test_alignment_errors)
-{
+/*
+ * On systems which can't merge extents, tests that call this function generate
+ * a lot of dirty memory very quickly. Purging between cycles mitigates
+ * potential OOM on e.g. 32-bit Windows.
+ */
+static void
+purge(void) {
+ assert_d_eq(mallctl("arena.0.purge", NULL, NULL, NULL, 0), 0,
+ "Unexpected mallctl error");
+}
+
+TEST_BEGIN(test_alignment_errors) {
size_t alignment;
void *p;
@@ -25,8 +32,7 @@ TEST_BEGIN(test_alignment_errors)
}
TEST_END
-TEST_BEGIN(test_oom_errors)
-{
+TEST_BEGIN(test_oom_errors) {
size_t alignment, size;
void *p;
@@ -64,15 +70,16 @@ TEST_BEGIN(test_oom_errors)
}
TEST_END
-TEST_BEGIN(test_alignment_and_size)
-{
+TEST_BEGIN(test_alignment_and_size) {
+#define NITER 4
size_t alignment, size, total;
unsigned i;
int err;
void *ps[NITER];
- for (i = 0; i < NITER; i++)
+ for (i = 0; i < NITER; i++) {
ps[i] = NULL;
+ }
for (alignment = 8;
alignment <= MAXALIGN;
@@ -94,8 +101,9 @@ TEST_BEGIN(test_alignment_and_size)
alignment, size, size, buf);
}
total += malloc_usable_size(ps[i]);
- if (total >= (MAXALIGN << 1))
+ if (total >= (MAXALIGN << 1)) {
break;
+ }
}
for (i = 0; i < NITER; i++) {
if (ps[i] != NULL) {
@@ -104,16 +112,16 @@ TEST_BEGIN(test_alignment_and_size)
}
}
}
+ purge();
}
+#undef NITER
}
TEST_END
int
-main(void)
-{
-
- return (test(
+main(void) {
+ return test(
test_alignment_errors,
test_oom_errors,
- test_alignment_and_size));
+ test_alignment_and_size);
}