diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-06 18:39:12 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2014-12-06 18:39:12 +0100 |
commit | ff27e3d5ca61fb6234b0876dc3368d0e5dfc5a95 (patch) | |
tree | e7945b5cae3925ae50082da7b80e9b3caf914fa4 /kernel/lib_tests | |
parent | 274765f7daa3cc1094f9f26196fcf2b9a5289ee2 (diff) | |
download | kogata-ff27e3d5ca61fb6234b0876dc3368d0e5dfc5a95.tar.gz kogata-ff27e3d5ca61fb6234b0876dc3368d0e5dfc5a95.zip |
Trying to track an annoying bug.
Diffstat (limited to 'kernel/lib_tests')
-rw-r--r-- | kernel/lib_tests/Makefile | 2 | ||||
-rw-r--r-- | kernel/lib_tests/slab_test.c | 42 |
2 files changed, 44 insertions, 0 deletions
diff --git a/kernel/lib_tests/Makefile b/kernel/lib_tests/Makefile new file mode 100644 index 0000000..4a21edf --- /dev/null +++ b/kernel/lib_tests/Makefile @@ -0,0 +1,2 @@ +slab_test.bin: slab_test.c ../include/slab_alloc.h ../lib/slab_alloc.c + gcc -m32 -o $@ -std=c99 -I ../include slab_test.c ../lib/slab_alloc.c diff --git a/kernel/lib_tests/slab_test.c b/kernel/lib_tests/slab_test.c new file mode 100644 index 0000000..4bfc6b0 --- /dev/null +++ b/kernel/lib_tests/slab_test.c @@ -0,0 +1,42 @@ +#include <slab_alloc.h> +#include <stdlib.h> +#include <stdio.h> + +slab_type_t slab_sizes[] = { + { "8B obj", 8, 1 }, + { "16B obj", 16, 2 }, + { "32B obj", 32, 2 }, + { "64B obj", 64, 2 }, + { "128B obj", 128, 2 }, + { "256B obj", 256, 4 }, + { "512B obj", 512, 4 }, + { "1KB obj", 1024, 8 }, + { "2KB obj", 2048, 8 }, + { "4KB obj", 4096, 16 }, + { 0, 0, 0 } +}; + + +int main(int argc, char *argv[]) { + mem_allocator_t *a = + create_slab_allocator(slab_sizes, malloc, free); + + const int m = 10000; + uint32_t* ptr[m]; + for (int i = 0; i < m; i++) { + size_t s = 1 << ((i * 7) % 12 + 2); + ptr[i] = (uint32_t*)slab_alloc(a, s); + ASSERT(ptr[i] != 0); + *ptr[i] = ((i * 2117) % (1<<30)); + printf("Alloc %i : 0x%p\n", s, ptr[i]); + } + for (int i = 0; i < m; i++) { + for (int j = i; j < m; j++) { + ASSERT(*ptr[j] == (j * 2117) % (1<<30)); + } + slab_free(a, ptr[i]); + } + destroy_slab_allocator(a); + + return 0; +} |