diff options
| author | nodist <kevin.comas.git@gmail.com> | 2026-10-12 11:06:37 -0400 |
|---|---|---|
| committer | nodist <kevin.comas.git@gmail.com> | 2026-10-12 11:06:37 -0400 |
| commit | 332c114cf633f70027c28ec6bedb898d9de85e51 (patch) | |
| tree | 0a9bb4760772e5e407c1aef9b896d65165f82f6c /test/memory.c | |
| parent | 4ee5b8d6a9ebf49ce30ff7d93ef7401039ffecc6 (diff) | |
basic allocator with valgrind testing
Diffstat (limited to 'test/memory.c')
| -rw-r--r-- | test/memory.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/memory.c b/test/memory.c new file mode 100644 index 0000000..05db8a2 --- /dev/null +++ b/test/memory.c @@ -0,0 +1,19 @@ + +#include "kpl_test.h" + +KPL_TEST(allocate) { + kpl_memory_allocator allocator = {}; + kpl_memory_allocator_init(&allocator); + for (int32_t times = 0; times < 700; times++) { + kpl_object *objects[10] = {}; + for (int32_t object = 0; object < 10; object++) { + objects[object] = kpl_memory_allocator_allocate(&allocator, 32, KPL_THREAD_MAIN_ID); + KPL_ASSERT(objects[object]->object_size == 32, "Invalid size for 32 byte object"); + } + for (int32_t object = 0; object < 10; object++) + kpl_memory_allocator_return(&allocator, objects[object]); + } + kpl_memory_allocator_slab_group *slab_group32 = &allocator.slabs[5]; + KPL_ASSERT(slab_group32->slab_head == slab_group32->slab_tail, "Only one slab should have been allocated"); + kpl_memory_allocator_free(&allocator); +} |
