kconfig: assert: Introduce kconfig option ASSERT_NO_FILE_INFO

Default behavior is to include __FILE__ info with all of the Zephyr
assert macros, __ASSERT, __ASSERT_NO_MSG and __ASSERT_LOC. Setting the
ASSERT_NO_FILE_INFO kconfig option, replaces the __FILE__ with an
empty string, thus removing the file information from the asserts.

The intention here is to allow for code space limited devices to run
with asserts enabled.

Signed-off-by: Danny Oerndrup <daor@demant.com>
This commit is contained in:
Danny Oerndrup 2019-10-11 14:21:40 +02:00 committed by Maureen Helm
commit b8add4aa0b
2 changed files with 29 additions and 16 deletions

View file

@ -20,6 +20,12 @@
#define __ASSERT_ON 0
#endif
#ifdef CONFIG_ASSERT_NO_FILE_INFO
#define __ASSERT_FILE_INFO ""
#else /* CONFIG_ASSERT_NO_FILE_INFO */
#define __ASSERT_FILE_INFO __FILE__
#endif /* CONFIG_ASSERT_NO_FILE_INFO */
#ifdef __ASSERT_ON
#if (__ASSERT_ON < 0) || (__ASSERT_ON > 2)
#error "Invalid __ASSERT() level: must be between 0 and 2"
@ -40,26 +46,26 @@ void assert_post_action(const char *file, unsigned int line);
#endif
#define __ASSERT_LOC(test) \
printk("ASSERTION FAIL [%s] @ %s:%d\n", \
Z_STRINGIFY(test), \
__FILE__, \
printk("ASSERTION FAIL [%s] @ %s:%d\n", \
Z_STRINGIFY(test), \
__ASSERT_FILE_INFO, \
__LINE__) \
#define __ASSERT_NO_MSG(test) \
do { \
if (!(test)) { \
__ASSERT_LOC(test); \
assert_post_action(__FILE__, __LINE__); \
} \
#define __ASSERT_NO_MSG(test) \
do { \
if (!(test)) { \
__ASSERT_LOC(test); \
assert_post_action(__ASSERT_FILE_INFO, __LINE__); \
} \
} while (false)
#define __ASSERT(test, fmt, ...) \
do { \
if (!(test)) { \
__ASSERT_LOC(test); \
printk("\t" fmt "\n", ##__VA_ARGS__); \
assert_post_action(__FILE__, __LINE__); \
} \
#define __ASSERT(test, fmt, ...) \
do { \
if (!(test)) { \
__ASSERT_LOC(test); \
printk("\t" fmt "\n", ##__VA_ARGS__); \
assert_post_action(__ASSERT_FILE_INFO, __LINE__); \
} \
} while (false)
#define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) \