From 3bbe42f789c393e1af3fa7e05f0fbd7542dc5bc2 Mon Sep 17 00:00:00 2001 From: Ederson de Souza Date: Tue, 21 Jan 2025 12:45:56 -0800 Subject: [PATCH] tests/subsys/tracing: Async tracing API test fix Test `tracing.transport.uart.async.test` was working only due sheer serendipity: one of the tracing strings checked, sys_trace_k_mutex_lock_exit, was never being registered on the tracing buffer. However, the check never got to check this string, so the test was passing. Why wasn't it being registered? Tracing buffer size was a bit small for the flurry of messages - increasing it solves the problem, and is what this patch does. Why did the check never got to the missing string? Tracing thread has a lower priority, so when the k_sleep of test thread expired, it was preempted. Indeed, if the sleep was changed by any number of ticks, the test would fail. Even changing order - and thus number - of instructions executed could make this test fail. While at it, fixed some typos and an imprecise commentary on code. Fixes: #84169 Signed-off-by: Ederson de Souza --- tests/subsys/tracing/tracing_api/prj.conf | 1 + tests/subsys/tracing/tracing_api/src/main.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/subsys/tracing/tracing_api/prj.conf b/tests/subsys/tracing/tracing_api/prj.conf index af5be66675f..099348043ca 100644 --- a/tests/subsys/tracing/tracing_api/prj.conf +++ b/tests/subsys/tracing/tracing_api/prj.conf @@ -3,3 +3,4 @@ CONFIG_TRACING=y CONFIG_TRACING_TEST=y CONFIG_TRACING_BACKEND_UART=y CONFIG_IDLE_STACK_SIZE=4096 +CONFIG_TRACING_BUFFER_SIZE=4096 diff --git a/tests/subsys/tracing/tracing_api/src/main.c b/tests/subsys/tracing/tracing_api/src/main.c index fe976265e0f..89f1478f633 100644 --- a/tests/subsys/tracing/tracing_api/src/main.c +++ b/tests/subsys/tracing/tracing_api/src/main.c @@ -67,8 +67,15 @@ static void tracing_backends_output( /* Check the output data. */ #ifdef CONFIG_TRACING_ASYNC if (async_tracing_api) { - /* Define static 'i' is for guaranteeing all strings of 0 ~ end - * of the array string_tracked are tested. + /* This verification should run only once, hence the static + * `i`. As soon as the tracing thread has a chance to run, + * right at the sleep at the async version of + * test_tracing_sys_api, it should have everything needed + * for this check on its buffer, which is sent here. + * Should SMP be ever enabled for this test, this logic + * will break down and one will need some sort of internal + * buffer to keep track of the tracing strings (or do the + * verification in some other way). */ static int i; @@ -184,8 +191,8 @@ ZTEST(tracing_api, test_tracing_sys_api) /* wait for some actions finished */ k_sleep(K_MSEC(100)); - zassert_true(tracing_api_found, "Failded to check output from backend"); - zassert_true(tracing_api_not_found == false, "Failded to check output from backend"); + zassert_true(tracing_api_found, "Failed to check output from backend"); + zassert_true(tracing_api_not_found == false, "Failed to check output from backend"); async_tracing_api = false; } #else