Note: this series applies on top of the series reducing stack usage, https://lore.kernel.org/linux-kselftest/20220113165931.451305-1-dlatypov@goo... There's no real smenatic dependency between these, just potential for merge conflicts.
The current layout of the assertion macros is confusing.
Here's the call chain for KUNIT_EXPECT_EQ() and KUNIT_EXPECT_EQ_MSG() KUNIT_EXPECT_EQ => KUNIT_BINARY_EQ_ASSERTION => # note: not shared with the _MSG variant KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
After this series KUNIT_EXPECT_EQ => KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
The current macro layout tries hard to reduce duplication, but comes at the cost of a lot of intermediates that can simply vanish.
The same call-chain again, but annotated with the info we add: KUNIT_EXPECT_EQ => specify we're an EXPECT, not an ASSERT KUNIT_BINARY_EQ_ASSERTION => specify we have a NULL msg KUNIT_BINARY_EQ_MSG_ASSERTION => specify we work with ints, not ptrs KUNIT_BASE_EQ_MSG_ASSERTION => specify that the op is '==' KUNIT_BASE_BINARY_ASSERTION
We can see that each level of the chain only specifes one parameter at a time. We've taken the concept of DRY too far.
The following is a full snippet of all the macros needed for KUNIT_EXPECT_EQ, showing that a bit of repetition is just fine: #define KUNIT_BINARY_INT_ASSERTION(test, \ assert_type, \ left, \ op, \ right, \ fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, op, right, \ fmt, \ ##__VA_ARGS__)
#define KUNIT_EXPECT_EQ(test, left, right) \ KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_INT_ASSERTION(test, \ KUNIT_EXPECTATION, \ left, ==, right, \ fmt, \ ##__VA_ARGS__)
as opposed to our current DRYer version
#define KUNIT_BASE_EQ_MSG_ASSERTION(test, \ assert_class, \ ASSERT_CLASS_INIT, \ assert_type, \ left, \ right, \ fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \ assert_class, \ ASSERT_CLASS_INIT, \ assert_type, \ left, ==, right, \ fmt, \ ##__VA_ARGS__)
#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_EQ_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, \ right, \ fmt, \ ##__VA_ARGS__)
#define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \ KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ assert_type, \ left, \ right, \ NULL) #define KUNIT_EXPECT_EQ(test, left, right) \ KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ KUNIT_EXPECTATION, \ left, \ right, \ fmt, \ ##__VA_ARGS__)
Daniel Latypov (5): kunit: make KUNIT_EXPECT_EQ() use KUNIT_EXPECT_EQ_MSG(), etc. kunit: drop unused intermediate macros for ptr inequality checks kunit: reduce layering in string assertion macros kunit: decrease macro layering for integer asserts kunit: decrease macro layering for EQ/NE asserts
include/kunit/test.h | 660 ++++++++++--------------------------------- 1 file changed, 142 insertions(+), 518 deletions(-)
There's quite a few macros in play for KUnit assertions.
The current macro chain looks like: KUNIT_EXPECT_EQ => KUNIT_BINARY_EQ_ASSERTION => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ => KUNIT_BINARY_EQ_ASSERTION => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION
After this change: KUNIT_EXPECT_EQ => KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ => KUNIT_ASSERT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION and we can drop the intermediate KUNIT_BINARY_EQ_ASSERTION.
This change does this for all the other macros as well.
Signed-off-by: Daniel Latypov dlatypov@google.com --- include/kunit/test.h | 168 +++++++------------------------------------ 1 file changed, 26 insertions(+), 142 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index 5964af750d93..b032dd6816d2 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -840,9 +840,6 @@ void kunit_do_failed_assertion(struct kunit *test, fmt, \ ##__VA_ARGS__)
-#define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \ - KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL) - #define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ KUNIT_UNARY_ASSERTION(test, \ assert_type, \ @@ -851,9 +848,6 @@ void kunit_do_failed_assertion(struct kunit *test, fmt, \ ##__VA_ARGS__)
-#define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \ - KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL) - /* * A factory macro for defining the assertions and expectations for the basic * comparisons defined for the built in types. @@ -1000,13 +994,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1022,13 +1009,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_NE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1039,13 +1019,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_NE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1061,13 +1034,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_LT_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1078,13 +1044,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_LT_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1100,13 +1059,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_LE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1117,13 +1069,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_LE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1139,13 +1084,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GT_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1156,13 +1094,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_GT_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1178,13 +1109,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1195,13 +1119,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_GE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1217,13 +1134,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_STR_ASSERTION(test, \ assert_type, \ left, \ @@ -1260,13 +1170,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1279,13 +1182,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \ - KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - NULL) - #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ assert_type, \ ptr, \ @@ -1304,12 +1200,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \ - KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ - assert_type, \ - ptr, \ - NULL) - /** * KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true. * @test: The test context object. @@ -1322,7 +1212,7 @@ do { \ * *expectation failure*. */ #define KUNIT_EXPECT_TRUE(test, condition) \ - KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition) + KUNIT_EXPECT_TRUE_MSG(test, condition, NULL)
#define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \ KUNIT_TRUE_MSG_ASSERTION(test, \ @@ -1341,7 +1231,7 @@ do { \ * KUNIT_EXPECT_TRUE() for more information. */ #define KUNIT_EXPECT_FALSE(test, condition) \ - KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition) + KUNIT_EXPECT_FALSE_MSG(test, condition, NULL)
#define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \ KUNIT_FALSE_MSG_ASSERTION(test, \ @@ -1362,7 +1252,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_EQ(test, left, right) \ - KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ @@ -1384,10 +1274,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_PTR_EQ(test, left, right) \ - KUNIT_BINARY_PTR_EQ_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right) + KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ @@ -1409,7 +1296,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_NE(test, left, right) \ - KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_NE_MSG_ASSERTION(test, \ @@ -1431,10 +1318,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_PTR_NE(test, left, right) \ - KUNIT_BINARY_PTR_NE_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right) + KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ @@ -1456,7 +1340,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_LT(test, left, right) \ - KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LT_MSG_ASSERTION(test, \ @@ -1478,7 +1362,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_LE(test, left, right) \ - KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LE_MSG_ASSERTION(test, \ @@ -1500,7 +1384,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_GT(test, left, right) \ - KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GT_MSG_ASSERTION(test, \ @@ -1522,7 +1406,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_GE(test, left, right) \ - KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GE_MSG_ASSERTION(test, \ @@ -1544,7 +1428,7 @@ do { \ * for more information. */ #define KUNIT_EXPECT_STREQ(test, left, right) \ - KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ @@ -1566,7 +1450,7 @@ do { \ * for more information. */ #define KUNIT_EXPECT_STRNEQ(test, left, right) \ - KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right) + KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ @@ -1587,7 +1471,7 @@ do { \ * more information. */ #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \ - KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr) + KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
#define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ @@ -1611,7 +1495,7 @@ do { \ * this is otherwise known as an *assertion failure*. */ #define KUNIT_ASSERT_TRUE(test, condition) \ - KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition) + KUNIT_ASSERT_TRUE_MSG(test, condition, NULL)
#define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \ KUNIT_TRUE_MSG_ASSERTION(test, \ @@ -1630,7 +1514,7 @@ do { \ * (see KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_FALSE(test, condition) \ - KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition) + KUNIT_ASSERT_FALSE_MSG(test, condition, NULL)
#define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \ KUNIT_FALSE_MSG_ASSERTION(test, \ @@ -1650,7 +1534,7 @@ do { \ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_EQ(test, left, right) \ - KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ @@ -1671,7 +1555,7 @@ do { \ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_PTR_EQ(test, left, right) \ - KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ @@ -1692,7 +1576,7 @@ do { \ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_NE(test, left, right) \ - KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_NE_MSG_ASSERTION(test, \ @@ -1714,7 +1598,7 @@ do { \ * failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_PTR_NE(test, left, right) \ - KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ @@ -1735,7 +1619,7 @@ do { \ * is not met. */ #define KUNIT_ASSERT_LT(test, left, right) \ - KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LT_MSG_ASSERTION(test, \ @@ -1756,7 +1640,7 @@ do { \ * KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_LE(test, left, right) \ - KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LE_MSG_ASSERTION(test, \ @@ -1778,7 +1662,7 @@ do { \ * is not met. */ #define KUNIT_ASSERT_GT(test, left, right) \ - KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GT_MSG_ASSERTION(test, \ @@ -1800,7 +1684,7 @@ do { \ * is not met. */ #define KUNIT_ASSERT_GE(test, left, right) \ - KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GE_MSG_ASSERTION(test, \ @@ -1821,7 +1705,7 @@ do { \ * assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_STREQ(test, left, right) \ - KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ @@ -1843,7 +1727,7 @@ do { \ * for more information. */ #define KUNIT_ASSERT_STRNEQ(test, left, right) \ - KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right) + KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ @@ -1864,7 +1748,7 @@ do { \ * KUNIT_ASSERT_TRUE()) when the assertion is not met. */ #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \ - KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr) + KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
#define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
On Wed, Jan 19, 2022 at 6:35 AM Daniel Latypov dlatypov@google.com wrote:
There's quite a few macros in play for KUnit assertions.
The current macro chain looks like: KUNIT_EXPECT_EQ => KUNIT_BINARY_EQ_ASSERTION => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ => KUNIT_BINARY_EQ_ASSERTION => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION
After this change: KUNIT_EXPECT_EQ => KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ => KUNIT_ASSERT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION and we can drop the intermediate KUNIT_BINARY_EQ_ASSERTION.
This change does this for all the other macros as well.
Signed-off-by: Daniel Latypov dlatypov@google.com
The sheer number of macros here was always a bit headache-inducing for me, so this is a great improvement in my book. Thanks!
Reviewed-by: David Gow davidgow@google.com
include/kunit/test.h | 168 +++++++------------------------------------ 1 file changed, 26 insertions(+), 142 deletions(-)
(It's great to see 116 fewer lines here!)
-- David
diff --git a/include/kunit/test.h b/include/kunit/test.h index 5964af750d93..b032dd6816d2 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -840,9 +840,6 @@ void kunit_do_failed_assertion(struct kunit *test, fmt, \ ##__VA_ARGS__)
-#define KUNIT_TRUE_ASSERTION(test, assert_type, condition) \
KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, NULL)
#define KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ KUNIT_UNARY_ASSERTION(test, \ assert_type, \ @@ -851,9 +848,6 @@ void kunit_do_failed_assertion(struct kunit *test, fmt, \ ##__VA_ARGS__)
-#define KUNIT_FALSE_ASSERTION(test, assert_type, condition) \
KUNIT_FALSE_MSG_ASSERTION(test, assert_type, condition, NULL)
/*
- A factory macro for defining the assertions and expectations for the basic
- comparisons defined for the built in types.
@@ -1000,13 +994,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_EQ_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1022,13 +1009,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_EQ_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_NE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1039,13 +1019,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_NE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_NE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1061,13 +1034,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_NE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_LT_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1078,13 +1044,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_LT_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_LT_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1100,13 +1059,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LT_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_LE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1117,13 +1069,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_LE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_LE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1139,13 +1084,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GT_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1156,13 +1094,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_GT_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_GT_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1178,13 +1109,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GT_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1195,13 +1119,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_GE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1217,13 +1134,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_STR_ASSERTION(test, \ assert_type, \ left, \ @@ -1260,13 +1170,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_STR_EQ_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ assert_type, \ left, \ @@ -1279,13 +1182,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_STR_NE_ASSERTION(test, assert_type, left, right) \
KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
NULL)
#define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ assert_type, \ ptr, \ @@ -1304,12 +1200,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, assert_type, ptr) \
KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
assert_type, \
ptr, \
NULL)
/**
- KUNIT_EXPECT_TRUE() - Causes a test failure when the expression is not true.
- @test: The test context object.
@@ -1322,7 +1212,7 @@ do { \
- *expectation failure*.
*/ #define KUNIT_EXPECT_TRUE(test, condition) \
KUNIT_TRUE_ASSERTION(test, KUNIT_EXPECTATION, condition)
KUNIT_EXPECT_TRUE_MSG(test, condition, NULL)
#define KUNIT_EXPECT_TRUE_MSG(test, condition, fmt, ...) \ KUNIT_TRUE_MSG_ASSERTION(test, \ @@ -1341,7 +1231,7 @@ do { \
- KUNIT_EXPECT_TRUE() for more information.
*/ #define KUNIT_EXPECT_FALSE(test, condition) \
KUNIT_FALSE_ASSERTION(test, KUNIT_EXPECTATION, condition)
KUNIT_EXPECT_FALSE_MSG(test, condition, NULL)
#define KUNIT_EXPECT_FALSE_MSG(test, condition, fmt, ...) \ KUNIT_FALSE_MSG_ASSERTION(test, \ @@ -1362,7 +1252,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_EQ(test, left, right) \
KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ @@ -1384,10 +1274,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_PTR_EQ(test, left, right) \
KUNIT_BINARY_PTR_EQ_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right)
KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ @@ -1409,7 +1296,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_NE(test, left, right) \
KUNIT_BINARY_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_NE_MSG_ASSERTION(test, \ @@ -1431,10 +1318,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_PTR_NE(test, left, right) \
KUNIT_BINARY_PTR_NE_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right)
KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ @@ -1456,7 +1340,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_LT(test, left, right) \
KUNIT_BINARY_LT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LT_MSG_ASSERTION(test, \ @@ -1478,7 +1362,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_LE(test, left, right) \
KUNIT_BINARY_LE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LE_MSG_ASSERTION(test, \ @@ -1500,7 +1384,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_GT(test, left, right) \
KUNIT_BINARY_GT_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GT_MSG_ASSERTION(test, \ @@ -1522,7 +1406,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_GE(test, left, right) \
KUNIT_BINARY_GE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GE_MSG_ASSERTION(test, \ @@ -1544,7 +1428,7 @@ do { \
- for more information.
*/ #define KUNIT_EXPECT_STREQ(test, left, right) \
KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ @@ -1566,7 +1450,7 @@ do { \
- for more information.
*/ #define KUNIT_EXPECT_STRNEQ(test, left, right) \
KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_EXPECTATION, left, right)
KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ @@ -1587,7 +1471,7 @@ do { \
- more information.
*/ #define KUNIT_EXPECT_NOT_ERR_OR_NULL(test, ptr) \
KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_EXPECTATION, ptr)
KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
#define KUNIT_EXPECT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ @@ -1611,7 +1495,7 @@ do { \
- this is otherwise known as an *assertion failure*.
*/ #define KUNIT_ASSERT_TRUE(test, condition) \
KUNIT_TRUE_ASSERTION(test, KUNIT_ASSERTION, condition)
KUNIT_ASSERT_TRUE_MSG(test, condition, NULL)
#define KUNIT_ASSERT_TRUE_MSG(test, condition, fmt, ...) \ KUNIT_TRUE_MSG_ASSERTION(test, \ @@ -1630,7 +1514,7 @@ do { \
- (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_FALSE(test, condition) \
KUNIT_FALSE_ASSERTION(test, KUNIT_ASSERTION, condition)
KUNIT_ASSERT_FALSE_MSG(test, condition, NULL)
#define KUNIT_ASSERT_FALSE_MSG(test, condition, fmt, ...) \ KUNIT_FALSE_MSG_ASSERTION(test, \ @@ -1650,7 +1534,7 @@ do { \
- failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_EQ(test, left, right) \
KUNIT_BINARY_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ @@ -1671,7 +1555,7 @@ do { \
- failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_PTR_EQ(test, left, right) \
KUNIT_BINARY_PTR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ @@ -1692,7 +1576,7 @@ do { \
- failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_NE(test, left, right) \
KUNIT_BINARY_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_NE_MSG_ASSERTION(test, \ @@ -1714,7 +1598,7 @@ do { \
- failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_PTR_NE(test, left, right) \
KUNIT_BINARY_PTR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ @@ -1735,7 +1619,7 @@ do { \
- is not met.
*/ #define KUNIT_ASSERT_LT(test, left, right) \
KUNIT_BINARY_LT_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LT_MSG_ASSERTION(test, \ @@ -1756,7 +1640,7 @@ do { \
- KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_LE(test, left, right) \
KUNIT_BINARY_LE_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_LE_MSG_ASSERTION(test, \ @@ -1778,7 +1662,7 @@ do { \
- is not met.
*/ #define KUNIT_ASSERT_GT(test, left, right) \
KUNIT_BINARY_GT_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GT_MSG_ASSERTION(test, \ @@ -1800,7 +1684,7 @@ do { \
- is not met.
*/ #define KUNIT_ASSERT_GE(test, left, right) \
KUNIT_BINARY_GE_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_GE_MSG_ASSERTION(test, \ @@ -1821,7 +1705,7 @@ do { \
- assertion failure (see KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_STREQ(test, left, right) \
KUNIT_BINARY_STR_EQ_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ @@ -1843,7 +1727,7 @@ do { \
- for more information.
*/ #define KUNIT_ASSERT_STRNEQ(test, left, right) \
KUNIT_BINARY_STR_NE_ASSERTION(test, KUNIT_ASSERTION, left, right)
KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \ KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ @@ -1864,7 +1748,7 @@ do { \
- KUNIT_ASSERT_TRUE()) when the assertion is not met.
*/ #define KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ptr) \
KUNIT_PTR_NOT_ERR_OR_NULL_ASSERTION(test, KUNIT_ASSERTION, ptr)
KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, NULL)
#define KUNIT_ASSERT_NOT_ERR_OR_NULL_MSG(test, ptr, fmt, ...) \ KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ -- 2.34.1.703.g22d0c6ccf7-goog
On Tue, Jan 18, 2022 at 5:35 PM Daniel Latypov dlatypov@google.com wrote:
There's quite a few macros in play for KUnit assertions.
The current macro chain looks like: KUNIT_EXPECT_EQ => KUNIT_BINARY_EQ_ASSERTION => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ => KUNIT_BINARY_EQ_ASSERTION => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION
After this change: KUNIT_EXPECT_EQ => KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION KUNIT_ASSERT_EQ => KUNIT_ASSERT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION and we can drop the intermediate KUNIT_BINARY_EQ_ASSERTION.
This change does this for all the other macros as well.
Signed-off-by: Daniel Latypov dlatypov@google.com
Reviewed-by: Brendan Higgins brendanhiggins@google.com
We have the intermediate macros for KUNIT_EXPECT_PTR_GT() and friends, but these macros don't exist.
I can see niche usecases for these macros existing, but since we've been fine without them for so long, let's drop this dead code.
Users can instead cast the pointers and use the other GT/LT macros.
Signed-off-by: Daniel Latypov dlatypov@google.com --- include/kunit/test.h | 60 -------------------------------------------- 1 file changed, 60 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index b032dd6816d2..c021945a75e3 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1044,21 +1044,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_LT_MSG_ASSERTION(test, \ - kunit_binary_ptr_assert, \ - KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_LE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1069,21 +1054,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_LE_MSG_ASSERTION(test, \ - kunit_binary_ptr_assert, \ - KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GT_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1094,21 +1064,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_GT_MSG_ASSERTION(test, \ - kunit_binary_ptr_assert, \ - KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1119,21 +1074,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_GE_MSG_ASSERTION(test, \ - kunit_binary_ptr_assert, \ - KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_BINARY_STR_ASSERTION(test, \ assert_type, \ left, \
On Wed, Jan 19, 2022 at 6:35 AM 'Daniel Latypov' via KUnit Development kunit-dev@googlegroups.com wrote:
We have the intermediate macros for KUNIT_EXPECT_PTR_GT() and friends, but these macros don't exist.
I can see niche usecases for these macros existing, but since we've been fine without them for so long, let's drop this dead code.
Users can instead cast the pointers and use the other GT/LT macros.
Signed-off-by: Daniel Latypov dlatypov@google.com
Agreed: while I can sort-of see why one might want to use something like this for bounds checking, casting to an integer is definitely acceptable (and we've got things like KASAN and fortify-source for many bounds-checking cases anyway).
Also, many languages explicitly treat pointers as not being comparable this way anyway, and rely on casting to integer, which is a trend worth following, I think.
Reviewed-by: David Gow davidgow@google.com
Cheers, -- David
include/kunit/test.h | 60 -------------------------------------------- 1 file changed, 60 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index b032dd6816d2..c021945a75e3 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1044,21 +1044,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LT_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_LT_MSG_ASSERTION(test, \
kunit_binary_ptr_assert, \
KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_LE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1069,21 +1054,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_LE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_LE_MSG_ASSERTION(test, \
kunit_binary_ptr_assert, \
KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GT_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1094,21 +1064,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GT_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_GT_MSG_ASSERTION(test, \
kunit_binary_ptr_assert, \
KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ KUNIT_BASE_GE_MSG_ASSERTION(test, \ kunit_binary_assert, \ @@ -1119,21 +1074,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_GE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_GE_MSG_ASSERTION(test, \
kunit_binary_ptr_assert, \
KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_STR_ASSERTION(test, \ assert_type, \ left, \ -- 2.34.1.703.g22d0c6ccf7-goog
-- You received this message because you are subscribed to the Google Groups "KUnit Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220118223506.1701553-3-dlatypo....
On Tue, Jan 18, 2022 at 5:35 PM Daniel Latypov dlatypov@google.com wrote:
We have the intermediate macros for KUNIT_EXPECT_PTR_GT() and friends, but these macros don't exist.
I can see niche usecases for these macros existing, but since we've been fine without them for so long, let's drop this dead code.
Users can instead cast the pointers and use the other GT/LT macros.
Signed-off-by: Daniel Latypov dlatypov@google.com
Oh, whoops, I didn't even realize we were missing those variants.
Reviewed-by: Brendan Higgins brendanhiggins@google.com
The current macro chain looks like: KUNIT_EXPECT_STREQ => KUNIT_EXPECT_STREQ_MSG => KUNIT_BINARY_STR_EQ_MSG_ASSERTION => KUNIT_BINARY_STR_ASSERTION. KUNIT_ASSERT_STREQ => KUNIT_ASSERT_STREQ_MSG => KUNIT_BINARY_STR_EQ_MSG_ASSERTION => KUNIT_BINARY_STR_ASSERTION. <ditto for STR_NE>
After this change: KUNIT_EXPECT_STREQ => KUNIT_EXPECT_STREQ_MSG => KUNIT_BINARY_STR_ASSERTION. KUNIT_ASSERT_STREQ => KUNIT_ASSERT_STREQ_MSG => KUNIT_BINARY_STR_ASSERTION. <ditto for STR_NE>
All the intermediate macro did was pass in "==" or "!=", so it seems better to just drop them at the cost of a bit more copy-paste.
Signed-off-by: Daniel Latypov dlatypov@google.com --- include/kunit/test.h | 68 +++++++++++++------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index c021945a75e3..d5dc1ef68bfe 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1098,30 +1098,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BINARY_STR_ASSERTION(test, \ - assert_type, \ - left, ==, right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BINARY_STR_ASSERTION(test, \ - assert_type, \ - left, !=, right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ assert_type, \ ptr, \ @@ -1371,12 +1347,11 @@ do { \ KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_STR_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, ==, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal. @@ -1393,12 +1368,11 @@ do { \ KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_STR_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, !=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err. @@ -1648,12 +1622,11 @@ do { \ KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_STR_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, ==, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal. @@ -1670,12 +1643,11 @@ do { \ KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_STR_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, !=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
On Wed, Jan 19, 2022 at 6:35 AM Daniel Latypov dlatypov@google.com wrote:
The current macro chain looks like: KUNIT_EXPECT_STREQ => KUNIT_EXPECT_STREQ_MSG => KUNIT_BINARY_STR_EQ_MSG_ASSERTION => KUNIT_BINARY_STR_ASSERTION. KUNIT_ASSERT_STREQ => KUNIT_ASSERT_STREQ_MSG => KUNIT_BINARY_STR_EQ_MSG_ASSERTION => KUNIT_BINARY_STR_ASSERTION.
<ditto for STR_NE>
After this change: KUNIT_EXPECT_STREQ => KUNIT_EXPECT_STREQ_MSG => KUNIT_BINARY_STR_ASSERTION. KUNIT_ASSERT_STREQ => KUNIT_ASSERT_STREQ_MSG => KUNIT_BINARY_STR_ASSERTION.
<ditto for STR_NE>
All the intermediate macro did was pass in "==" or "!=", so it seems better to just drop them at the cost of a bit more copy-paste.
Signed-off-by: Daniel Latypov dlatypov@google.com
Agreed, I don't think the copy-paste here is significant enough to have any real chance of causing problems. This is clearly an improvement.
Reviewed-by: David Gow davidgow@google.com
-- David
include/kunit/test.h | 68 +++++++++++++------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index c021945a75e3..d5dc1ef68bfe 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -1098,30 +1098,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BINARY_STR_ASSERTION(test, \
assert_type, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BINARY_STR_ASSERTION(test, \
assert_type, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \ assert_type, \ ptr, \ @@ -1371,12 +1347,11 @@ do { \ KUNIT_EXPECT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STREQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_STR_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_STRNEQ() - Expects that strings @left and @right are not equal.
@@ -1393,12 +1368,11 @@ do { \ KUNIT_EXPECT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_STRNEQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_STR_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_NOT_ERR_OR_NULL() - Expects that @ptr is not null and not err.
@@ -1648,12 +1622,11 @@ do { \ KUNIT_ASSERT_STREQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STREQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_STR_EQ_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_STR_ASSERTION(test, \
KUNIT_ASSERTION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_STRNEQ() - Expects that strings @left and @right are not equal.
@@ -1670,12 +1643,11 @@ do { \ KUNIT_ASSERT_STRNEQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_STRNEQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_STR_NE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_STR_ASSERTION(test, \
KUNIT_ASSERTION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_NOT_ERR_OR_NULL() - Assertion that @ptr is not null and not err.
-- 2.34.1.703.g22d0c6ccf7-goog
On Tue, Jan 18, 2022 at 5:35 PM Daniel Latypov dlatypov@google.com wrote:
The current macro chain looks like: KUNIT_EXPECT_STREQ => KUNIT_EXPECT_STREQ_MSG => KUNIT_BINARY_STR_EQ_MSG_ASSERTION => KUNIT_BINARY_STR_ASSERTION. KUNIT_ASSERT_STREQ => KUNIT_ASSERT_STREQ_MSG => KUNIT_BINARY_STR_EQ_MSG_ASSERTION => KUNIT_BINARY_STR_ASSERTION.
<ditto for STR_NE>
After this change: KUNIT_EXPECT_STREQ => KUNIT_EXPECT_STREQ_MSG => KUNIT_BINARY_STR_ASSERTION. KUNIT_ASSERT_STREQ => KUNIT_ASSERT_STREQ_MSG => KUNIT_BINARY_STR_ASSERTION.
<ditto for STR_NE>
All the intermediate macro did was pass in "==" or "!=", so it seems better to just drop them at the cost of a bit more copy-paste.
Signed-off-by: Daniel Latypov dlatypov@google.com
Reviewed-by: Brendan Higgins brendanhiggins@google.com
Introduce a KUNIT_BINARY_INT_ASSERTION for the likes of KUNIT_EXPECT_LT. This is analagous to KUNIT_BINARY_STR_ASSERTION.
Note: this patch leaves the EQ/NE macros untouched since those share some intermediate macros for the pointer-based macros.
The current macro chain looks like: KUNIT_EXPECT_LT_MSG => KUNIT_BASE_LT_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_GT_MSG => KUNIT_BASE_GT_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION <ditto for LE, GE, and ASSERT variants>
After this change: KUNIT_EXPECT_LT_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_GT_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
I.e. we've traded all the unique intermediary macros for a single shared KUNIT_BINARY_INT_ASSERTION. The only difference is that users of KUNIT_BINARY_INT_ASSERTION also need to pass the operation (==, <, etc.).
Signed-off-by: Daniel Latypov dlatypov@google.com --- include/kunit/test.h | 199 +++++++++++-------------------------------- 1 file changed, 51 insertions(+), 148 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index d5dc1ef68bfe..48cf520b69ce 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -920,77 +920,28 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BASE_LT_MSG_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_BINARY_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, <, right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BASE_LE_MSG_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_BINARY_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, <=, right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BASE_GT_MSG_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ +#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ + KUNIT_BASE_EQ_MSG_ASSERTION(test, \ + kunit_binary_assert, \ + KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, \ right, \ fmt, \ - ...) \ - KUNIT_BASE_BINARY_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, >, right, \ - fmt, \ ##__VA_ARGS__)
-#define KUNIT_BASE_GE_MSG_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, \ - right, \ - fmt, \ +#define KUNIT_BINARY_INT_ASSERTION(test, \ + assert_type, \ + left, \ + op, \ + right, \ + fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, >=, right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_EQ_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ - left, \ - right, \ + left, op, right, \ fmt, \ ##__VA_ARGS__)
@@ -1034,46 +985,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_LT_MSG_ASSERTION(test, \ - kunit_binary_assert, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_LE_MSG_ASSERTION(test, \ - kunit_binary_assert, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_GT_MSG_ASSERTION(test, \ - kunit_binary_assert, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_GE_MSG_ASSERTION(test, \ - kunit_binary_assert, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_BINARY_STR_ASSERTION(test, \ assert_type, \ left, \ @@ -1259,12 +1170,11 @@ do { \ KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_LT_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, <, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right. @@ -1281,12 +1191,11 @@ do { \ KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_LE_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, <=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_GT() - An expectation that @left is greater than @right. @@ -1303,12 +1212,11 @@ do { \ KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_GT_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, >, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right. @@ -1325,12 +1233,11 @@ do { \ KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_GE_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, >=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal. @@ -1536,12 +1443,11 @@ do { \ KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_LT_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, <, right, \ + fmt, \ + ##__VA_ARGS__) /** * KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right. * @test: The test context object. @@ -1557,12 +1463,11 @@ do { \ KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_LE_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, <=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_GT() - An assertion that @left is greater than @right. @@ -1579,12 +1484,11 @@ do { \ KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_GT_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, >, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right. @@ -1601,12 +1505,11 @@ do { \ KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_GE_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, >=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
On Wed, Jan 19, 2022 at 6:35 AM Daniel Latypov dlatypov@google.com wrote:
Introduce a KUNIT_BINARY_INT_ASSERTION for the likes of KUNIT_EXPECT_LT. This is analagous to KUNIT_BINARY_STR_ASSERTION.
Note: this patch leaves the EQ/NE macros untouched since those share some intermediate macros for the pointer-based macros.
I didn't like this until I realised the next patch in the series fixes it. :-)
The current macro chain looks like: KUNIT_EXPECT_LT_MSG => KUNIT_BASE_LT_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_GT_MSG => KUNIT_BASE_GT_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION <ditto for LE, GE, and ASSERT variants>
After this change: KUNIT_EXPECT_LT_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_GT_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
I.e. we've traded all the unique intermediary macros for a single shared KUNIT_BINARY_INT_ASSERTION. The only difference is that users of KUNIT_BINARY_INT_ASSERTION also need to pass the operation (==, <, etc.).
Signed-off-by: Daniel Latypov dlatypov@google.com
This also seems like a win to me. While I'm not a huge fan of passing the operation into macros in general, it's so clearly an improvement here (and we're doing it elsewhere in the macros with good results) that I think it's a good idea in this case.
Reviewed-by: David Gow davidgow@google.com
-- David
include/kunit/test.h | 199 +++++++++++-------------------------------- 1 file changed, 51 insertions(+), 148 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index d5dc1ef68bfe..48cf520b69ce 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -920,77 +920,28 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BASE_LT_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, <, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BASE_LE_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, <=, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BASE_GT_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
+#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \ left, \ right, \ fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, >, right, \
fmt, \ ##__VA_ARGS__)
-#define KUNIT_BASE_GE_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
+#define KUNIT_BINARY_INT_ASSERTION(test, \
assert_type, \
left, \
op, \
right, \
fmt, \ ...) \ KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, >=, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_EQ_MSG_ASSERTION(test, \ kunit_binary_assert, \ KUNIT_INIT_BINARY_ASSERT_STRUCT, \ assert_type, \
left, \
right, \
left, op, right, \ fmt, \ ##__VA_ARGS__)
@@ -1034,46 +985,6 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_LT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_LT_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_LE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_LE_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_GT_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_GT_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_GE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_GE_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_STR_ASSERTION(test, \ assert_type, \ left, \ @@ -1259,12 +1170,11 @@ do { \ KUNIT_EXPECT_LT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LT_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_LT_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, <, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_LE() - Expects that @left is less than or equal to @right.
@@ -1281,12 +1191,11 @@ do { \ KUNIT_EXPECT_LE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_LE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_LE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, <=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_GT() - An expectation that @left is greater than @right.
@@ -1303,12 +1212,11 @@ do { \ KUNIT_EXPECT_GT_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GT_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_GT_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, >, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_GE() - Expects that @left is greater than or equal to @right.
@@ -1325,12 +1233,11 @@ do { \ KUNIT_EXPECT_GE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_GE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, >=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_STREQ() - Expects that strings @left and @right are equal.
@@ -1536,12 +1443,11 @@ do { \ KUNIT_ASSERT_LT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LT_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_LT_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, <, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_LE() - An assertion that @left is less than or equal to @right.
- @test: The test context object.
@@ -1557,12 +1463,11 @@ do { \ KUNIT_ASSERT_LE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_LE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_LE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, <=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_GT() - An assertion that @left is greater than @right.
@@ -1579,12 +1484,11 @@ do { \ KUNIT_ASSERT_GT_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GT_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_GT_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, >, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_GE() - Assertion that @left is greater than or equal to @right.
@@ -1601,12 +1505,11 @@ do { \ KUNIT_ASSERT_GE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_GE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_GE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, >=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_STREQ() - An assertion that strings @left and @right are equal.
-- 2.34.1.703.g22d0c6ccf7-goog
On Tue, Jan 18, 2022 at 5:35 PM Daniel Latypov dlatypov@google.com wrote:
Introduce a KUNIT_BINARY_INT_ASSERTION for the likes of KUNIT_EXPECT_LT. This is analagous to KUNIT_BINARY_STR_ASSERTION.
Note: this patch leaves the EQ/NE macros untouched since those share some intermediate macros for the pointer-based macros.
The current macro chain looks like: KUNIT_EXPECT_LT_MSG => KUNIT_BASE_LT_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_GT_MSG => KUNIT_BASE_GT_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION <ditto for LE, GE, and ASSERT variants>
After this change: KUNIT_EXPECT_LT_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_GT_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
I.e. we've traded all the unique intermediary macros for a single shared KUNIT_BINARY_INT_ASSERTION. The only difference is that users of KUNIT_BINARY_INT_ASSERTION also need to pass the operation (==, <, etc.).
Signed-off-by: Daniel Latypov dlatypov@google.com
Reviewed-by: Brendan Higgins brendanhiggins@google.com
Introduce KUNIT_BINARY_PTR_ASSERTION to match KUNIT_BINARY_INT_ASSERTION and make KUNIT_EXPECT_EQ and KUNIT_EXPECT_PTREQ use these instead of shared intermediate macros that only remove the need to type "==" or "!=".
The current macro chain looks like: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION <ditto for NE and ASSERT>
After this change: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
Signed-off-by: Daniel Latypov dlatypov@google.com --- include/kunit/test.h | 173 ++++++++++++------------------------------- 1 file changed, 49 insertions(+), 124 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index 48cf520b69ce..bf82c313223b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -888,48 +888,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_BASE_EQ_MSG_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_BINARY_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, ==, right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BASE_NE_MSG_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_BINARY_ASSERTION(test, \ - assert_class, \ - ASSERT_CLASS_INIT, \ - assert_type, \ - left, !=, right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_EQ_MSG_ASSERTION(test, \ - kunit_binary_assert, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - #define KUNIT_BINARY_INT_ASSERTION(test, \ assert_type, \ left, \ @@ -945,43 +903,18 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_EQ_MSG_ASSERTION(test, \ - kunit_binary_ptr_assert, \ - KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\ - KUNIT_BASE_NE_MSG_ASSERTION(test, \ - kunit_binary_assert, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) - -#define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ - assert_type, \ - left, \ - right, \ - fmt, \ - ...) \ - KUNIT_BASE_NE_MSG_ASSERTION(test, \ +#define KUNIT_BINARY_PTR_ASSERTION(test, \ + assert_type, \ + left, \ + op, \ + right, \ + fmt, \ + ...) \ + KUNIT_BASE_BINARY_ASSERTION(test, \ kunit_binary_ptr_assert, \ KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ assert_type, \ - left, \ - right, \ + left, op, right, \ fmt, \ ##__VA_ARGS__)
@@ -1082,12 +1015,11 @@ do { \ KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, ==, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal. @@ -1104,12 +1036,11 @@ do { \ KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_PTR_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, ==, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal. @@ -1126,12 +1057,11 @@ do { \ KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_NE_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, !=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal. @@ -1148,12 +1078,11 @@ do { \ KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ - KUNIT_EXPECTATION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_PTR_ASSERTION(test, \ + KUNIT_EXPECTATION, \ + left, !=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_EXPECT_LT() - An expectation that @left is less than @right. @@ -1358,12 +1287,11 @@ do { \ KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_EQ_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, ==, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal. @@ -1379,12 +1307,11 @@ do { \ KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_PTR_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, ==, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal. @@ -1400,12 +1327,11 @@ do { \ KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_NE_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_INT_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, !=, right, \ + fmt, \ + ##__VA_ARGS__)
/** * KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal. @@ -1422,12 +1348,11 @@ do { \ KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \ - KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \ - KUNIT_ASSERTION, \ - left, \ - right, \ - fmt, \ - ##__VA_ARGS__) + KUNIT_BINARY_PTR_ASSERTION(test, \ + KUNIT_ASSERTION, \ + left, !=, right, \ + fmt, \ + ##__VA_ARGS__) /** * KUNIT_ASSERT_LT() - An assertion that @left is less than @right. * @test: The test context object.
On Wed, Jan 19, 2022 at 6:35 AM Daniel Latypov dlatypov@google.com wrote:
Introduce KUNIT_BINARY_PTR_ASSERTION to match KUNIT_BINARY_INT_ASSERTION and make KUNIT_EXPECT_EQ and KUNIT_EXPECT_PTREQ use these instead of shared intermediate macros that only remove the need to type "==" or "!=".
The current macro chain looks like: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
<ditto for NE and ASSERT>
After this change: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
Signed-off-by: Daniel Latypov dlatypov@google.com
This is great: the macros are much simpler and nicer now. In fact, this whole series is one of the nicest I've seen for a while: I can't think of any serious downsides to any of it.
Reviewed-by: David Gow davidgow@google.com
Thanks, -- David
include/kunit/test.h | 173 ++++++++++++------------------------------- 1 file changed, 49 insertions(+), 124 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index 48cf520b69ce..bf82c313223b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -888,48 +888,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BASE_NE_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_INT_ASSERTION(test, \ assert_type, \ left, \ @@ -945,43 +903,18 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
kunit_binary_ptr_assert, \
KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_NE_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_NE_MSG_ASSERTION(test, \
+#define KUNIT_BINARY_PTR_ASSERTION(test, \
assert_type, \
left, \
op, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \ kunit_binary_ptr_assert, \ KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ assert_type, \
left, \
right, \
left, op, right, \ fmt, \ ##__VA_ARGS__)
@@ -1082,12 +1015,11 @@ do { \ KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
@@ -1104,12 +1036,11 @@ do { \ KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
@@ -1126,12 +1057,11 @@ do { \ KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_NE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
@@ -1148,12 +1078,11 @@ do { \ KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
@@ -1358,12 +1287,11 @@ do { \ KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
@@ -1379,12 +1307,11 @@ do { \ KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_ASSERTION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
@@ -1400,12 +1327,11 @@ do { \ KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_NE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
@@ -1422,12 +1348,11 @@ do { \ KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_ASSERTION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
- @test: The test context object.
-- 2.34.1.703.g22d0c6ccf7-goog
On Fri, Jan 21, 2022 at 2:22 AM David Gow davidgow@google.com wrote:
On Wed, Jan 19, 2022 at 6:35 AM Daniel Latypov dlatypov@google.com wrote:
Introduce KUNIT_BINARY_PTR_ASSERTION to match KUNIT_BINARY_INT_ASSERTION and make KUNIT_EXPECT_EQ and KUNIT_EXPECT_PTREQ use these instead of shared intermediate macros that only remove the need to type "==" or "!=".
The current macro chain looks like: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
<ditto for NE and ASSERT>
After this change: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
Signed-off-by: Daniel Latypov dlatypov@google.com
This is great: the macros are much simpler and nicer now. In fact, this whole series is one of the nicest I've seen for a while: I can't think of any serious downsides to any of it.
I agree. I am a fan.
Reviewed-by: David Gow davidgow@google.com
Thanks, -- David
include/kunit/test.h | 173 ++++++++++++------------------------------- 1 file changed, 49 insertions(+), 124 deletions(-)
diff --git a/include/kunit/test.h b/include/kunit/test.h index 48cf520b69ce..bf82c313223b 100644 --- a/include/kunit/test.h +++ b/include/kunit/test.h @@ -888,48 +888,6 @@ do { \ ##__VA_ARGS__); \ } while (0)
-#define KUNIT_BASE_EQ_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BASE_NE_MSG_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \
assert_class, \
ASSERT_CLASS_INIT, \
assert_type, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_EQ_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
#define KUNIT_BINARY_INT_ASSERTION(test, \ assert_type, \ left, \ @@ -945,43 +903,18 @@ do { \ fmt, \ ##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_EQ_MSG_ASSERTION(test, \
kunit_binary_ptr_assert, \
KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_NE_MSG_ASSERTION(test, assert_type, left, right, fmt, ...)\
KUNIT_BASE_NE_MSG_ASSERTION(test, \
kunit_binary_assert, \
KUNIT_INIT_BINARY_ASSERT_STRUCT, \
assert_type, \
left, \
right, \
fmt, \
##__VA_ARGS__)
-#define KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
assert_type, \
left, \
right, \
fmt, \
...) \
KUNIT_BASE_NE_MSG_ASSERTION(test, \
+#define KUNIT_BINARY_PTR_ASSERTION(test, \
assert_type, \
left, \
op, \
right, \
fmt, \
...) \
KUNIT_BASE_BINARY_ASSERTION(test, \ kunit_binary_ptr_assert, \ KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT, \ assert_type, \
left, \
right, \
left, op, right, \ fmt, \ ##__VA_ARGS__)
@@ -1082,12 +1015,11 @@ do { \ KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_PTR_EQ() - Expects that pointers @left and @right are equal.
@@ -1104,12 +1036,11 @@ do { \ KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_NE() - An expectation that @left and @right are not equal.
@@ -1126,12 +1057,11 @@ do { \ KUNIT_EXPECT_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_NE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_PTR_NE() - Expects that pointers @left and @right are not equal.
@@ -1148,12 +1078,11 @@ do { \ KUNIT_EXPECT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_EXPECT_PTR_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_EXPECTATION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_EXPECT_LT() - An expectation that @left is less than @right.
@@ -1358,12 +1287,11 @@ do { \ KUNIT_ASSERT_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_EQ_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_PTR_EQ() - Asserts that pointers @left and @right are equal.
@@ -1379,12 +1307,11 @@ do { \ KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_EQ_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_EQ_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_ASSERTION, \
left, ==, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_NE() - An assertion that @left and @right are not equal.
@@ -1400,12 +1327,11 @@ do { \ KUNIT_ASSERT_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_NE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_INT_ASSERTION(test, \
KUNIT_ASSERTION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_PTR_NE() - Asserts that pointers @left and @right are not equal.
@@ -1422,12 +1348,11 @@ do { \ KUNIT_ASSERT_PTR_NE_MSG(test, left, right, NULL)
#define KUNIT_ASSERT_PTR_NE_MSG(test, left, right, fmt, ...) \
KUNIT_BINARY_PTR_NE_MSG_ASSERTION(test, \
KUNIT_ASSERTION, \
left, \
right, \
fmt, \
##__VA_ARGS__)
KUNIT_BINARY_PTR_ASSERTION(test, \
KUNIT_ASSERTION, \
left, !=, right, \
fmt, \
##__VA_ARGS__)
/**
- KUNIT_ASSERT_LT() - An assertion that @left is less than @right.
- @test: The test context object.
-- 2.34.1.703.g22d0c6ccf7-goog
On Tue, Jan 18, 2022 at 5:35 PM Daniel Latypov dlatypov@google.com wrote:
Introduce KUNIT_BINARY_PTR_ASSERTION to match KUNIT_BINARY_INT_ASSERTION and make KUNIT_EXPECT_EQ and KUNIT_EXPECT_PTREQ use these instead of shared intermediate macros that only remove the need to type "==" or "!=".
The current macro chain looks like: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_EQ_MSG_ASSERTION => KUNIT_BASE_EQ_MSG_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
<ditto for NE and ASSERT>
After this change: KUNIT_EXPECT_EQ_MSG => KUNIT_BINARY_INT_ASSERTION => KUNIT_BASE_BINARY_ASSERTION KUNIT_EXPECT_PTR_EQ_MSG => KUNIT_BINARY_PTR_ASSERTION => KUNIT_BASE_BINARY_ASSERTION
Signed-off-by: Daniel Latypov dlatypov@google.com
Reviewed-by: Brendan Higgins brendanhiggins@google.com
linux-kselftest-mirror@lists.linaro.org