add: tiny

This commit is contained in:
2024-07-30 19:16:15 +02:00
parent fe833fbfcb
commit 545c02c8f8
11 changed files with 153 additions and 46 deletions

View File

@ -19,6 +19,7 @@ void test(const void* expected_value, const void* value, const char* test_name,
int main(int ac, char **av)
{
void *ptr, *ptr1, *ptr2, *ptr3;
(void) ac;
(void) av;
@ -27,15 +28,15 @@ int main(int ac, char **av)
test((void*) 15, (void*) get_align_increment((void*) 1), "align test 2", "");
printf("-----------ALLOC (LARGE)-----------\n");
void* ptr = ft_malloc(10000000);
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);
ptr1 = ft_malloc(10000000);
ptr2 = ft_malloc(10000000);
ptr3 = ft_malloc(10000000);
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr1) == NULL), "alloc first", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr2) == NULL), "alloc second", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[LARGE], ptr3) == NULL), "alloc third", "");
@ -46,5 +47,29 @@ int main(int ac, char **av)
ft_free(ptr2);
test(NULL, allocs_tree[LARGE], "free disorder3", "");
printf("-----------ALLOC (TINY)-----------\n");
ptr = ft_malloc(4);
ft_free(ptr);
test(NULL, allocs_tree[TINY], "alloc free", "simple alloc, simple free");
ptr = ft_malloc(4);
test(ptr, ((void **) allocs_tree[TINY])[CHUNK_DATA_START_POS], "free alloc", "alloc after a free on the first block");
ft_free(ptr);
ptr1 = ft_malloc(4);
ptr2 = ft_malloc(4);
ptr3 = ft_malloc(4);
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[TINY], ptr1) == NULL), "alloc first", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[TINY], ptr2) == NULL), "alloc second", "");
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[TINY], ptr3) == NULL), "alloc third", "");
show_alloc_mem();
ft_free(ptr1);
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[TINY], ptr2) == NULL), "free disorder1", "");
ft_free(ptr3);
test(0, (const void*) (uintptr_t) (raw_get_chunk(allocs_tree[TINY], ptr2) == NULL), "free disorder2", "");
show_alloc_mem();
ft_free(ptr2);
show_alloc_mem();
test(NULL, allocs_tree[TINY], "free disorder3", "");
return 0;
}