Skip to content

Commit

Permalink
[wip] add a test case for fuzzing with afl (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaskalev authored Oct 20, 2023
1 parent edb3aa0 commit 92ca3ff
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file removed test-cpp-translation-unit
Binary file not shown.
42 changes: 42 additions & 0 deletions test-fuzz.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <assert.h>
#include <stdlib.h>
#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);
}
}
}

0 comments on commit 92ca3ff

Please sign in to comment.