diff options
Diffstat (limited to 'malloc/malloc/tests')
| -rwxr-xr-x | malloc/malloc/tests/corruptionproof | bin | 0 -> 16632 bytes | |||
| -rwxr-xr-x | malloc/malloc/tests/memoryfootprint | bin | 0 -> 18064 bytes | |||
| -rwxr-xr-x | malloc/malloc/tests/speed | bin | 0 -> 17280 bytes | |||
| -rwxr-xr-x | malloc/malloc/tests/tests.sh | 3 | ||||
| -rw-r--r-- | malloc/malloc/tests/unit.c | 161 |
5 files changed, 164 insertions, 0 deletions
diff --git a/malloc/malloc/tests/corruptionproof b/malloc/malloc/tests/corruptionproof Binary files differnew file mode 100755 index 0000000..26ebc81 --- /dev/null +++ b/malloc/malloc/tests/corruptionproof diff --git a/malloc/malloc/tests/memoryfootprint b/malloc/malloc/tests/memoryfootprint Binary files differnew file mode 100755 index 0000000..1718375 --- /dev/null +++ b/malloc/malloc/tests/memoryfootprint diff --git a/malloc/malloc/tests/speed b/malloc/malloc/tests/speed Binary files differnew file mode 100755 index 0000000..a1026c8 --- /dev/null +++ b/malloc/malloc/tests/speed diff --git a/malloc/malloc/tests/tests.sh b/malloc/malloc/tests/tests.sh new file mode 100755 index 0000000..7993b2e --- /dev/null +++ b/malloc/malloc/tests/tests.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo aaaaa diff --git a/malloc/malloc/tests/unit.c b/malloc/malloc/tests/unit.c new file mode 100644 index 0000000..e30c2da --- /dev/null +++ b/malloc/malloc/tests/unit.c @@ -0,0 +1,161 @@ +#include <criterion/assert.h> +#include <criterion/criterion.h> +#include <stdio.h> + +#include "utils.h" +#include "wrapper.h" + +void print_header(struct header *h) +{ + if (!h) + return; + printf("------------- Header %p -----------\n", (void *)h); + printf("Free: %s\n", h->free ? "Yes" : "No"); + printf("Previous header: %p\n", (void *)h->prev); + printf("Next header: %p\n", (void *)h->next); + printf("Data size: %zu\n", h->size); + printf("??????????? Data ????????????\n"); + if (h->free) + { + printf("Unknown data\n"); + } + else + { + void *d = h; + char *data = d; + data += align(sizeof(struct header), sizeof(long double)); + printf("%s\n", data); + } +} + +void print_headers(struct header *h) +{ + if (!h) + return; + struct header *first = h; + while (first) + { + print_header(first); + first = first->next; + } +} + +void print_page(struct page *p) +{ + if (!p) + return; + printf("############## Page %p ##############\n", (void *)p); + printf("Previous page: %p\n", (void *)p->prev); + printf("Next page: %p\n", (void *)p->next); + printf("Page size: %zu\n", p->size); + print_headers(p->blocks); +} + +void print_pages(struct page *p) +{ + if (!p) + { + printf("No pages mapped\n"); + return; + } + printf("***************************************************************\n"); + struct page *first = p; + while (first) + { + print_page(first); + first = first->next; + } +} + +TestSuite(utils); + +Test(utils, next_pow1) +{ + size_t input = 1; + size_t expected = 1; + size_t actual = next_pow(input); + cr_expect(expected == actual, "Expected %zu, got %zu", expected, actual); +} + +Test(utils, next_pow3) +{ + size_t input = 3; + size_t expected = 4; + size_t actual = next_pow(input); + cr_expect(expected == actual, "Expected %zu, got %zu", expected, actual); +} + +Test(utils, next_pow720) +{ + size_t input = 720; + size_t expected = 1024; + size_t actual = next_pow(input); + cr_expect(expected == actual, "Expected %zu, got %zu", expected, actual); +} + +TestSuite(paging); + +Test(paging, pegging_one) +{ + int ret = add_page(5); + struct page *p = get_pages(); + cr_expect(ret, "add_page failed"); + ret = add_page(10000); + // cr_expect(ret, "add_page failed"); + ret = add_page(5000); + ret = add_page(42); + cr_expect(ret, "add_page failed"); + print_pages(get_pages()); + ret = remove_page(p); + cr_expect(ret, "remove_page failed"); + print_pages(get_pages()); + struct header *h = find_free(5000); + print_header(h); + h = find_free(100000); + cr_expect(h == NULL, "NULL expected, segfault incoming"); + h = find_free(42); + print_header(h); + print_pages(get_pages()); + printf(" / \\\n"); + printf(" / | \\\n"); + printf(" /__.__\\ SPLITTING\n"); + split_chunk(h, 25); + print_pages(get_pages()); + h->free = 1; + fuse(h); + print_pages(get_pages()); + while ((p = get_pages())) + remove_page(p); +} + +TestSuite(alloc); + +Test(alloc, malloc_simple) +{ + printf("//////////////////// Tests alloc ///////////////////\n"); + char *s = my_malloc(4); + s[0] = 'a'; + s[1] = 'c'; + s[2] = 'u'; + s[3] = '\0'; + printf("%s\n", s); + printf("Freeing...\n"); + print_pages(get_pages()); + printf("//////////////////// Fin tests alloc ///////////////////\n"); +} + +Test(alloc, malloc_stresstest) +{ + printf("\nSTRESSTEST \n"); + void *t = my_malloc(10000000); + cr_assert(t, "malloc returned NULL"); + my_free(t); + t = my_malloc(10000000); + void *r = my_malloc(4000000); + print_pages(get_pages()); + my_free(t); + print_pages(get_pages()); + my_free(r); + print_pages(get_pages()); + printf("\nEND STRESSTEST \n"); +} |
