]>
git.proxmox.com Git - mirror_frr.git/blob - tests/test-memory.c
6849b9dcebefa0db94231994ee4ed71fe4b8e13a
2 * This file is part of Quagga.
4 * Quagga is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
9 * Quagga is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Quagga; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 DEFINE_MGROUP(TEST_MEMORY
, "memory test")
24 DEFINE_MTYPE_STATIC(TEST_MEMORY
, TEST
, "generic test mtype")
26 /* Memory torture tests
28 * Tests below are generic but comments are focused on interaction with
29 * Paul's proposed memory 'quick' cache, which may never be included in
33 struct thread_master
*master
;
35 #if 0 /* set to 1 to use system alloc directly */
40 #define XMALLOC(T,S) malloc((S))
41 #define XCALLOC(T,S) calloc(1, (S))
42 #define XREALLOC(T,P,S) realloc((P),(S))
43 #define XFREE(T,P) free((P))
49 main(int argc
, char **argv
)
54 printf ("malloc x, malloc x, free, malloc x, free free\n\n");
55 /* simple case, test cache */
56 for (i
= 0; i
< TIMES
; i
++)
58 a
[0] = XMALLOC (MTYPE_TEST
, 1024);
59 memset (a
[0], 1, 1024);
60 a
[1] = XMALLOC (MTYPE_TEST
, 1024);
61 memset (a
[1], 1, 1024);
62 XFREE(MTYPE_TEST
, a
[0]); /* should go to cache */
63 a
[0] = XMALLOC (MTYPE_TEST
, 1024); /* should be satisfied from cache */
64 XFREE(MTYPE_TEST
, a
[0]);
65 XFREE(MTYPE_TEST
, a
[1]);
68 printf ("malloc x, malloc y, free x, malloc y, free free\n\n");
69 /* cache should go invalid, valid, invalid, etc.. */
70 for (i
= 0; i
< TIMES
; i
++)
72 a
[0] = XMALLOC (MTYPE_TEST
, 512);
73 memset (a
[0], 1, 512);
74 a
[1] = XMALLOC (MTYPE_TEST
, 1024); /* invalidate cache */
75 memset (a
[1], 1, 1024);
76 XFREE(MTYPE_TEST
, a
[0]);
77 a
[0] = XMALLOC (MTYPE_TEST
, 1024);
78 XFREE(MTYPE_TEST
, a
[0]);
79 XFREE(MTYPE_TEST
, a
[1]);
80 /* cache should become valid again on next request */
83 printf ("calloc\n\n");
85 for (i
= 0; i
< TIMES
; i
++)
87 a
[0] = XCALLOC (MTYPE_TEST
, 1024);
88 memset (a
[0], 1, 1024);
89 a
[1] = XCALLOC (MTYPE_TEST
, 512); /* invalidate cache */
90 memset (a
[1], 1, 512);
91 XFREE(MTYPE_TEST
, a
[1]);
92 XFREE(MTYPE_TEST
, a
[0]);
93 /* alloc == 0, cache can become valid again on next request */
96 printf ("calloc and realloc\n\n");
97 /* check calloc + realloc */
98 for (i
= 0; i
< TIMES
; i
++)
100 printf ("calloc a0 1024\n");
101 a
[0] = XCALLOC (MTYPE_TEST
, 1024);
102 memset (a
[0], 1, 1024/2);
104 printf ("calloc 1 1024\n");
105 a
[1] = XCALLOC (MTYPE_TEST
, 1024);
106 memset (a
[1], 1, 1024/2);
108 printf ("realloc 0 1024\n");
109 a
[3] = XREALLOC (MTYPE_TEST
, a
[0], 2048); /* invalidate cache */
112 memset (a
[0], 1, 1024);
114 printf ("calloc 2 512\n");
115 a
[2] = XCALLOC (MTYPE_TEST
, 512);
116 memset (a
[2], 1, 512);
118 printf ("free 1 0 2\n");
119 XFREE(MTYPE_TEST
, a
[1]);
120 XFREE(MTYPE_TEST
, a
[0]);
121 XFREE(MTYPE_TEST
, a
[2]);
122 /* alloc == 0, cache valid next request */