From 08168f60f7214782798eeb2f791ca1bbeec83b6b Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 9 Dec 2019 14:41:43 +0100 Subject: [PATCH] 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 --- subsys/bluetooth/common/Kconfig | 3 +-- subsys/bluetooth/common/log.h | 17 ++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/common/Kconfig b/subsys/bluetooth/common/Kconfig index 2c9b97a270a..f66ede26d0c 100644 --- a/subsys/bluetooth/common/Kconfig +++ b/subsys/bluetooth/common/Kconfig @@ -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 diff --git a/subsys/bluetooth/common/log.h b/subsys/bluetooth/common/log.h index c4f526bbba0..d17a9a27323 100644 --- a/subsys/bluetooth/common/log.h +++ b/subsys/bluetooth/common/log.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -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*/