session: force cleanup of cts without app wrk 50/42950/1
authorFlorin Coras <[email protected]>
Tue, 13 May 2025 19:20:51 +0000 (15:20 -0400)
committerFlorin Coras <[email protected]>
Tue, 13 May 2025 19:21:32 +0000 (15:21 -0400)
Also some improvements to unit tests.

Type: fix

Change-Id: Ib16f320e4404748fee8e3c6994b8df8dd890b9ea
Signed-off-by: Florin Coras <[email protected]>
src/plugins/unittest/session_test.c
src/vnet/session/application_local.c

index 6678519..d54655e 100644 (file)
   _evald;                                                      \
 })
 
-#define SESSION_TEST(_cond, _comment, _args...)                        \
-{                                                              \
-    if (!SESSION_TEST_I(_cond, _comment, ##_args)) {           \
-       return 1;                                               \
-    }                                                          \
-}
+#define SESSION_TEST(_cond, _comment, _args...)                               \
+  do                                                                          \
+    {                                                                         \
+      if (!SESSION_TEST_I (_cond, _comment, ##_args))                         \
+       {                                                                     \
+         return 1;                                                           \
+       }                                                                     \
+    }                                                                         \
+  while (0)
 
 #define ST_DBG(_comment, _args...)                             \
     fformat(stderr,  _comment "\n",  ##_args);                 \
@@ -670,6 +673,11 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input)
   u64 handle;
   int error = 0;
 
+  /* Make sure segment count and accept are reset before starting test
+   * in case tests are ran multiple times */
+  placeholder_segment_count = 0;
+  placeholder_accept = 0;
+
   ns_id = format (0, "appns1");
   server_name = format (0, "session_test");
   client_name = format (0, "session_test_client");
@@ -2375,7 +2383,7 @@ session_get_memory_usage (void)
 static int
 session_test_enable_disable (vlib_main_t *vm, unformat_input_t *input)
 {
-  u32 iteration = 100, i;
+  u32 iteration = 100, i, n_sessions = 0;
   uword was_enabled;
   f32 was_using, now_using;
 
@@ -2391,6 +2399,10 @@ session_test_enable_disable (vlib_main_t *vm, unformat_input_t *input)
        }
     }
 
+  for (int thread_index = 0; thread_index <= vlib_num_workers ();
+       thread_index++)
+    n_sessions += pool_elts (session_main.wrk[thread_index].sessions);
+
   was_enabled = clib_mem_trace_enable_disable (0);
   /* warm up */
   for (i = 0; i < 10; i++)
@@ -2412,8 +2424,12 @@ session_test_enable_disable (vlib_main_t *vm, unformat_input_t *input)
   now_using = session_get_memory_usage ();
 
   clib_mem_trace_enable_disable (was_enabled);
-  SESSION_TEST ((was_using == now_using), "was using %.2fM, now using %.2fM",
-               was_using, now_using);
+  if (n_sessions)
+    SESSION_TEST ((now_using < was_using + (1 << 15)),
+                 "was using %.2fM, now using %.2fM", was_using, now_using);
+  else
+    SESSION_TEST ((was_using == now_using), "was using %.2fM, now using %.2fM",
+                 was_using, now_using);
 
   return 0;
 }
index f22e364..1392e5d 100644 (file)
@@ -95,6 +95,7 @@ ct_connection_alloc (clib_thread_index_t thread_index)
   ct->server_wrk = ~0;
   ct->seg_ctx_index = ~0;
   ct->ct_seg_index = ~0;
+  ct->peer_index = ~0;
   return ct;
 }
 
@@ -1109,7 +1110,7 @@ ct_session_postponed_cleanup (ct_connection_t *ct)
        }
       else
        {
-         ct_connection_free (ct);
+         ct_session_cleanup_server_session (s);
        }
     }
 }