Skip to content

Commit

Permalink
ztest: fix z_assert_within() bounds
Browse files Browse the repository at this point in the history
zassert_within should also compare on equality instead
of only greater/lower.
example:
zassert_within(1,1,0); // should return true
zassert_within(1,2,1); // should return true

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
  • Loading branch information
alexanderwachter authored and nashif committed Feb 19, 2021
1 parent 0e64b47 commit cb97dd1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subsys/testsuite/ztest/include/ztest_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static inline void z_zassert(bool cond,
* @param msg Optional message to print if the assertion fails
*/
#define zassert_within(a, b, d, msg, ...) \
zassert(((a) > ((b) - (d))) && ((a) < ((b) + (d))), \
zassert(((a) >= ((b) - (d))) && ((a) <= ((b) + (d))), \
#a " not within " #b " +/- " #d, \
msg, ##__VA_ARGS__)

Expand Down

0 comments on commit cb97dd1

Please sign in to comment.