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 <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruscinski 2021-11-18 12:57:19 +01:00 committed by Anas Nashif
commit a50e13ceed
2 changed files with 13 additions and 0 deletions

View file

@ -87,6 +87,11 @@ config TEST_LOGGING_DEFAULTS
logging configuration, or no logging at all, disable this
in the project-level defconfig.
config TEST_LOGGING_FLUSH_AFTER_TEST
bool "When enabled logs are flushed after each test case"
default y
depends on MULTITHREADING
config TEST_ENABLE_USERSPACE
bool
depends on TEST_USERSPACE

View file

@ -11,6 +11,7 @@
#include <sys/libc-hooks.h>
#endif
#include <sys/reboot.h>
#include <logging/log_ctrl.h>
#ifdef KERNEL
static struct k_thread ztest_thread;
@ -368,15 +369,22 @@ static int run_test(struct unit_test *test)
}
k_thread_start(&ztest_thread);
k_thread_join(&ztest_thread, K_FOREVER);
} else {
test_result = 1;
run_test_functions(test);
}
phase = TEST_PHASE_TEARDOWN;
test->teardown();
phase = TEST_PHASE_FRAMEWORK;
/* Flush all logs in case deferred mode is used. */
while (IS_ENABLED(CONFIG_TEST_LOGGING_FLUSH_AFTER_TEST) && log_data_pending()) {
k_msleep(100);
}
if (test_result == -1) {
ret = TC_FAIL;
}