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>
This commit is contained in:
Krzysztof Chruscinski 2019-04-12 16:01:52 +02:00 committed by Anas Nashif
commit 7a2d025bce

View file

@ -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
*