51 lines
1.8 KiB
C
51 lines
1.8 KiB
C
#include "../include/malloc.h"
|
|
#include "../src/align.h"
|
|
#include "../src/malloc.h"
|
|
#include "../src/chunk.h"
|
|
#include "../src/raw_chunk_manager.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#define NOT_NULL (void*) 55342301
|
|
|
|
void test(const void* expected_value, const void* value, const char* test_name, const char* description)
|
|
{
|
|
printf("%s ", test_name);
|
|
if ((expected_value == NOT_NULL && value != NULL) || (expected_value != NOT_NULL && expected_value == value))
|
|
printf("[OK]");
|
|
else
|
|
printf("[FAILED] %s {%p != %p}", description, expected_value, value);
|
|
printf("\n");
|
|
}
|
|
|
|
int main(int ac, char **av)
|
|
{
|
|
(void) ac;
|
|
(void) av;
|
|
|
|
printf("-----------ALIGN-----------\n");
|
|
test(0, (void*) get_align_increment(0), "align test 1", "");
|
|
test((void*) 15, (void*) get_align_increment((void*) 1), "align test 2", "");
|
|
|
|
printf("-----------ALLOC (LARGE)-----------\n");
|
|
void* ptr = ft_malloc(10000000);
|
|
ft_free(ptr);
|
|
test(NULL, allocs_tree[LARGE], "alloc free", "simple alloc, simple free");
|
|
ptr = ft_malloc(10000000);
|
|
test(ptr, ((void **) allocs_tree[LARGE])[CHUNK_DATA_START_POS], "free alloc", "alloc after a free on the first block");
|
|
ft_free(ptr);
|
|
void *ptr1 = ft_malloc(10000000);
|
|
void *ptr2 = ft_malloc(10000000);
|
|
void *ptr3 = ft_malloc(10000000);
|
|
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr1), "alloc first", "");
|
|
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr2), "alloc second", "");
|
|
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr3), "alloc third", "");
|
|
ft_free(ptr1);
|
|
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr2), "free disorder1", "");
|
|
ft_free(ptr3);
|
|
test(NOT_NULL, raw_get_chunk(allocs_tree[LARGE], ptr2), "free disorder2", "");
|
|
ft_free(ptr2);
|
|
test(NULL, allocs_tree[LARGE], "free disorder3", "");
|
|
|
|
return 0;
|
|
} |