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 #define __ASSERT_ON 0
#endif #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 #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"
@ -42,14 +48,14 @@ 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), \ Z_STRINGIFY(test), \
__FILE__, \ __ASSERT_FILE_INFO, \
__LINE__) \ __LINE__) \
#define __ASSERT_NO_MSG(test) \ #define __ASSERT_NO_MSG(test) \
do { \ do { \
if (!(test)) { \ if (!(test)) { \
__ASSERT_LOC(test); \ __ASSERT_LOC(test); \
assert_post_action(__FILE__, __LINE__); \ assert_post_action(__ASSERT_FILE_INFO, __LINE__); \
} \ } \
} while (false) } while (false)
@ -58,7 +64,7 @@ void assert_post_action(const char *file, unsigned int line);
if (!(test)) { \ if (!(test)) { \
__ASSERT_LOC(test); \ __ASSERT_LOC(test); \
printk("\t" fmt "\n", ##__VA_ARGS__); \ printk("\t" fmt "\n", ##__VA_ARGS__); \
assert_post_action(__FILE__, __LINE__); \ assert_post_action(__ASSERT_FILE_INFO, __LINE__); \
} \ } \
} while (false) } while (false)

View file

@ -155,6 +155,13 @@ config FORCE_NO_ASSERT
CFLAGS and not Kconfig. Added solely to be able to work CFLAGS and not Kconfig. Added solely to be able to work
around compiler bugs for specific tests. around compiler bugs for specific tests.
config ASSERT_NO_FILE_INFO
bool "Disable file info for asserts"
help
This option removes the name and the path of the source file
in which the assertion occurred. Enabling this will save
target code space, and thus may be necessary for tiny targets.
config OBJECT_TRACING config OBJECT_TRACING
bool "Kernel object tracing" bool "Kernel object tracing"
help help