From 03eb37e8fd35587b944f8cbc85cd81a08b0ed17a Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Thu, 24 Sep 2015 16:44:16 -0700 Subject: [PATCH] Make mallocx() OOM test more robust. Make mallocx() OOM testing work correctly even on systems that can allocate the majority of virtual address space in a single contiguous region. --- test/integration/mallocx.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c index 3973938b..6253175d 100644 --- a/test/integration/mallocx.c +++ b/test/integration/mallocx.c @@ -52,9 +52,20 @@ TEST_BEGIN(test_oom) 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); + /* + * It should be impossible to allocate two objects that each consume + * more than 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); + } + } #if LG_SIZEOF_PTR == 3 size = ZU(0x8000000000000000);