Skip to content

Commit

Permalink
testsuite: ztest: Add zassert_within macro
Browse files Browse the repository at this point in the history
Added macro to test value against another value with
accepted delta.

Signed-off-by: Krzysztof Chruscinski <[email protected]>
  • Loading branch information
nordic-krch authored and nashif committed May 8, 2019
1 parent 44739f4 commit 7a2d025
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions subsys/testsuite/ztest/include/ztest_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ static inline void z_zassert(int cond,
zassert((void *)(a) == (void *)(b), #a " not equal to " #b, \
msg, ##__VA_ARGS__)

/**
* @brief Assert that @a a is within @a b with delta @a d
*
* @param a Value to compare
* @param b Value to compare
* @param d Delta
* @param msg Optional message to print if the assertion fails
*/
#define zassert_within(a, b, d, msg, ...) \
zassert(((a) > ((b) - (d))) && ((a) < ((b) + (d))), \
#a " not within " #b " +/- " #d, \
msg, ##__VA_ARGS__)

/**
* @brief Assert that 2 memory buffers have the same contents
*
Expand Down

0 comments on commit 7a2d025

Please sign in to comment.