55 lines
1.0 KiB
C
55 lines
1.0 KiB
C
#include "memory_arena.h"
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <setjmp.h>
|
|
#include <cmocka.h>
|
|
|
|
/**
|
|
* Memory arena Test
|
|
*
|
|
* At this level, the function should behave similarly to the standard lib's
|
|
* malloc, calloc, realloc, and free
|
|
*/
|
|
|
|
static int setup_mem_arena(void** state)
|
|
{
|
|
(void)state;
|
|
|
|
// Test with 8 MB
|
|
mem_arena_init(8);
|
|
return 0;
|
|
}
|
|
|
|
static int teardown_mem_arena(void** state)
|
|
{
|
|
(void)state;
|
|
|
|
mem_arena_deinit();
|
|
return 0;
|
|
}
|
|
|
|
static void test_simple_malloc(void **state)
|
|
{
|
|
(void)state;
|
|
|
|
void* buf = mem_arena_malloc(16);
|
|
|
|
assert_non_null(buf);
|
|
assert_int_equal(mem_arena_get_allocated(), 16);
|
|
mem_arena_print();
|
|
mem_arena_free(buf);
|
|
assert_int_equal(mem_arena_get_allocated(), 0);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
const struct CMUnitTest tests[] = {
|
|
cmocka_unit_test_setup_teardown(test_simple_malloc, setup_mem_arena, teardown_mem_arena),
|
|
};
|
|
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
}
|