Skip to content

Commit 6deca93

Browse files
nordic-krchkartben
authored andcommitted
testsuite: ztest: Add validation of zassert strings
Add noncallable printf with string used for ztest assert/assume macros to ensure printf-like argument validation at compile time. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent d8c8333 commit 6deca93

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

subsys/testsuite/ztest/include/zephyr/ztest_assert.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
191191
_zassert_base(cond, default_msg, msg, ##__VA_ARGS__)
192192

193193
#define zassert(cond, default_msg, ...) \
194+
IF_ENABLED(__VA_OPT__(1), ( \
195+
if (0) { \
196+
printf(__VA_ARGS__); \
197+
})) \
194198
_zassert_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
195199

196200
/**
@@ -229,6 +233,10 @@ static inline bool z_zexpect(bool cond, const char *default_msg, const char *fil
229233
_zassume_base(cond, default_msg, msg, ##__VA_ARGS__)
230234

231235
#define zassume(cond, default_msg, ...) \
236+
IF_ENABLED(__VA_OPT__(1), ( \
237+
if (0) { \
238+
printf(__VA_ARGS__); \
239+
})) \
232240
_zassume_va(cond, default_msg, COND_CODE_1(__VA_OPT__(1), (__VA_ARGS__), (NULL)))
233241

234242
/**

0 commit comments

Comments
 (0)