Commit a50e13ce authored by Krzysztof Chruściński's avatar Krzysztof Chruściński Committed by Anas Nashif
Browse files

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: default avatarKrzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
parent 22d53f91
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+8 −0
Original line number Diff line number Diff line
@@ -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;
	}