diff --git a/test/salloc_align.c b/test/salloc_align.c new file mode 100644 index 0000000..8fbf7e3 --- /dev/null +++ b/test/salloc_align.c @@ -0,0 +1,40 @@ +#ifndef DEBUG +#define DEBUG +#endif + +#include +#include +#include +#include "ucore/ucore_utils.h" +#include "../src/ucore_salloc.c" + +// Intended to be run under valgrind. Should show no errors + + +int main(int argc, char *argv[]) +{ + size_t i; + Chunk *c; + SAlloc *s = uc_new_salloc(1023); + printf("Alignof double %zu\n", __alignof__(double)); + printf("Alignof void* %zu\n", __alignof__(void*)); + for (i = 0; i < 1013; i++) { + uc_s_alloc(s, sizeof(double)*41); + } + + c = s->first; + while(c) { + uintptr_t p = (uintptr_t)&c->data.data[0]; + printf("Chunk data %p\n", &c->data.data[0]); + c = c->next; + assert((p/__alignof__(short)) * __alignof__(short) == p); + assert((p/__alignof__(int)) * __alignof__(int) == p); + assert((p/__alignof__(float)) * __alignof__(float) == p); + assert((p/__alignof__(long long)) * __alignof__(long long) == p); + assert((p/__alignof__(void*)) * __alignof__(void*) == p); + } + + uc_free_salloc(s); + + return 0; +}