assert: Add verbose option to assertion messages

Add verbose option which would control if the assertion mechanism prints
any information at all. With this disabled they application will have to
use the stack-frame to locate the assertion location.

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

View file

@ -20,6 +20,12 @@
#define __ASSERT_ON 0
#endif
#if defined(CONFIG_ASSERT_VERBOSE)
#define __ASSERT_PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__)
#else /* CONFIG_ASSERT_VERBOSE */
#define __ASSERT_PRINT(fmt, ...)
#endif /* CONFIG_ASSERT_VERBOSE */
#ifdef CONFIG_ASSERT_NO_FILE_INFO
#define __ASSERT_FILE_INFO ""
#else /* CONFIG_ASSERT_NO_FILE_INFO */
@ -33,7 +39,7 @@
#endif /* CONFIG_ASSERT_NO_COND_INFO */
#define __ASSERT_LOC(test) \
printk("ASSERTION FAIL [%s] @ %s:%d\n", \
__ASSERT_PRINT("ASSERTION FAIL [%s] @ %s:%d\n", \
__ASSERT_COND_INFO(test), \
__ASSERT_FILE_INFO, \
__LINE__) \

View file

@ -181,6 +181,15 @@ config FORCE_NO_ASSERT
CFLAGS and not Kconfig. Added solely to be able to work
around compiler bugs for specific tests.
config ASSERT_VERBOSE
bool "Enable verbose assertions"
default y
help
This option enables printing an assert message with information about
the assertion that occurred. This includes printing the location,
the conditional expression and additional message specific to the
assert.
config ASSERT_NO_FILE_INFO
bool "Disable file info for asserts"
help