diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2015-05-29 05:48:31 +0200 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-09-19 16:31:04 -0400 |
| commit | 4a1ab8e4050a141d3d7a80b5f8bb27dfd045dae8 (patch) | |
| tree | 14b33d958cb88df6195994c78ee74b781e7968a6 /tests/test-memory.c | |
| parent | fc7948fafee457874a21aa955c56a617b563f85c (diff) | |
*: split & distribute memtypes and stop (re|ab)using lib/ MTYPEs
This is a rather large mechanical commit that splits up the memory types
defined in lib/memtypes.c and distributes them into *_memory.[ch] files
in the individual daemons.
The zebra change is slightly annoying because there is no nice place to
put the #include "zebra_memory.h" statement.
bgpd, ospf6d, isisd and some tests were reusing MTYPEs defined in the
library for its own use. This is bad practice and would break when the
memtype are made static.
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
[CF: rebased for cmaster-next]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Diffstat (limited to 'tests/test-memory.c')
| -rw-r--r-- | tests/test-memory.c | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/tests/test-memory.c b/tests/test-memory.c index 807249ea6d..6849b9dceb 100644 --- a/tests/test-memory.c +++ b/tests/test-memory.c @@ -20,6 +20,9 @@ #include <zebra.h> #include <memory.h> +DEFINE_MGROUP(TEST_MEMORY, "memory test") +DEFINE_MTYPE_STATIC(TEST_MEMORY, TEST, "generic test mtype") + /* Memory torture tests * * Tests below are generic but comments are focused on interaction with @@ -52,28 +55,28 @@ main(int argc, char **argv) /* simple case, test cache */ for (i = 0; i < TIMES; i++) { - a[0] = XMALLOC (MTYPE_VTY, 1024); + a[0] = XMALLOC (MTYPE_TEST, 1024); memset (a[0], 1, 1024); - a[1] = XMALLOC (MTYPE_VTY, 1024); + a[1] = XMALLOC (MTYPE_TEST, 1024); memset (a[1], 1, 1024); - XFREE(MTYPE_VTY, a[0]); /* should go to cache */ - a[0] = XMALLOC (MTYPE_VTY, 1024); /* should be satisfied from cache */ - XFREE(MTYPE_VTY, a[0]); - XFREE(MTYPE_VTY, a[1]); + XFREE(MTYPE_TEST, a[0]); /* should go to cache */ + a[0] = XMALLOC (MTYPE_TEST, 1024); /* should be satisfied from cache */ + XFREE(MTYPE_TEST, a[0]); + XFREE(MTYPE_TEST, a[1]); } printf ("malloc x, malloc y, free x, malloc y, free free\n\n"); /* cache should go invalid, valid, invalid, etc.. */ for (i = 0; i < TIMES; i++) { - a[0] = XMALLOC (MTYPE_VTY, 512); + a[0] = XMALLOC (MTYPE_TEST, 512); memset (a[0], 1, 512); - a[1] = XMALLOC (MTYPE_VTY, 1024); /* invalidate cache */ + a[1] = XMALLOC (MTYPE_TEST, 1024); /* invalidate cache */ memset (a[1], 1, 1024); - XFREE(MTYPE_VTY, a[0]); - a[0] = XMALLOC (MTYPE_VTY, 1024); - XFREE(MTYPE_VTY, a[0]); - XFREE(MTYPE_VTY, a[1]); + XFREE(MTYPE_TEST, a[0]); + a[0] = XMALLOC (MTYPE_TEST, 1024); + XFREE(MTYPE_TEST, a[0]); + XFREE(MTYPE_TEST, a[1]); /* cache should become valid again on next request */ } @@ -81,12 +84,12 @@ main(int argc, char **argv) /* test calloc */ for (i = 0; i < TIMES; i++) { - a[0] = XCALLOC (MTYPE_VTY, 1024); + a[0] = XCALLOC (MTYPE_TEST, 1024); memset (a[0], 1, 1024); - a[1] = XCALLOC (MTYPE_VTY, 512); /* invalidate cache */ + a[1] = XCALLOC (MTYPE_TEST, 512); /* invalidate cache */ memset (a[1], 1, 512); - XFREE(MTYPE_VTY, a[1]); - XFREE(MTYPE_VTY, a[0]); + XFREE(MTYPE_TEST, a[1]); + XFREE(MTYPE_TEST, a[0]); /* alloc == 0, cache can become valid again on next request */ } @@ -95,27 +98,27 @@ main(int argc, char **argv) for (i = 0; i < TIMES; i++) { printf ("calloc a0 1024\n"); - a[0] = XCALLOC (MTYPE_VTY, 1024); + a[0] = XCALLOC (MTYPE_TEST, 1024); memset (a[0], 1, 1024/2); printf ("calloc 1 1024\n"); - a[1] = XCALLOC (MTYPE_VTY, 1024); + a[1] = XCALLOC (MTYPE_TEST, 1024); memset (a[1], 1, 1024/2); printf ("realloc 0 1024\n"); - a[3] = XREALLOC (MTYPE_VTY, a[0], 2048); /* invalidate cache */ + a[3] = XREALLOC (MTYPE_TEST, a[0], 2048); /* invalidate cache */ if (a[3] != NULL) a[0] = a[3]; memset (a[0], 1, 1024); printf ("calloc 2 512\n"); - a[2] = XCALLOC (MTYPE_VTY, 512); + a[2] = XCALLOC (MTYPE_TEST, 512); memset (a[2], 1, 512); printf ("free 1 0 2\n"); - XFREE(MTYPE_VTY, a[1]); - XFREE(MTYPE_VTY, a[0]); - XFREE(MTYPE_VTY, a[2]); + XFREE(MTYPE_TEST, a[1]); + XFREE(MTYPE_TEST, a[0]); + XFREE(MTYPE_TEST, a[2]); /* alloc == 0, cache valid next request */ } return 0; |
