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
0c516a00c4
(Make *allocx() size class
overflow behavior defined.).
This resolves #379.
This commit is contained in:
parent
108c4a11e9
commit
9aa1543e9c
@ -69,19 +69,28 @@ TEST_END
|
|||||||
|
|
||||||
TEST_BEGIN(test_oom)
|
TEST_BEGIN(test_oom)
|
||||||
{
|
{
|
||||||
|
size_t hugemax;
|
||||||
|
bool oom;
|
||||||
|
void *ptrs[3];
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It should be impossible to allocate two objects that each consume
|
* It should be impossible to allocate three objects that each consume
|
||||||
* more than half the virtual address space.
|
* nearly half the virtual address space.
|
||||||
*/
|
*/
|
||||||
{
|
hugemax = get_huge_size(get_nhuge()-1);
|
||||||
size_t hugemax = get_huge_size(get_nhuge()-1);
|
oom = false;
|
||||||
void *p = mallocx(hugemax, 0);
|
for (i = 0; i < sizeof(ptrs) / sizeof(void *); i++) {
|
||||||
if (p != NULL) {
|
ptrs[i] = mallocx(hugemax, 0);
|
||||||
assert_ptr_null(mallocx(hugemax, 0),
|
if (ptrs[i] == NULL)
|
||||||
"Expected OOM for mallocx(size=%#zx, 0)", hugemax);
|
oom = true;
|
||||||
dallocx(p, 0);
|
}
|
||||||
}
|
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
|
#if LG_SIZEOF_PTR == 3
|
||||||
|
Loading…
Reference in New Issue
Block a user