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