aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/unittest/session_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/unittest/session_test.c')
-rw-r--r--src/plugins/unittest/session_test.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/plugins/unittest/session_test.c b/src/plugins/unittest/session_test.c
index f0e5d4b4f3d..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");
@@ -2362,7 +2370,10 @@ session_get_memory_usage (void)
s = format (s, "%U\n", format_clib_mem_heap, heap, 0);
ss = strstr ((char *) s, "used:");
if (ss)
- sscanf (ss, "used: %f", &used);
+ {
+ if (sscanf (ss, "used: %f", &used) != 1)
+ clib_warning ("invalid 'used' value");
+ }
else
clib_warning ("substring 'used:' not found from show memory");
vec_free (s);
@@ -2372,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;
@@ -2388,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++)
@@ -2409,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;
}
@@ -2732,6 +2751,8 @@ session_test (vlib_main_t * vm,
done:
if (res)
return clib_error_return (0, "Session unit test failed");
+
+ vlib_cli_output (vm, "SUCCESS");
return 0;
}