Seyi Kuforiji | c143dfa | 2025-01-17 13:29:24 +0100 | [diff] [blame] | 1 | #include "unit-test.h" |
| 2 | #include "mem-pool.h" |
| 3 | |
| 4 | static void test_many_pool_allocations(size_t block_alloc) |
| 5 | { |
| 6 | struct mem_pool pool = { .block_alloc = block_alloc }; |
| 7 | size_t size = 100; |
| 8 | char *buffer = mem_pool_calloc(&pool, 1, size); |
| 9 | for (size_t i = 0; i < size; i++) |
| 10 | cl_assert_equal_i(0, buffer[i]); |
| 11 | cl_assert(pool.mp_block != NULL); |
| 12 | cl_assert(pool.mp_block->next_free != NULL); |
| 13 | cl_assert(pool.mp_block->end != NULL); |
| 14 | mem_pool_discard(&pool, 0); |
| 15 | } |
| 16 | |
| 17 | void test_mem_pool__big_block(void) |
| 18 | { |
| 19 | test_many_pool_allocations(1024 * 1024); |
| 20 | } |
| 21 | |
| 22 | void test_mem_pool__tiny_block(void) |
| 23 | { |
| 24 | test_many_pool_allocations(1); |
| 25 | } |