From 44d12d435aba23c4a99af1dddf20e1777690b348 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 3 May 2016 09:37:54 -0700 Subject: [PATCH] Update mallocx() OOM test to deal with smaller hugemax. Depending on virtual memory resource limits, it is necessary to attempt allocating three maximally sized objects to trigger OOM rather than just two, since the maximum supported size is slightly less than half the total virtual memory address space. This fixes a test failure that was introduced by 0c516a00c4cb28cff55ce0995f756b5aae074c9e (Make *allocx() size class overflow behavior defined.). This resolves #379. --- test/integration/mallocx.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/test/integration/mallocx.c b/test/integration/mallocx.c index 42eee105..c185cc63 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