Skip to contentSkip to conversation

kunit: remove KUNIT_INIT_MEM_ASSERTION macro

PATCH In review Daniel Latypov 2 participants 2 messages Nov 9, 2022 – Nov 19, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kunit: remove KUNIT_INIT_MEM_ASSERTION macro

Commit 870f63b7cd78 ("kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros") removed all the other macros of this type.

But it raced with commit b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros"), which added another instance.

Remove KUNIT_INIT_MEM_ASSERTION and just use the generic KUNIT_INIT_ASSERT macro instead.
Rename the size arg to avoid conflicts by appending a "_" (like we did in the previous commit).

---
 include/kunit/assert.h |  7 -------
 include/kunit/test.h   | 12 ++++++------
 2 files changed, 6 insertions(+), 13 deletions(-)
include/kunit/assert.h +0 -7
index 43144cfddc19..24c2b9fa61e8 100644
@@ -192,13 +192,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
 				    const struct va_format *message,
 				    struct string_stream *stream);
 
-#define KUNIT_INIT_MEM_ASSERT_STRUCT(text_, left_val, right_val, size_) {      \
-	.text = text_,							       \
-	.left_value = left_val,						       \
-	.right_value = right_val,				       	       \
-	.size = size_						       	       \
-}
-
 /**
  * struct kunit_mem_assert - An expectation/assertion that compares two
  *	memory blocks.
include/kunit/test.h +6 -6
index d7f60e8aab30..4666a4d199ea 100644
@@ -666,13 +666,13 @@ do {									       \
 			    left,					       \
 			    op,						       \
 			    right,					       \
-			    size,					       \
+			    size_,					       \
 			    fmt,					       \
 			    ...)					       \
 do {									       \
 	const void *__left = (left);					       \
 	const void *__right = (right);					       \
-	const size_t __size = (size);					       \
+	const size_t __size = (size_);					       \
 	static const struct kunit_binary_assert_text __text = {		       \
 		.operation = #op,					       \
 		.left_text = #left,					       \
@@ -686,10 +686,10 @@ do {									       \
 		      assert_type,					       \
 		      kunit_mem_assert,					       \
 		      kunit_mem_assert_format,				       \
-		      KUNIT_INIT_MEM_ASSERT_STRUCT(&__text,		       \
-						   __left,		       \
-						   __right,		       \
-						   __size),		       \
+		      KUNIT_INIT_ASSERT(.text = &__text,		       \
+					.left_value = __left,		       \
+					.right_value = __right,		       \
+					.size = __size),		       \
 		      fmt,						       \
 		      ##__VA_ARGS__);					       \
 } while (0)

base-commit: 870f63b7cd78d0055902d839a60408f7428b4e84

Signature · 1 line
2.38.1.431.g37b22c650d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Daniel Latypov

Commit 870f63b7cd78 ("kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros") removed all the other macros of this type.

But it raced with commit b8a926bea8b1 ("kunit: Introduce KUNIT_EXPECT_MEMEQ and KUNIT_EXPECT_MEMNEQ macros"), which added another instance.

Quoted 7 lines

Remove KUNIT_INIT_MEM_ASSERTION and just use the generic KUNIT_INIT_ASSERT macro instead.
Rename the size arg to avoid conflicts by appending a "_" (like we did in the previous commit).

---

Thanks for catching this. Looks good and works here.

Cheers,
-- David

Quoted 62 lines
 include/kunit/assert.h |  7 -------
 include/kunit/test.h   | 12 ++++++------
 2 files changed, 6 insertions(+), 13 deletions(-)
include/kunit/assert.h +0 -7
index 43144cfddc19..24c2b9fa61e8 100644
@@ -192,13 +192,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
                                    const struct va_format *message,
                                    struct string_stream *stream);
 
-#define KUNIT_INIT_MEM_ASSERT_STRUCT(text_, left_val, right_val, size_) {      \
-       .text = text_,                                                         \
-       .left_value = left_val,                                                \
-       .right_value = right_val,                                              \
-       .size = size_                                                          \
-}
-
 /**
  * struct kunit_mem_assert - An expectation/assertion that compares two
  *     memory blocks.
include/kunit/test.h +6 -6
index d7f60e8aab30..4666a4d199ea 100644
@@ -666,13 +666,13 @@ do {                                                                             \
                            left,                                              \
                            op,                                                \
                            right,                                             \
-                           size,                                              \
+                           size_,                                             \
                            fmt,                                               \
                            ...)                                               \
 do {                                                                          \
        const void *__left = (left);                                           \
        const void *__right = (right);                                         \
-       const size_t __size = (size);                                          \
+       const size_t __size = (size_);                                         \
        static const struct kunit_binary_assert_text __text = {                \
                .operation = #op,                                              \
                .left_text = #left,                                            \
@@ -686,10 +686,10 @@ do {                                                                             \
                      assert_type,                                             \
                      kunit_mem_assert,                                        \
                      kunit_mem_assert_format,                                 \
-                     KUNIT_INIT_MEM_ASSERT_STRUCT(&__text,                    \
-                                                  __left,                     \
-                                                  __right,                    \
-                                                  __size),                    \
+                     KUNIT_INIT_ASSERT(.text = &__text,                       \
+                                       .left_value = __left,                  \
+                                       .right_value = __right,                \
+                                       .size = __size),                       \
                      fmt,                                                     \
                      ##__VA_ARGS__);                                          \
 } while (0)

base-commit: 870f63b7cd78d0055902d839a60408f7428b4e84 --
2.38.1.431.g37b22c650d-goog