4 /* Memory torture tests
6 * Tests below are generic but comments are focused on interaction with
7 * Paul's proposed memory 'quick' cache, which may never be included in
11 struct thread_master
*master
;
13 #if 0 /* set to 1 to use system alloc directly */
18 #define XMALLOC(T,S) malloc((S))
19 #define XCALLOC(T,S) calloc(1, (S))
20 #define XREALLOC(T,P,S) realloc((P),(S))
21 #define XFREE(T,P) free((P))
27 main(int argc
, char **argv
)
32 printf ("malloc x, malloc x, free, malloc x, free free\n\n");
33 /* simple case, test cache */
34 for (i
= 0; i
< TIMES
; i
++)
36 a
[0] = XMALLOC (MTYPE_VTY
, 1024);
37 memset (a
[0], 1, 1024);
38 a
[1] = XMALLOC (MTYPE_VTY
, 1024);
39 memset (a
[1], 1, 1024);
40 XFREE(MTYPE_VTY
, a
[0]); /* should go to cache */
41 a
[0] = XMALLOC (MTYPE_VTY
, 1024); /* should be satisfied from cache */
42 XFREE(MTYPE_VTY
, a
[0]);
43 XFREE(MTYPE_VTY
, a
[1]);
46 printf ("malloc x, malloc y, free x, malloc y, free free\n\n");
47 /* cache should go invalid, valid, invalid, etc.. */
48 for (i
= 0; i
< TIMES
; i
++)
50 a
[0] = XMALLOC (MTYPE_VTY
, 512);
51 memset (a
[0], 1, 512);
52 a
[1] = XMALLOC (MTYPE_VTY
, 1024); /* invalidate cache */
53 memset (a
[1], 1, 1024);
54 XFREE(MTYPE_VTY
, a
[0]);
55 a
[0] = XMALLOC (MTYPE_VTY
, 1024);
56 XFREE(MTYPE_VTY
, a
[0]);
57 XFREE(MTYPE_VTY
, a
[1]);
58 /* cache should become valid again on next request */
61 printf ("calloc\n\n");
63 for (i
= 0; i
< TIMES
; i
++)
65 a
[0] = XCALLOC (MTYPE_VTY
, 1024);
66 memset (a
[0], 1, 1024);
67 a
[1] = XCALLOC (MTYPE_VTY
, 512); /* invalidate cache */
68 memset (a
[1], 1, 512);
69 XFREE(MTYPE_VTY
, a
[1]);
70 XFREE(MTYPE_VTY
, a
[0]);
71 /* alloc == 0, cache can become valid again on next request */
74 printf ("calloc and realloc\n\n");
75 /* check calloc + realloc */
76 for (i
= 0; i
< TIMES
; i
++)
78 printf ("calloc a0 1024\n");
79 a
[0] = XCALLOC (MTYPE_VTY
, 1024);
80 memset (a
[0], 1, 1024/2);
82 printf ("calloc 1 1024\n");
83 a
[1] = XCALLOC (MTYPE_VTY
, 1024);
84 memset (a
[1], 1, 1024/2);
86 printf ("realloc 0 1024\n");
87 a
[3] = XREALLOC (MTYPE_VTY
, a
[0], 2048); /* invalidate cache */
90 memset (a
[0], 1, 1024);
92 printf ("calloc 2 512\n");
93 a
[2] = XCALLOC (MTYPE_VTY
, 512);
94 memset (a
[2], 1, 512);
96 printf ("free 1 0 2\n");
97 XFREE(MTYPE_VTY
, a
[1]);
98 XFREE(MTYPE_VTY
, a
[0]);
99 XFREE(MTYPE_VTY
, a
[2]);
100 /* alloc == 0, cache valid next request */