Bluetooth: assert: Change printed expression to printing line and file

Change assertion messaged printed from printing expression to printing
the line and file name. This provides more context as the same
expression could be asserted upon multiple times and would then not
provide enough clarity in the message.

Also using a formatted string would save code space as we can use the
same string for all messages instead of creating a unique one for each
condition.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2019-12-09 14:41:43 +01:00 committed by Alberto Escolar
commit 08168f60f7
2 changed files with 11 additions and 9 deletions

View file

@ -61,8 +61,7 @@ config BT_ASSERT
default y
help
Use a custom Bluetooth assert implementation instead of the
kernel-wide __ASSERT(), which is enabled by CONFIG_ASSERT and is
disabled by default.
kernel-wide __ASSERT() when CONFIG_ASSERT is disabled.
if BT_ASSERT

View file

@ -15,6 +15,7 @@
#include <offsets.h>
#include <zephyr.h>
#include <logging/log.h>
#include <sys/__assert.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
@ -42,9 +43,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
#define BT_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__)
#if defined(CONFIG_BT_ASSERT_VERBOSE)
#define BT_ASSERT_PRINT(fmt, ...) printk(fmt, ##__VA_ARGS__)
#define BT_ASSERT_PRINT(test) __ASSERT_LOC(test)
#else
#define BT_ASSERT_PRINT(fmt, ...)
#define BT_ASSERT_PRINT(test)
#endif /* CONFIG_BT_ASSERT_VERBOSE */
#if defined(CONFIG_BT_ASSERT_PANIC)
@ -54,11 +55,13 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
#endif /* CONFIG_BT_ASSERT_PANIC */
#if defined(CONFIG_BT_ASSERT)
#define BT_ASSERT(cond) if (!(cond)) { \
BT_ASSERT_PRINT("assert: '" #cond \
"' failed\n"); \
BT_ASSERT_DIE(); \
}
#define BT_ASSERT(cond) \
do { \
if (!(cond)) { \
BT_ASSERT_PRINT(cond); \
BT_ASSERT_DIE(); \
} \
} while (0)
#else
#define BT_ASSERT(cond) __ASSERT_NO_MSG(cond)
#endif/* CONFIG_BT_ASSERT*/