diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9881820..43c93cc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,11 +14,14 @@ jobs: - name: test-main run: make LLVM_VERSION=14 working-directory: . + - name: bench-main + run: make LLVM_VERSION=14 bench + working-directory: . - name: test-multiplatform run: make test-multiplatform working-directory: . - name: test-cpp-translation-unit - run: make LLVM_VERSION=12 test-cpp-translation-unit + run: make LLVM_VERSION=14 test-cpp-translation-unit working-directory: . - uses: actions/upload-artifact@v3 if: failure() diff --git a/README.md b/README.md index fa6547d..73fc8c5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is a buddy memory allocator that might be suitable for use in applications ## Features - Bounded allocation and deallocation cost -- Fixed call stack use, no recursion +- Fixed call stack usage, no recursion, no global state - C99-compatibility for code and tests - 100% line and branch test coverage - Supports 32-bit and 64-bit platforms diff --git a/test-cpp-translation-unit b/test-cpp-translation-unit deleted file mode 100755 index 20c6be3..0000000 Binary files a/test-cpp-translation-unit and /dev/null differ diff --git a/test-fuzz.c b/test-fuzz.c new file mode 100644 index 0000000..cbc9863 --- /dev/null +++ b/test-fuzz.c @@ -0,0 +1,42 @@ +#include +#include +#define BUDDY_ALLOC_IMPLEMENTATION +#include "buddy_alloc.h" + +int main(void) +{ + unsigned char buffer[16384]; + void *allocs[255]; + unsigned char *meta = malloc(buddy_sizeof_alignment(16384, 64)); + struct buddy *b = buddy_init_alignment(meta, buffer, 16384, 64); + struct buddy_tree *tree = buddy_tree(b); + for (;;) { + int slot = getchar(); + if (slot == EOF) { + break; + } + if (allocs[slot]) { + if (getchar() % 2) { + buddy_free(b, allocs[slot]); + } else { + int size = slot*slot; + if (getchar() % 2) { + size = size/2; + } else { + size = size*2; + } + buddy_realloc(b, allocs[slot], size); + } + assert(buddy_tree_check_invariant(tree, buddy_tree_root()) == 0); + allocs[slot] = 0; + } else { + int size = getchar(); + if (size == EOF) { + break; + } + size *= size; // Exercise large slots too + allocs[slot] = buddy_malloc(b, size); + assert(buddy_tree_check_invariant(tree, buddy_tree_root()) == 0); + } + } +} \ No newline at end of file