-
Notifications
You must be signed in to change notification settings - Fork 0
WIP: Add logging levels to ztest #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,37 @@ typedef struct esf z_arch_esf_t; | |
#endif /* KERNEL */ | ||
|
||
#include <sys/printk.h> | ||
|
||
/* Test logging destination */ | ||
#ifdef CONFIG_ZTEST_PRINT_TO_LOG | ||
/* Use the Zephyr logging subsystem */ | ||
#include <logging/log.h> | ||
|
||
#ifndef ZTEST_DONT_DECLARE_LOG | ||
/* Automatically declare the log module in all compilation units including | ||
* this header, unless this macro is set. The macro should be set in the | ||
* source file that initially registers the module to avoid a redefinition. | ||
*/ | ||
|
||
LOG_MODULE_DECLARE(ztest_log_mod); | ||
#endif /* ZTEST_DONT_DECLARE_LOG */ | ||
|
||
|
||
#define ZTEST_DBG LOG_DBG | ||
#define ZTEST_INF LOG_INF | ||
#define ZTEST_WRN LOG_WRN | ||
#define ZTEST_ERR LOG_ERR | ||
#define ZTEST_PRINTK LOG_PRINTK | ||
#else | ||
/* Direct everything through printk */ | ||
#define ZTEST_DBG printk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was hoping to avoid this, as there are a lot of tests printing their own log messages, but if that's the best way forward I'll do that... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You know, before we keep pushing on this we should know what the overhead of |
||
#define ZTEST_INF printk | ||
#define ZTEST_WRN printk | ||
#define ZTEST_ERR printk | ||
#define ZTEST_PRINTK printk | ||
#endif /* ZTEST_PRINT_TO_LOG */ | ||
|
||
/* TODO: Do we want to retain this? Could user tests be relying on it? */ | ||
#define PRINT printk | ||
|
||
#include <zephyr.h> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,11 +75,11 @@ static int cleanup_test(struct unit_test *test) | |
#endif | ||
|
||
if (!ret && mock_status == 1) { | ||
PRINT("Test %s failed: Unused mock parameter values\n", | ||
ZTEST_ERR("Test %s failed: Unused mock parameter values\n", | ||
test->name); | ||
ret = TC_FAIL; | ||
} else if (!ret && mock_status == 2) { | ||
PRINT("Test %s failed: Unused mock return values\n", | ||
ZTEST_ERR("Test %s failed: Unused mock return values\n", | ||
test->name); | ||
ret = TC_FAIL; | ||
} else { | ||
|
@@ -244,15 +244,15 @@ static void handle_signal(int sig) | |
"teardown", | ||
}; | ||
|
||
PRINT(" %s", strsignal(sig)); | ||
ZTEST_ERR(" %s", strsignal(sig)); | ||
switch (phase) { | ||
case TEST_PHASE_SETUP: | ||
case TEST_PHASE_TEST: | ||
case TEST_PHASE_TEARDOWN: | ||
PRINT(" at %s function\n", phase_str[phase]); | ||
ZTEST_ERR(" at %s function\n", phase_str[phase]); | ||
longjmp(test_fail, 1); | ||
case TEST_PHASE_FRAMEWORK: | ||
PRINT("\n"); | ||
ZTEST_ERR("\n"); | ||
longjmp(stack_fail, 1); | ||
} | ||
} | ||
|
@@ -263,7 +263,7 @@ static void init_testing(void) | |
signal(SIGSEGV, handle_signal); | ||
|
||
if (setjmp(stack_fail)) { | ||
PRINT("Test suite crashed."); | ||
ZTEST_ERR("Test suite crashed."); | ||
exit(1); | ||
} | ||
} | ||
|
@@ -482,7 +482,7 @@ void ztest_verify_all_registered_test_suites_ran(void) | |
|
||
for (ptr = _ztest_suite_node_list_start; ptr < _ztest_suite_node_list_end; ++ptr) { | ||
if (ptr->stats.run_count < 1) { | ||
PRINT("ERROR: Test '%s' did not run.\n", ptr->name); | ||
ZTEST_ERR("ERROR: Test '%s' did not run.\n", ptr->name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like these prefixes like |
||
all_tests_run = false; | ||
} | ||
} | ||
|
@@ -521,7 +521,8 @@ void main(void) | |
ret = k_mem_domain_add_partition(&k_mem_domain_default, | ||
&ztest_mem_partition); | ||
if (ret != 0) { | ||
PRINT("ERROR: failed to add ztest_mem_partition to mem domain (%d)\n", | ||
ZTEST_ERR( | ||
"ERROR: failed to add ztest_mem_partition to mem domain (%d)\n", | ||
ret); | ||
k_oops(); | ||
} | ||
|
@@ -530,7 +531,8 @@ void main(void) | |
ret = k_mem_domain_add_partition(&k_mem_domain_default, | ||
&z_malloc_partition); | ||
if (ret != 0) { | ||
PRINT("ERROR: failed to add z_malloc_partition to mem domain (%d)\n", | ||
ZTEST_ERR( | ||
"ERROR: failed to add z_malloc_partition to mem domain (%d)\n", | ||
ret); | ||
k_oops(); | ||
} | ||
|
@@ -553,12 +555,12 @@ void main(void) | |
} | ||
state.boots += 1; | ||
if (test_status == 0) { | ||
PRINT("Reset board #%u to test again\n", | ||
ZTEST_ERR("Reset board #%u to test again\n", | ||
state.boots); | ||
k_msleep(10); | ||
sys_reboot(SYS_REBOOT_COLD); | ||
} else { | ||
PRINT("Failed after %u attempts\n", state.boots); | ||
ZTEST_ERR("Failed after %u attempts\n", state.boots); | ||
state.boots = 0; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the convention is to prefix with
Z_
for internal defines