Files
libucore/test/salloc_align.c
T
2013-01-16 21:04:21 +01:00

41 lines
1.0 KiB
C

#ifndef DEBUG
#define DEBUG
#endif
#include <string.h>
#include <stdio.h>
#include <assert.h>
#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;
}