1 #include "alloc/alloc.h"
3 #include "alloc/alloc.c"
8 #define POOL_SIZE (1 << POOL_ORD)
10 static void invert_bytes(unsigned char *p, unsigned long size)
14 for (i = 0; i < size; i++)
18 static bool sizes_ok(void *mem, unsigned long poolsize, void *p[], unsigned num)
22 for (i = 0; i < num; i++)
23 if (alloc_size(mem, poolsize, p[i]) < i)
28 int main(int argc, char *argv[])
36 /* FIXME: Needs to be page aligned for now. */
37 posix_memalign(&mem, 1 << POOL_ORD, POOL_SIZE);
39 alloc_init(mem, POOL_SIZE);
41 /* Check that alloc_size() gives reasonable answers. */
42 for (i = 0; i < POOL_SIZE; i++) {
43 p[i] = alloc_get(mem, POOL_SIZE, i, 1);
46 invert_bytes(p[i], alloc_size(mem, POOL_SIZE, p[i]));
50 ok1(alloc_check(mem, POOL_SIZE));
51 ok1(sizes_ok(mem, POOL_SIZE, p, num));
53 /* Free every second one. */
54 for (i = 0; i < num; i+=2) {
55 alloc_free(mem, POOL_SIZE, p[i]);
59 invert_bytes(p[i/2], alloc_size(mem,POOL_SIZE,p[i/2]));
63 ok1(alloc_check(mem, POOL_SIZE));
64 ok1(sizes_ok(mem, POOL_SIZE, p, num));