Skip to content

Commit

Permalink
kunit: fix assert_type for comparison macros
Browse files Browse the repository at this point in the history
[ Upstream commit aded3ca ]

When replacing KUNIT_BINARY_*_MSG_ASSERTION() macros with
KUNIT_BINARY_INT_ASSERTION(), the assert_type parameter was not always
correctly transferred.  Specifically, the following errors were
introduced:
  - KUNIT_EXPECT_LE_MSG() uses KUNIT_ASSERTION
  - KUNIT_ASSERT_LT_MSG() uses KUNIT_EXPECTATION
  - KUNIT_ASSERT_GT_MSG() uses KUNIT_EXPECTATION

A failing KUNIT_EXPECT_LE_MSG() test thus prevents further tests from
running, while failing KUNIT_ASSERT_{LT,GT}_MSG() tests do not prevent
further tests from running.  This is contrary to the documentation,
which states that failing KUNIT_EXPECT_* macros allow further tests to
run, while failing KUNIT_ASSERT_* macros should prevent this.

Revert the KUNIT_{ASSERTION,EXPECTATION} switches to fix the behaviour
for the affected macros.

Fixes: 40f3977 ("kunit: decrease macro layering for integer asserts")
Signed-off-by: Sander Vanheule <sander@svanheule.net>
Reviewed-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
svanheule authored and gregkh committed Sep 15, 2022
1 parent adbb4a4 commit c07642f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/kunit/test.h
Expand Up @@ -863,7 +863,7 @@ do { \

#define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
KUNIT_EXPECTATION, \
left, <=, right, \
fmt, \
##__VA_ARGS__)
Expand Down Expand Up @@ -1153,7 +1153,7 @@ do { \

#define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
KUNIT_ASSERTION, \
left, <, right, \
fmt, \
##__VA_ARGS__)
Expand Down Expand Up @@ -1194,7 +1194,7 @@ do { \

#define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
KUNIT_ASSERTION, \
left, >, right, \
fmt, \
##__VA_ARGS__)
Expand Down

0 comments on commit c07642f

Please sign in to comment.