Bluetooth: log: Add BT_ASSERT_MSG that matches __ASSERT

Add BT_ASSERT_MSG assert mechanism that can print assertion messages
when verbose bluetooth asserts are enabled.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-04-08 10:44:33 +02:00 committed by Johan Hedberg
commit 9e8a30203f

View file

@ -44,8 +44,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
#if defined(CONFIG_BT_ASSERT_VERBOSE) #if defined(CONFIG_BT_ASSERT_VERBOSE)
#define BT_ASSERT_PRINT(test) __ASSERT_LOC(test) #define BT_ASSERT_PRINT(test) __ASSERT_LOC(test)
#define BT_ASSERT_PRINT_MSG(fmt, ...) __ASSERT_MSG_INFO(fmt, ##__VA_ARGS__)
#else #else
#define BT_ASSERT_PRINT(test) #define BT_ASSERT_PRINT(test)
#define BT_ASSERT_PRINT_MSG(fmt, ...)
#endif /* CONFIG_BT_ASSERT_VERBOSE */ #endif /* CONFIG_BT_ASSERT_VERBOSE */
#if defined(CONFIG_BT_ASSERT_PANIC) #if defined(CONFIG_BT_ASSERT_PANIC)
@ -62,8 +64,18 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
BT_ASSERT_DIE(); \ BT_ASSERT_DIE(); \
} \ } \
} while (0) } while (0)
#define BT_ASSERT_MSG(cond, fmt, ...) \
do { \
if (!(cond)) { \
BT_ASSERT_PRINT(cond); \
BT_ASSERT_PRINT_MSG(fmt, ##__VA_ARGS__); \
BT_ASSERT_DIE(); \
} \
} while (0)
#else #else
#define BT_ASSERT(cond) __ASSERT_NO_MSG(cond) #define BT_ASSERT(cond) __ASSERT_NO_MSG(cond)
#define BT_ASSERT_MSG(cond, msg, ...) __ASSERT(cond, msg, ##__VA_ARGS__)
#endif/* CONFIG_BT_ASSERT*/ #endif/* CONFIG_BT_ASSERT*/
#define BT_HEXDUMP_DBG(_data, _length, _str) \ #define BT_HEXDUMP_DBG(_data, _length, _str) \