More sallog_align test
This commit is contained in:
+22
-5
@@ -7,10 +7,14 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "ucore/ucore_utils.h"
|
#include "ucore/ucore_utils.h"
|
||||||
#include "../src/ucore_salloc.c"
|
#include "../src/ucore_salloc.c"
|
||||||
|
struct Foo {
|
||||||
// Intended to be run under valgrind. Should show no errors
|
short s1;
|
||||||
|
char b;
|
||||||
|
short s2;
|
||||||
|
int foo;
|
||||||
|
char *data;
|
||||||
|
char c;
|
||||||
|
};
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
@@ -18,10 +22,13 @@ int main(int argc, char *argv[])
|
|||||||
SAlloc *s = uc_new_salloc(1023);
|
SAlloc *s = uc_new_salloc(1023);
|
||||||
printf("Alignof double %zu\n", __alignof__(double));
|
printf("Alignof double %zu\n", __alignof__(double));
|
||||||
printf("Alignof void* %zu\n", __alignof__(void*));
|
printf("Alignof void* %zu\n", __alignof__(void*));
|
||||||
|
printf("Alignof struct Foo %zu\n", __alignof__(struct Foo));
|
||||||
for (i = 0; i < 1013; i++) {
|
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;
|
c = s->first;
|
||||||
while(c) {
|
while(c) {
|
||||||
uintptr_t p = (uintptr_t)&c->data.data[0];
|
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__(float)) * __alignof__(float) == p);
|
||||||
assert((p/__alignof__(long long)) * __alignof__(long long) == p);
|
assert((p/__alignof__(long long)) * __alignof__(long long) == p);
|
||||||
assert((p/__alignof__(void*)) * __alignof__(void*) == p);
|
assert((p/__alignof__(void*)) * __alignof__(void*) == p);
|
||||||
|
assert((p/__alignof__(double)) * __alignof__(double) == p);
|
||||||
}
|
}
|
||||||
|
|
||||||
uc_free_salloc(s);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user