1 #include "tests/malloc.h"
4 #include <unistd.h> // getopt()
8 static int s_quiet
= 0;
11 #if defined(HAVE_MALLINFO)
12 static size_t check(size_t min
, size_t max
)
21 printf("arena = %d\n", mi
.arena
); /* non-mmapped space allocated from system */
22 printf("ordblks = %d\n", mi
.ordblks
); /* number of free chunks */
23 printf("smblks = %d\n", mi
.smblks
); /* number of fastbin blocks */
24 printf("hblks = %d\n", mi
.hblks
); /* number of mmapped regions */
25 printf("hblkhd = %d\n", mi
.hblkhd
); /* space in mmapped regions */
26 printf("usmblks = %d\n", mi
.usmblks
); /* maximum total allocated space */
27 printf("fsmblks = %d\n", mi
.fsmblks
); /* space available in freed fastbin blocks */
28 printf("uordblks = %d\n", mi
.uordblks
); /* total allocated space */
29 printf("fordblks = %d\n", mi
.fordblks
); /* total free space */
30 printf("keepcost = %d\n", mi
.keepcost
); /* top-most, releasable (via malloc_trim) space */
31 printf("(min = %zu, max = %zu)\n", min
, max
);
36 used
= mi
.uordblks
+ mi
.hblkhd
;
43 // used should be reasonably close to min
44 // define "reasonably" as within 20%
49 if ((mi
.ordblks
== 0) != (mi
.fordblks
== 0))
52 if ((mi
.smblks
== 0) != (mi
.fsmblks
== 0))
55 if ((mi
.hblks
== 0) != (mi
.hblkhd
== 0))
58 if (mi
.keepcost
> mi
.fordblks
)
61 if (mi
.fsmblks
> mi
.fordblks
)
64 // arena should be reasonably close to fordblks + uordblks
65 if (mi
.arena
< mi
.fordblks
+ mi
.uordblks
)
68 if (mi
.arena
/5*4 > mi
.fordblks
+ mi
.uordblks
)
74 static size_t check(size_t min
, size_t max
)
78 printf("mallinfo() is not supported on this platform.\n");
85 int main(int argc
, char** argv
)
92 while ((optchar
= getopt(argc
, argv
, "q")) != EOF
)
100 fprintf(stderr
, "Usage: %s [-q].\n", argv
[0]);
106 for (i
= 1; i
<= 40; i
++)
108 int size
= i
* i
* 8;
110 ptr
[i
- 1] = malloc(size
);
113 max
= check(min
, (size_t)-1);
115 for (i
= 1; i
<= 20; i
++)
117 int size
= i
* i
* 8;
125 for ( ; i
<= 40; i
++)
130 fprintf(stderr
, "Success.\n");