diff --git a/test/salloc_align.c b/test/salloc_align.c index 8fbf7e3..389d19a 100644 --- a/test/salloc_align.c +++ b/test/salloc_align.c @@ -7,10 +7,14 @@ #include #include "ucore/ucore_utils.h" #include "../src/ucore_salloc.c" - -// Intended to be run under valgrind. Should show no errors - - +struct Foo { + short s1; + char b; + short s2; + int foo; + char *data; + char c; +}; int main(int argc, char *argv[]) { size_t i; @@ -18,10 +22,13 @@ int main(int argc, char *argv[]) SAlloc *s = uc_new_salloc(1023); printf("Alignof double %zu\n", __alignof__(double)); printf("Alignof void* %zu\n", __alignof__(void*)); + printf("Alignof struct Foo %zu\n", __alignof__(struct Foo)); for (i = 0; i < 1013; i++) { - uc_s_alloc(s, sizeof(double)*41); + uintptr_t p = (uintptr_t)uc_s_alloc(s, sizeof(double)*41); + assert((p/__alignof__(double)) * __alignof__(double) == p); } + c = s->first; while(c) { uintptr_t p = (uintptr_t)&c->data.data[0]; @@ -32,9 +39,19 @@ int main(int argc, char *argv[]) assert((p/__alignof__(float)) * __alignof__(float) == p); assert((p/__alignof__(long long)) * __alignof__(long long) == p); assert((p/__alignof__(void*)) * __alignof__(void*) == p); + assert((p/__alignof__(double)) * __alignof__(double) == p); } uc_free_salloc(s); + s = uc_new_salloc(141); + for (i = 0; i < 1013; i++) { + uintptr_t p = (uintptr_t)uc_s_alloc(s, sizeof(struct Foo)); + assert((p/__alignof__(struct Foo)) * __alignof__(struct Foo) == p); + } + + uc_free_salloc(s); + + return 0; }