assert: Add option to disable condition from assertion message

Add Kconfig option to disable the conditional expression in the assert
that failed. This would save code space, and file and line provides
better information than the conditional expression in case where
the same expression would be asserted upon.

For example __ASSERT_NO_MSG(buf) wouldn't make much sense in
configuration where CONFIG_ASSERT_NO_FILE_INFO was enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2019-12-09 14:07:10 +01:00 committed by Alberto Escolar
commit 94d331b2eb
2 changed files with 16 additions and 1 deletions

View file

@ -26,6 +26,12 @@
#define __ASSERT_FILE_INFO __FILE__ #define __ASSERT_FILE_INFO __FILE__
#endif /* CONFIG_ASSERT_NO_FILE_INFO */ #endif /* CONFIG_ASSERT_NO_FILE_INFO */
#ifdef CONFIG_ASSERT_NO_COND_INFO
#define __ASSERT_COND_INFO(test) ""
#else /* CONFIG_ASSERT_NO_COND_INFO */
#define __ASSERT_COND_INFO(test) Z_STRINGIFY(test)
#endif /* CONFIG_ASSERT_NO_COND_INFO */
#ifdef __ASSERT_ON #ifdef __ASSERT_ON
#if (__ASSERT_ON < 0) || (__ASSERT_ON > 2) #if (__ASSERT_ON < 0) || (__ASSERT_ON > 2)
#error "Invalid __ASSERT() level: must be between 0 and 2" #error "Invalid __ASSERT() level: must be between 0 and 2"
@ -47,7 +53,7 @@ void assert_post_action(const char *file, unsigned int line);
#define __ASSERT_LOC(test) \ #define __ASSERT_LOC(test) \
printk("ASSERTION FAIL [%s] @ %s:%d\n", \ printk("ASSERTION FAIL [%s] @ %s:%d\n", \
Z_STRINGIFY(test), \ __ASSERT_COND_INFO(test), \
__ASSERT_FILE_INFO, \ __ASSERT_FILE_INFO, \
__LINE__) \ __LINE__) \

View file

@ -188,6 +188,15 @@ config ASSERT_NO_FILE_INFO
in which the assertion occurred. Enabling this will save in which the assertion occurred. Enabling this will save
target code space, and thus may be necessary for tiny targets. target code space, and thus may be necessary for tiny targets.
config ASSERT_NO_COND_INFO
bool "Disable condition info for asserts"
help
This option removes the assert condition from the printed assert
message. Enabling this will save target code space, and thus may be
necessary for tiny targets. It is recommended to disable condition
info before disabling file info since the condition can be found in
the source using file info.
config OBJECT_TRACING config OBJECT_TRACING
bool "Kernel object tracing" bool "Kernel object tracing"
help help