Pre-2.0 release, MFC 63 - HAMMER I/O error handling and catastrophic
[dragonfly.git] / tools / test / malloc / main.c
bloba3565f5db70890fe950ac1e2069a08fac4c9c636
1 /*
2 * $DragonFly: src/tools/test/malloc/main.c,v 1.2 2003/11/07 14:38:38 eirikn Exp $
3 */
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <unistd.h>
9 u_long NBUCKETS = 2000;
10 u_long NOPS = 200000;
11 u_long NSIZE = (16*1024);
13 char **foo;
15 int
16 main(int argc, char **argv)
18 int i,j,k;
20 if (argc > 1) NOPS = strtoul(argv[1],0,0);
21 if (argc > 2) NBUCKETS = strtoul(argv[2],0,0);
22 if (argc > 3) NSIZE = strtoul(argv[3],0,0);
23 printf("BRK(0)=%x ",sbrk(0));
24 foo = malloc (sizeof *foo * NBUCKETS);
25 memset(foo,0,sizeof *foo * NBUCKETS);
26 for (i = 1; i <= 4096; i+=i) {
27 for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
28 foo[j] = malloc(i);
30 for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
31 free(foo[j]);
32 foo[j] = 0;
36 for (i = 0 ; i < NOPS ; i++) {
37 j = random() % NBUCKETS;
38 k = random() % NSIZE;
39 foo[j] = realloc(foo[j], k & 1 ? 0 : k);
40 if (foo[j])
41 foo[j][0] = 1;
43 printf("BRK(1)=%x ",sbrk(0));
44 for (j = 0 ; j < NBUCKETS ; j++) {
45 if (foo[j]) {
46 free(foo[j]);
47 foo[j] = 0;
50 printf("BRK(2)=%x NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n",
51 sbrk(0),NOPS,NBUCKETS,NSIZE);
52 return 0;