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 <ederson.desouza@intel.com>
This commit is contained in:
Ederson de Souza 2025-01-21 12:45:56 -08:00 committed by Benjamin Cabé
commit 3bbe42f789
2 changed files with 12 additions and 4 deletions

View file

@ -3,3 +3,4 @@ CONFIG_TRACING=y
CONFIG_TRACING_TEST=y CONFIG_TRACING_TEST=y
CONFIG_TRACING_BACKEND_UART=y CONFIG_TRACING_BACKEND_UART=y
CONFIG_IDLE_STACK_SIZE=4096 CONFIG_IDLE_STACK_SIZE=4096
CONFIG_TRACING_BUFFER_SIZE=4096

View file

@ -67,8 +67,15 @@ static void tracing_backends_output(
/* Check the output data. */ /* Check the output data. */
#ifdef CONFIG_TRACING_ASYNC #ifdef CONFIG_TRACING_ASYNC
if (async_tracing_api) { if (async_tracing_api) {
/* Define static 'i' is for guaranteeing all strings of 0 ~ end /* This verification should run only once, hence the static
* of the array string_tracked are tested. * `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; static int i;
@ -184,8 +191,8 @@ ZTEST(tracing_api, test_tracing_sys_api)
/* wait for some actions finished */ /* wait for some actions finished */
k_sleep(K_MSEC(100)); k_sleep(K_MSEC(100));
zassert_true(tracing_api_found, "Failded to check output from backend"); zassert_true(tracing_api_found, "Failed to check output from backend");
zassert_true(tracing_api_not_found == false, "Failded to check output from backend"); zassert_true(tracing_api_not_found == false, "Failed to check output from backend");
async_tracing_api = false; async_tracing_api = false;
} }
#else #else