From 305ee1816a31b2a69279830793868d27db9f5a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Barna=C5=9B?= Date: Wed, 17 Aug 2022 15:54:31 +0200 Subject: [PATCH] ztest: prepare zassert and zassume macro to be used without message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds intermediate macros that will allow to use the zassert and zassume macros without setting the msg parameter as NULL if it isn't used. Signed-off-by: Michał Barnaś --- .../ztest/include/zephyr/ztest_assert.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/subsys/testsuite/ztest/include/zephyr/ztest_assert.h b/subsys/testsuite/ztest/include/zephyr/ztest_assert.h index 7e3811869f4..7e00e208f6a 100644 --- a/subsys/testsuite/ztest/include/zephyr/ztest_assert.h +++ b/subsys/testsuite/ztest/include/zephyr/ztest_assert.h @@ -130,7 +130,7 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil * @param default_msg Message to print if @a cond is false * @param msg Optional, can be NULL. Message to print if @a cond is false. */ -#define zassert(cond, default_msg, msg, ...) \ +#define _zassert_base(cond, default_msg, msg, ...) \ do { \ bool _msg = (msg != NULL); \ bool _ret = z_zassert(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\ @@ -143,6 +143,12 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil } \ } while (0) +#define _zassert_va(cond, default_msg, msg, ...) \ + _zassert_base(cond, default_msg, msg, ##__VA_ARGS__) + +#define zassert(cond, default_msg, ...) \ + _zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL))) + /** * @brief Skip the test, if @a cond is false * @@ -161,7 +167,7 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil * @param default_msg Message to print if @a cond is false * @param msg Optional, can be NULL. Message to print if @a cond is false. */ -#define zassume(cond, default_msg, msg, ...) \ +#define _zassume_base(cond, default_msg, msg, ...) \ do { \ bool _msg = (msg != NULL); \ bool _ret = z_zassume(cond, _msg ? ("(" default_msg ")") : (default_msg), __FILE__,\ @@ -173,6 +179,13 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil ()) \ } \ } while (0) + +#define _zassume_va(cond, default_msg, msg, ...) \ + _zassume_base(cond, default_msg, msg, ##__VA_ARGS__) + +#define zassume(cond, default_msg, ...) \ + _zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL))) + /** * @brief Assert that this function call won't be reached * @param msg Optional message to print if the assertion fails