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:
parent
0464caef6a
commit
b8add4aa0b
2 changed files with 29 additions and 16 deletions
|
@ -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"
|
||||||
|
@ -40,26 +46,26 @@ void assert_post_action(const char *file, unsigned int line);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#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)
|
||||||
|
|
||||||
#define __ASSERT(test, fmt, ...) \
|
#define __ASSERT(test, fmt, ...) \
|
||||||
do { \
|
do { \
|
||||||
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)
|
||||||
|
|
||||||
#define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) \
|
#define __ASSERT_EVAL(expr1, expr2, test, fmt, ...) \
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue