ztest: remove msg parameter from zassert_* and zassume_* macros
This commit removes the requirement for msg parameter in zassert_* and zassume_* macros. It will allow to use them without sending NULL as the last parameter. The default messages look like: void* beauty_ptr = NULL; zassert_not_null(beauty_ptr); => Assertion failed at main.c:20: suite_test: beauty_ptr is NULL void* ugly_ptr = (void*)0xbaadf00d; zassume_is_null(ugly_ptr); => Assumption failed at main.c:23: suite_test: ugly_ptr is not NULL int apple = 3; int tomato = 9; zassume_equal(apple, tomato); => Assumption failed at main.c:27: suite_test: apple not equal to tomato Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit is contained in:
parent
305ee1816a
commit
36f74e9837
1 changed files with 54 additions and 60 deletions
|
@ -188,45 +188,44 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
|
||||
/**
|
||||
* @brief Assert that this function call won't be reached
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_unreachable(msg, ...) zassert(0, "Reached unreachable code", msg, ##__VA_ARGS__)
|
||||
#define zassert_unreachable(...) zassert(0, "Reached unreachable code", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a cond is true
|
||||
* @param cond Condition to check
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_true(cond, msg, ...) zassert(cond, #cond " is false", msg, ##__VA_ARGS__)
|
||||
#define zassert_true(cond, ...) zassert(cond, #cond " is false", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a cond is false
|
||||
* @param cond Condition to check
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_false(cond, msg, ...) zassert(!(cond), #cond " is true", msg, ##__VA_ARGS__)
|
||||
#define zassert_false(cond, ...) zassert(!(cond), #cond " is true", ##__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
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_ok(cond, msg, ...) zassert(!(cond), #cond " is non-zero", msg, ##__VA_ARGS__)
|
||||
#define zassert_ok(cond, ...) zassert(!(cond), #cond " is non-zero", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a ptr is NULL
|
||||
* @param ptr Pointer to compare
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_is_null(ptr, msg, ...) \
|
||||
zassert((ptr) == NULL, #ptr " is not NULL", msg, ##__VA_ARGS__)
|
||||
#define zassert_is_null(ptr, ...) zassert((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a ptr is not NULL
|
||||
* @param ptr Pointer to compare
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_not_null(ptr, msg, ...) zassert((ptr) != NULL, #ptr " is NULL", msg, ##__VA_ARGS__)
|
||||
#define zassert_not_null(ptr, ...) zassert((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a a equals @a b
|
||||
|
@ -235,10 +234,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
*
|
||||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_equal(a, b, msg, ...) \
|
||||
zassert((a) == (b), #a " not equal to " #b, msg, ##__VA_ARGS__)
|
||||
#define zassert_equal(a, b, ...) zassert((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a a does not equal @a b
|
||||
|
@ -247,10 +245,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
*
|
||||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_not_equal(a, b, msg, ...) \
|
||||
zassert((a) != (b), #a " equal to " #b, msg, ##__VA_ARGS__)
|
||||
#define zassert_not_equal(a, b, ...) zassert((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a a equals @a b
|
||||
|
@ -259,10 +256,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
*
|
||||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_equal_ptr(a, b, msg, ...) \
|
||||
zassert((void *)(a) == (void *)(b), #a " not equal to " #b, msg, ##__VA_ARGS__)
|
||||
#define zassert_equal_ptr(a, b, ...) \
|
||||
zassert((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a a is within @a b with delta @a d
|
||||
|
@ -270,11 +267,11 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param d Delta
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_within(a, b, d, msg, ...) \
|
||||
#define zassert_within(a, b, d, ...) \
|
||||
zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
|
||||
msg, ##__VA_ARGS__)
|
||||
##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assert that @a a is greater than or equal to @a l and less
|
||||
|
@ -283,10 +280,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* @param a Value to compare
|
||||
* @param l Lower limit
|
||||
* @param u Upper limit
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_between_inclusive(a, l, u, msg, ...) \
|
||||
zassert(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", msg, \
|
||||
#define zassert_between_inclusive(a, l, u, ...) \
|
||||
zassert(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
|
||||
##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
|
@ -311,10 +308,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* @param buf Buffer to compare
|
||||
* @param exp Buffer with expected contents
|
||||
* @param size Size of buffers
|
||||
* @param msg Optional message to print if the assertion fails
|
||||
* @param ... Optional message and variables to print if the assertion fails
|
||||
*/
|
||||
#define zassert_mem_equal__(buf, exp, size, msg, ...) \
|
||||
zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, msg, ##__VA_ARGS__)
|
||||
#define zassert_mem_equal__(buf, exp, size, ...) \
|
||||
zassert(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -335,9 +332,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* If the assumption fails, the test will be marked as "skipped".
|
||||
*
|
||||
* @param cond Condition to check
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_true(cond, msg, ...) zassume(cond, #cond " is false", msg, ##__VA_ARGS__)
|
||||
#define zassume_true(cond, ...) zassume(cond, #cond " is false", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a cond is false
|
||||
|
@ -345,9 +342,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* If the assumption fails, the test will be marked as "skipped".
|
||||
*
|
||||
* @param cond Condition to check
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_false(cond, msg, ...) zassume(!(cond), #cond " is true", msg, ##__VA_ARGS__)
|
||||
#define zassume_false(cond, ...) zassume(!(cond), #cond " is true", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a cond is 0 (success)
|
||||
|
@ -355,9 +352,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* If the assumption fails, the test will be marked as "skipped".
|
||||
*
|
||||
* @param cond Condition to check
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_ok(cond, msg, ...) zassume(!(cond), #cond " is non-zero", msg, ##__VA_ARGS__)
|
||||
#define zassume_ok(cond, ...) zassume(!(cond), #cond " is non-zero", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a ptr is NULL
|
||||
|
@ -365,10 +362,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* If the assumption fails, the test will be marked as "skipped".
|
||||
*
|
||||
* @param ptr Pointer to compare
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_is_null(ptr, msg, ...) \
|
||||
zassume((ptr) == NULL, #ptr " is not NULL", msg, ##__VA_ARGS__)
|
||||
#define zassume_is_null(ptr, ...) zassume((ptr) == NULL, #ptr " is not NULL", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a ptr is not NULL
|
||||
|
@ -376,9 +372,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* If the assumption fails, the test will be marked as "skipped".
|
||||
*
|
||||
* @param ptr Pointer to compare
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_not_null(ptr, msg, ...) zassume((ptr) != NULL, #ptr " is NULL", msg, ##__VA_ARGS__)
|
||||
#define zassume_not_null(ptr, ...) zassume((ptr) != NULL, #ptr " is NULL", ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a a equals @a b
|
||||
|
@ -388,10 +384,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
*
|
||||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_equal(a, b, msg, ...) \
|
||||
zassume((a) == (b), #a " not equal to " #b, msg, ##__VA_ARGS__)
|
||||
#define zassume_equal(a, b, ...) zassume((a) == (b), #a " not equal to " #b, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a a does not equal @a b
|
||||
|
@ -401,10 +396,9 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
*
|
||||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_not_equal(a, b, msg, ...) \
|
||||
zassume((a) != (b), #a " equal to " #b, msg, ##__VA_ARGS__)
|
||||
#define zassume_not_equal(a, b, ...) zassume((a) != (b), #a " equal to " #b, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a a equals @a b
|
||||
|
@ -414,10 +408,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
*
|
||||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_equal_ptr(a, b, msg, ...) \
|
||||
zassume((void *)(a) == (void *)(b), #a " not equal to " #b, msg, ##__VA_ARGS__)
|
||||
#define zassume_equal_ptr(a, b, ...) \
|
||||
zassume((void *)(a) == (void *)(b), #a " not equal to " #b, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a a is within @a b with delta @a d
|
||||
|
@ -427,11 +421,11 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* @param a Value to compare
|
||||
* @param b Value to compare
|
||||
* @param d Delta
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_within(a, b, d, msg, ...) \
|
||||
#define zassume_within(a, b, d, ...) \
|
||||
zassume(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), #a " not within " #b " +/- " #d, \
|
||||
msg, ##__VA_ARGS__)
|
||||
##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @brief Assume that @a a is greater than or equal to @a l and less
|
||||
|
@ -442,10 +436,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* @param a Value to compare
|
||||
* @param l Lower limit
|
||||
* @param u Upper limit
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_between_inclusive(a, l, u, msg, ...) \
|
||||
zassume(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", msg, \
|
||||
#define zassume_between_inclusive(a, l, u, ...) \
|
||||
zassume(((a) >= (l)) && ((a) <= (u)), #a " not between " #l " and " #u " inclusive", \
|
||||
##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
|
@ -472,10 +466,10 @@ static inline bool z_zassume(bool cond, const char *default_msg, const char *fil
|
|||
* @param buf Buffer to compare
|
||||
* @param exp Buffer with expected contents
|
||||
* @param size Size of buffers
|
||||
* @param msg Optional message to print if the assumption fails
|
||||
* @param ... Optional message and variables to print if the assumption fails
|
||||
*/
|
||||
#define zassume_mem_equal__(buf, exp, size, msg, ...) \
|
||||
zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, msg, ##__VA_ARGS__)
|
||||
#define zassume_mem_equal__(buf, exp, size, ...) \
|
||||
zassume(memcmp(buf, exp, size) == 0, #buf " not equal to " #exp, ##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue