Skip to content
Permalink
Browse files

testsuite: ztest: Add zassert_within macro

Added macro to test value against another value with
accepted delta.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information...
nordic-krch authored and nashif committed Apr 12, 2019
1 parent 44739f4 commit 7a2d025bce43f2f381891d5b5be43646c238fe4a
Showing with 13 additions and 0 deletions.
  1. +13 −0 subsys/testsuite/ztest/include/ztest_assert.h
@@ -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
*

0 comments on commit 7a2d025

Please sign in to comment.
You can’t perform that action at this time.