1#include "mem/tests/test_internal.h"
2#include <math/units.h>
3
4TEST_DEFINE_UNIT(mem, valloc_zero_large_reuse) {
5 const size_t size = KIB(64);
6 for (uint32_t iteration = 0; iteration < 32; iteration++) {
7 uint8_t *buffer = valloc(size, ALLOC_ZERO,
8 .behavior = ALLOC_BEHAVIOR_NORMAL |
9 ALLOC_BEHAVIOR_FLAG_MINIMAL);
10 TEST_ASSERT_NONNULL(buffer);
11 bool zero = true;
12 for (size_t i = 0; i < size; i++)
13 if (buffer[i] != 0) {
14 zero = false;
15 break;
16 }
17
18 /* Dirty the allocation before returning it */
19 memset(buffer, 0xa5, size);
20 vfree(buffer);
21 TEST_ASSERT_MSG(zero, "nonzero allocation on iteration %u", iteration);
22 }
23 return TEST_SUCCESS;
24}
25