aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/test/test.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2023-03-16 16:55:38 +0000
committerFlorin Coras <florin.coras@gmail.com>2023-03-17 16:34:06 +0000
commitc7d3a5b9688e094fde987d0caff2bfb826e7e4e1 (patch)
treed4f87a4d7b8e80fb21c5cc817b862f68e9b55190 /src/vppinfra/test/test.c
parentf8b61fb538046e287063864349d43e98b62b5faf (diff)
vppinfra: auto-free test memory
Type: improvement Change-Id: Ibc40a02c8c45fc8d9409c9a86fea7aaf70d9c048 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/test/test.c')
-rw-r--r--src/vppinfra/test/test.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/vppinfra/test/test.c b/src/vppinfra/test/test.c
index 15ea6fd2973..194d725611a 100644
--- a/src/vppinfra/test/test.c
+++ b/src/vppinfra/test/test.c
@@ -39,6 +39,9 @@ test_funct (test_main_t *tm)
goto next;
err = (r->fn) (0);
fformat (stdout, "%-50s %s\n", r->name, err ? "FAIL" : "PASS");
+ for (int i = 0; i < vec_len (tm->allocated_mem); i++)
+ clib_mem_free (tm->allocated_mem[i]);
+ vec_free (tm->allocated_mem);
if (err)
{
clib_error_report (err);
@@ -141,6 +144,9 @@ test_perf (test_main_t *tm)
clib_perfmon_reset (ctx);
pt->fn (pt);
clib_perfmon_capture (ctx, pt->n_ops, "%0s", pt->name);
+ for (int i = 0; i < vec_len (tm->allocated_mem); i++)
+ clib_mem_free (tm->allocated_mem[i]);
+ vec_free (tm->allocated_mem);
}
}
while ((++pt)->fn);
@@ -209,6 +215,7 @@ test_mem_alloc (uword size)
size = round_pow2 (size, CLIB_CACHE_LINE_BYTES);
rv = clib_mem_alloc_aligned (size, CLIB_CACHE_LINE_BYTES);
clib_memset_u8 (rv, 0, size);
+ vec_add1 (test_main.allocated_mem, rv);
return rv;
}
@@ -221,6 +228,7 @@ test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask)
rv = clib_mem_alloc_aligned (size, CLIB_CACHE_LINE_BYTES);
for (uword i = 0; i < size; i++)
rv[i] = ((u8) i + start) & mask;
+ vec_add1 (test_main.allocated_mem, rv);
return rv;
}
@@ -239,11 +247,7 @@ test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt)
if (data_size < alloc_size)
clib_memset_u8 (e, 0, alloc_size - data_size);
+ vec_add1 (test_main.allocated_mem, rv);
return rv;
}
-void
-test_mem_free (void *p)
-{
- clib_mem_free (p);
-}