From 90f6689697a18d3de6e08f7e00fed526e9284b45 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Tue, 13 May 2025 15:20:51 -0400 Subject: [PATCH] session: force cleanup of cts without app wrk Also some improvements to unit tests. Type: fix Change-Id: Ib16f320e4404748fee8e3c6994b8df8dd890b9ea Signed-off-by: Florin Coras --- src/plugins/unittest/session_test.c | 34 +++++++++++++++++++++++++--------- src/vnet/session/application_local.c | 3 ++- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/plugins/unittest/session_test.c b/src/plugins/unittest/session_test.c index 667851901c4..d54655e6456 100644 --- a/src/plugins/unittest/session_test.c +++ b/src/plugins/unittest/session_test.c @@ -33,12 +33,15 @@ _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; } diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c index f22e3647b7f..1392e5d58f2 100644 --- a/src/vnet/session/application_local.c +++ b/src/vnet/session/application_local.c @@ -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); } } } -- 2.16.6