inet6: require RTF_ANNOUNCE to proxy NS
[dragonfly.git] / tools / test / malloc / main.c
blob4a018739a74a8ed23fdc4e699d884286d88b69c2
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
5 u_long NBUCKETS = 2000;
6 u_long NOPS = 200000;
7 u_long NSIZE = (16*1024);
9 char **foo;
11 int
12 main(int argc, char **argv)
14 int i,j,k;
16 if (argc > 1) NOPS = strtoul(argv[1],0,0);
17 if (argc > 2) NBUCKETS = strtoul(argv[2],0,0);
18 if (argc > 3) NSIZE = strtoul(argv[3],0,0);
19 printf("BRK(0)=%x ",sbrk(0));
20 foo = malloc (sizeof *foo * NBUCKETS);
21 memset(foo,0,sizeof *foo * NBUCKETS);
22 for (i = 1; i <= 4096; i+=i) {
23 for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
24 foo[j] = malloc(i);
26 for (j = 0 ; j < 40960/i && j < NBUCKETS; j++) {
27 free(foo[j]);
28 foo[j] = NULL;
32 for (i = 0 ; i < NOPS ; i++) {
33 j = random() % NBUCKETS;
34 k = random() % NSIZE;
35 foo[j] = realloc(foo[j], k & 1 ? 0 : k);
36 if (foo[j])
37 foo[j][0] = 1;
39 printf("BRK(1)=%x ",sbrk(0));
40 for (j = 0 ; j < NBUCKETS ; j++) {
41 if (foo[j]) {
42 free(foo[j]);
43 foo[j] = NULL;
46 printf("BRK(2)=%x NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n",
47 sbrk(0),NOPS,NBUCKETS,NSIZE);
48 return 0;