1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <assert.h> 4 5 #include "../smalloc.h" 6 #include "../flist.h" 7 8 FILE *f_err; 9 struct timeval *fio_tv = NULL; 10 unsigned int fio_debug = 0; 11 12 #define MAGIC1 0xa9b1c8d2 13 #define MAGIC2 0xf0a1e9b3 14 15 #define LOOPS 32 16 17 struct elem { 18 unsigned int magic1; 19 struct flist_head list; 20 unsigned int magic2; 21 }; 22 23 FLIST_HEAD(list); 24 25 static int do_rand_allocs(void) 26 { 27 unsigned int size, nr, rounds = 0; 28 unsigned long total; 29 struct elem *e; 30 31 while (rounds++ < LOOPS) { 32 #ifdef STEST_SEED 33 srand(MAGIC1); 34 #endif 35 nr = total = 0; 36 while (total < 128*1024*1024UL) { 37 size = 8 * sizeof(struct elem) + (int) (999.0 * (rand() / (RAND_MAX + 1.0))); 38 e = smalloc(size); 39 if (!e) { 40 printf("fail at %lu, size %u\n", total, size); 41 break; 42 } 43 e->magic1 = MAGIC1; 44 e->magic2 = MAGIC2; 45 total += size; 46 flist_add_tail(&e->list, &list); 47 nr++; 48 } 49 50 printf("Got items: %u\n", nr); 51 52 while (!flist_empty(&list)) { 53 e = flist_entry(list.next, struct elem, list); 54 assert(e->magic1 == MAGIC1); 55 assert(e->magic2 == MAGIC2); 56 flist_del(&e->list); 57 sfree(e); 58 } 59 } 60 61 return 0; 62 } 63 64 static int do_specific_alloc(unsigned long size) 65 { 66 void *ptr; 67 68 ptr = smalloc(size); 69 sfree(ptr); 70 return 0; 71 } 72 73 int main(int argc, char *argv[]) 74 { 75 f_err = stderr; 76 77 sinit(); 78 79 do_rand_allocs(); 80 81 /* smalloc bug, commit 271067a6 */ 82 do_specific_alloc(671386584); 83 84 scleanup(); 85 return 0; 86 } 87 88 void __dprint(int type, const char *str, ...) 89 { 90 } 91