Skip to content

Commit a50e13c

Browse files
nordic-krchnashif
authored andcommitted
testsuite: ztest: Add logs flushing after each test case
When deferred mode is used, logging is using lowest priority thread to process the logs. When test cases are performed one by one processor never reaches lowest priority thread until whole suite is completed. Added flushing after each test case. Feature is optional (by default enabled). CONFIG_TEST_LOGGING_FLUSH_AFTER_TEST=n to disable. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 22d53f9 commit a50e13c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

subsys/testsuite/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ config TEST_LOGGING_DEFAULTS
8787
logging configuration, or no logging at all, disable this
8888
in the project-level defconfig.
8989

90+
config TEST_LOGGING_FLUSH_AFTER_TEST
91+
bool "When enabled logs are flushed after each test case"
92+
default y
93+
depends on MULTITHREADING
94+
9095
config TEST_ENABLE_USERSPACE
9196
bool
9297
depends on TEST_USERSPACE

subsys/testsuite/ztest/src/ztest.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sys/libc-hooks.h>
1212
#endif
1313
#include <sys/reboot.h>
14+
#include <logging/log_ctrl.h>
1415

1516
#ifdef KERNEL
1617
static struct k_thread ztest_thread;
@@ -368,15 +369,22 @@ static int run_test(struct unit_test *test)
368369
}
369370
k_thread_start(&ztest_thread);
370371
k_thread_join(&ztest_thread, K_FOREVER);
372+
371373
} else {
372374
test_result = 1;
373375
run_test_functions(test);
374376
}
375377

378+
376379
phase = TEST_PHASE_TEARDOWN;
377380
test->teardown();
378381
phase = TEST_PHASE_FRAMEWORK;
379382

383+
/* Flush all logs in case deferred mode is used. */
384+
while (IS_ENABLED(CONFIG_TEST_LOGGING_FLUSH_AFTER_TEST) && log_data_pending()) {
385+
k_msleep(100);
386+
}
387+
380388
if (test_result == -1) {
381389
ret = TC_FAIL;
382390
}

0 commit comments

Comments
 (0)