summaryrefslogtreecommitdiffstats
path: root/src
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
parentf8b61fb538046e287063864349d43e98b62b5faf (diff)
vppinfra: auto-free test memory
Type: improvement Change-Id: Ibc40a02c8c45fc8d9409c9a86fea7aaf70d9c048 Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vppinfra/test/ip_csum.c10
-rw-r--r--src/vppinfra/test/sha2.c4
-rw-r--r--src/vppinfra/test/test.c14
-rw-r--r--src/vppinfra/test/test.h2
-rw-r--r--src/vppinfra/test/toeplitz.c39
5 files changed, 10 insertions, 59 deletions
diff --git a/src/vppinfra/test/ip_csum.c b/src/vppinfra/test/ip_csum.c
index 9387336ad7d..b8508ee449d 100644
--- a/src/vppinfra/test/ip_csum.c
+++ b/src/vppinfra/test/ip_csum.c
@@ -110,7 +110,6 @@ test_clib_ip_csum (clib_error_t *err)
}
}
done:
- test_mem_free (buf);
return err;
}
@@ -125,9 +124,6 @@ perftest_ip4_hdr (test_perf_t *tp)
for (int i = 0; i < n; i++)
res[i] = clib_ip_csum (data + i * 20, 20);
test_perf_event_disable (tp);
-
- test_mem_free (data);
- test_mem_free (res);
}
void __test_perf_fn
@@ -142,9 +138,6 @@ perftest_tcp_payload (test_perf_t *tp)
for (int i = 0; i < n; i++)
res[i] = clib_ip_csum (data + i * lenp[0], lenp[0]);
test_perf_event_disable (tp);
-
- test_mem_free (data);
- test_mem_free (res);
}
void __test_perf_fn
@@ -157,9 +150,6 @@ perftest_byte (test_perf_t *tp)
test_perf_event_enable (tp);
res[0] = clib_ip_csum (data, np[0]);
test_perf_event_disable (tp);
-
- test_mem_free (data);
- test_mem_free (res);
}
REGISTER_TEST (clib_ip_csum) = {
diff --git a/src/vppinfra/test/sha2.c b/src/vppinfra/test/sha2.c
index 9b4abbed657..0924461447c 100644
--- a/src/vppinfra/test/sha2.c
+++ b/src/vppinfra/test/sha2.c
@@ -305,10 +305,6 @@ check_digest (clib_error_t *err, int tc, u8 *calculated, const u8 *expected,
test_perf_event_enable (tp); \
clib_hmac_sha##bits (key, *kl, data, *np, digest); \
test_perf_event_disable (tp); \
- \
- test_mem_free (key); \
- test_mem_free (data); \
- test_mem_free (digest); \
} \
REGISTER_TEST (clib_hmac_sha##bits) = { \
.name = "clib_hmac_sha" #bits, \
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);
-}
diff --git a/src/vppinfra/test/test.h b/src/vppinfra/test/test.h
index 7d54d80c6ec..a0e5f6db669 100644
--- a/src/vppinfra/test/test.h
+++ b/src/vppinfra/test/test.h
@@ -57,6 +57,7 @@ typedef struct
u8 *filter;
u8 *bundle;
f64 ref_clock;
+ void **allocated_mem;
} test_main_t;
extern test_main_t test_main;
@@ -102,6 +103,5 @@ test_perf_event_disable (test_perf_t *t)
void *test_mem_alloc (uword size);
void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);
-void test_mem_free (void *p);
#endif
diff --git a/src/vppinfra/test/toeplitz.c b/src/vppinfra/test/toeplitz.c
index c1bd13fae8c..708fd0e60fc 100644
--- a/src/vppinfra/test/toeplitz.c
+++ b/src/vppinfra/test/toeplitz.c
@@ -253,8 +253,6 @@ test_clib_toeplitz_hash (clib_error_t *err)
done:
clib_toeplitz_hash_key_free (k);
- test_mem_free (bigkey);
- test_mem_free (bigdata);
return err;
}
@@ -272,8 +270,6 @@ perftest_fixed_12byte (test_perf_t *tp)
test_perf_event_disable (tp);
clib_toeplitz_hash_key_free (k);
- test_mem_free (data);
- test_mem_free (res);
}
void __test_perf_fn
@@ -290,8 +286,6 @@ perftest_fixed_36byte (test_perf_t *tp)
test_perf_event_disable (tp);
clib_toeplitz_hash_key_free (k);
- test_mem_free (data);
- test_mem_free (res);
}
void __test_perf_fn
@@ -314,9 +308,6 @@ perftest_variable_size (test_perf_t *tp)
test_perf_event_disable (tp);
clib_toeplitz_hash_key_free (k);
- test_mem_free (data);
- test_mem_free (res);
- test_mem_free (key);
}
REGISTER_TEST (clib_toeplitz_hash) = {
@@ -430,11 +421,6 @@ test_clib_toeplitz_hash_x4 (clib_error_t *err)
done:
clib_toeplitz_hash_key_free (k);
- test_mem_free (bigkey);
- test_mem_free (bigdata0);
- test_mem_free (bigdata1);
- test_mem_free (bigdata2);
- test_mem_free (bigdata3);
return err;
}
@@ -459,14 +445,6 @@ perftest_fixed_12byte_x4 (test_perf_t *tp)
test_perf_event_disable (tp);
clib_toeplitz_hash_key_free (k);
- test_mem_free (d0);
- test_mem_free (d1);
- test_mem_free (d2);
- test_mem_free (d3);
- test_mem_free (h0);
- test_mem_free (h1);
- test_mem_free (h2);
- test_mem_free (h3);
}
void __test_perf_fn
@@ -490,14 +468,6 @@ perftest_fixed_36byte_x4 (test_perf_t *tp)
test_perf_event_disable (tp);
clib_toeplitz_hash_key_free (k);
- test_mem_free (d0);
- test_mem_free (d1);
- test_mem_free (d2);
- test_mem_free (d3);
- test_mem_free (h0);
- test_mem_free (h1);
- test_mem_free (h2);
- test_mem_free (h3);
}
void __test_perf_fn
@@ -527,15 +497,6 @@ perftest_variable_size_x4 (test_perf_t *tp)
test_perf_event_disable (tp);
clib_toeplitz_hash_key_free (k);
- test_mem_free (key);
- test_mem_free (d0);
- test_mem_free (d1);
- test_mem_free (d2);
- test_mem_free (d3);
- test_mem_free (h0);
- test_mem_free (h1);
- test_mem_free (h2);
- test_mem_free (h3);
}
REGISTER_TEST (clib_toeplitz_hash_x4) = {