5 #include "../smalloc.h"
7 #include "../arch/arch.h"
10 #define MAGIC1 0xa9b1c8d2
11 #define MAGIC2 0xf0a1e9b3
14 #define MAXSMALLOC 120*1024*1024UL
15 #define LARGESMALLOC 128*1024U
19 struct flist_head list;
24 static FLIST_HEAD(list);
26 static int do_rand_allocs(void)
28 unsigned int i, size, nr, rounds = 0, ret = 0;
34 while (rounds++ < LOOPS) {
40 while (total < MAXSMALLOC) {
41 size = 8 * sizeof(struct elem) + (int) (999.0 * (rand() / (RAND_MAX + 1.0)));
44 printf("fail at %lu, size %u\n", total, size);
50 for (i = 0; i < size; i++) {
52 printf("buffer not cleared at %lu, size %u\n", total, size);
58 /* stop the while loop if buffer was not cleared */
66 flist_add_tail(&e->list, &list);
70 printf("Got items: %u\n", nr);
72 while (!flist_empty(&list)) {
73 e = flist_entry(list.next, struct elem, list);
74 assert(e->magic1 == MAGIC1);
75 assert(e->magic2 == MAGIC2);
81 e = scalloc(1, LARGESMALLOC);
84 printf("failure allocating %u bytes at %lu allocated during sfree phase\n",
90 for (i = 0; i < LARGESMALLOC; i++) {
94 printf("large buffer not cleared at %lu, size %u\n", total, size);
107 int main(int argc, char *argv[])
115 ret = do_rand_allocs();
116 smalloc_debug(0); /* TODO: check that free and total blocks