summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2015-09-21 18:53:00 (GMT)
committerJason Evans <jasone@canonware.com>2015-09-21 18:53:00 (GMT)
commit486d249fb4715fd3de679b6c2a04f7e657883111 (patch)
treef6f9e9644f4fde5f36ca57f6c1b43d6567b1bf3b /test
parent9898051fd16ebd5d29dc27aae5e069fe04486ff3 (diff)
parentb8e966f121e55ffa0c904f9ff7d419797b872aa8 (diff)
downloadjemalloc-4.0.2.zip
jemalloc-4.0.2.tar.gz
jemalloc-4.0.2.tar.bz2
Merge branch 'dev'4.0.2
Diffstat (limited to 'test')
-rw-r--r--test/integration/mallocx.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c
index 4b0e33f..3973938 100644
--- a/test/integration/mallocx.c
+++ b/test/integration/mallocx.c
@@ -1,5 +1,74 @@
#include "test/jemalloc_test.h"
+static unsigned
+get_nsizes_impl(const char *cmd)
+{
+ unsigned ret;
+ size_t z;
+
+ z = sizeof(unsigned);
+ assert_d_eq(mallctl(cmd, &ret, &z, NULL, 0), 0,
+ "Unexpected mallctl(\"%s\", ...) failure", cmd);
+
+ return (ret);
+}
+
+static unsigned
+get_nhuge(void)
+{
+
+ return (get_nsizes_impl("arenas.nhchunks"));
+}
+
+static size_t
+get_size_impl(const char *cmd, size_t ind)
+{
+ size_t ret;
+ size_t z;
+ size_t mib[4];
+ size_t miblen = 4;
+
+ z = sizeof(size_t);
+ assert_d_eq(mallctlnametomib(cmd, mib, &miblen),
+ 0, "Unexpected mallctlnametomib(\"%s\", ...) failure", cmd);
+ mib[2] = ind;
+ z = sizeof(size_t);
+ assert_d_eq(mallctlbymib(mib, miblen, &ret, &z, NULL, 0),
+ 0, "Unexpected mallctlbymib([\"%s\", %zu], ...) failure", cmd, ind);
+
+ return (ret);
+}
+
+static size_t
+get_huge_size(size_t ind)
+{
+
+ return (get_size_impl("arenas.hchunk.0.size", ind));
+}
+
+TEST_BEGIN(test_oom)
+{
+ size_t hugemax, size, alignment;
+
+ hugemax = get_huge_size(get_nhuge()-1);
+
+ /* In practice hugemax is too large to be allocated. */
+ assert_ptr_null(mallocx(hugemax, 0),
+ "Expected OOM for mallocx(size=%#zx, 0)", hugemax);
+
+#if LG_SIZEOF_PTR == 3
+ size = ZU(0x8000000000000000);
+ alignment = ZU(0x8000000000000000);
+#else
+ size = ZU(0x80000000);
+ alignment = ZU(0x80000000);
+#endif
+ assert_ptr_null(mallocx(size, MALLOCX_ALIGN(alignment)),
+ "Expected OOM for mallocx(size=%#zx, MALLOCX_ALIGN(%#zx)", size,
+ alignment);
+}
+TEST_END
+
TEST_BEGIN(test_basic)
{
#define MAXSZ (((size_t)1) << 26)
@@ -96,6 +165,7 @@ main(void)
{
return (test(
+ test_oom,
test_basic,
test_alignment_and_size));
}