From c5d85e175fae85dce4236d20a92717e084b57709 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 6 Aug 2020 16:47:02 -0600 Subject: [PATCH] subsys/testsuite: Add an assert for a zero return code Many functions signal success by returning a return code of zero. Add an assertion for this. Some functions can return a positive value to indicate success, where they want to convey some information. This is not handled by this assert function. Signed-off-by: Simon Glass --- subsys/testsuite/ztest/include/ztest_assert.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/subsys/testsuite/ztest/include/ztest_assert.h b/subsys/testsuite/ztest/include/ztest_assert.h index f52fca661e7..e1ed2ffdf46 100644 --- a/subsys/testsuite/ztest/include/ztest_assert.h +++ b/subsys/testsuite/ztest/include/ztest_assert.h @@ -116,6 +116,14 @@ static inline void z_zassert(bool cond, #define zassert_false(cond, msg, ...) zassert(!(cond), #cond " is true", \ msg, ##__VA_ARGS__) +/** + * @brief Assert that @a cond is 0 (success) + * @param cond Condition to check + * @param msg Optional message to print if the assertion fails + */ +#define zassert_ok(cond, msg, ...) zassert(!(cond), #cond " is non-zero", \ + msg, ##__VA_ARGS__) + /** * @brief Assert that @a ptr is NULL * @param ptr Pointer to compare