vppinfra: auto-free test memory 10/38510/3
authorDamjan Marion <damarion@cisco.com>
Thu, 16 Mar 2023 16:55:38 +0000 (16:55 +0000)
committerFlorin Coras <florin.coras@gmail.com>
Fri, 17 Mar 2023 16:34:06 +0000 (16:34 +0000)
Type: improvement
Change-Id: Ibc40a02c8c45fc8d9409c9a86fea7aaf70d9c048
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vppinfra/test/ip_csum.c
src/vppinfra/test/sha2.c
src/vppinfra/test/test.c
src/vppinfra/test/test.h
src/vppinfra/test/toeplitz.c

index 9387336..b8508ee 100644 (file)
@@ -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) = {
index 9b4abbe..0924461 100644 (file)
@@ -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,                                            \
index 15ea6fd..194d725 100644 (file)
@@ -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);
-}
index 7d54d80..a0e5f6d 100644 (file)
@@ -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
index c1bd13f..708fd0e 100644 (file)
@@ -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) = {