aboutsummaryrefslogtreecommitdiff
path: root/src/tests/slab_test.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-09 17:39:41 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-09 17:40:03 +0100
commitf2c51bc81d2aa618b29ddbeaae5ac1c5308821f0 (patch)
treefae67a79d5e60128d074550326a05216694a5848 /src/tests/slab_test.c
parenta5dfdd2b3fa91a2cda4f807c88bd35928e3c7a61 (diff)
downloadkogata-f2c51bc81d2aa618b29ddbeaae5ac1c5308821f0.tar.gz
kogata-f2c51bc81d2aa618b29ddbeaae5ac1c5308821f0.zip
Reorganize all.
Diffstat (limited to 'src/tests/slab_test.c')
-rw-r--r--src/tests/slab_test.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tests/slab_test.c b/src/tests/slab_test.c
new file mode 100644
index 0000000..747c785
--- /dev/null
+++ b/src/tests/slab_test.c
@@ -0,0 +1,44 @@
+#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;
+}
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/