blob: 2bc2493b7ef62b891eb6d3cb7e1083a6954c2b7e [file] [log] [blame]
Seyi Kuforijic143dfa2025-01-17 13:29:24 +01001#include "unit-test.h"
2#include "mem-pool.h"
3
4static 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
17void test_mem_pool__big_block(void)
18{
19 test_many_pool_allocations(1024 * 1024);
20}
21
22void test_mem_pool__tiny_block(void)
23{
24 test_many_pool_allocations(1);
25}