kunit: more assertion reworking
cover kunit: more assertion reworking
RFC: https://lore.kernel.org/linux-kselftest/[email protected]/
Changes since then: tweak commit messages, reformatting to make
checkpatch.pl happy. Nothing substantial.
Why send this out again now: the initial Rust patchset no longer
contains the Kunit changes, so hopefully both series can go into 6.1
and later we can coordinate the update the kunit.rs wrapper.
This is a follow up to these three series:
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
The two goals of those series were
a) reduce the size of struct kunit_assert and friends. (struct kunit_assert went from 48 => 8 bytes on UML.)
b) simplify the internal code, mostly by deleting macros
This series goes further
a) sizeof(struct kunit_assert) = 0 now
b) e.g. we delete another class of macros (KUNIT_INIT_*_ASSERT_STRUCT)
Note: this does change the function signature of kunit_do_failed_assertion, so we'd need to update the rust wrapper in
https://github.com/Rust-for-Linux/linux/blob/rust/rust/kernel/kunit.rs,
but hopefully it's just a simple change, e.g. maybe just like:
@@ -38,9 +38,7 @@
});
static CONDITION: &'static $crate::str::CStr =
$crate::c_str!(stringify!($cond));
static ASSERTION: UnaryAssert =
UnaryAssert($crate::bindings::kunit_unary_assert {
- assert: $crate::bindings::kunit_assert {
- format: Some($crate::bindings::kunit_unary_assert_format),
- },
+ assert: $crate::bindings::kunit_assert {},
condition: CONDITION.as_char_ptr(),
expected_true: true,
});
@@ -67,6 +65,7 @@
core::ptr::addr_of!(LOCATION.0),
$crate::bindings::kunit_assert_type_KUNIT_ASSERTION,
core::ptr::addr_of!(ASSERTION.0.assert),
+ Some($crate::bindings::kunit_unary_assert_format),
core::ptr::null(),
);
}Daniel Latypov (4):
kunit: remove format func from struct kunit_assert, get it to 0 bytes
kunit: rename base KUNIT_ASSERTION macro to _KUNIT_FAILED
kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros
kunit: declare kunit_assert structs as const
include/kunit/assert.h | 74 ++---------------------- include/kunit/test.h | 127 +++++++++++++++++++++++------------------ lib/kunit/test.c | 7 ++- 3 files changed, 80 insertions(+), 128 deletions(-)
base-commit: 511cce163b75bc3933fa3de769a82bb7e8663f2b
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
PATCH 1/4 kunit: remove format func from struct kunit_assert, get it to 0 bytes
Each calll to a KUNIT_EXPECT_*() macro creates a local variable which contains a struct kunit_assert.
Normally, we'd hope the compiler would be able to optimize this away, but we've seen cases where it hasn't, see
https://groups.google.com/g/kunit-dev/c/i3fZXgvBrfA/m/GbrMNej2BAAJ.
In changes like commit 21957f90b28f ("kunit: split out part of kunit_assert into a static const"), we've moved more and more parts out of struct kunit_assert and its children types (kunit_binary_assert).
This patch removes the final field and gets us to:
sizeof(struct kunit_assert) == 0
sizeof(struct kunit_binary_assert) == 24 (on UML x86_64).
This also reduces the amount of macro plumbing going on at the cost of passing in one more arg to the base KUNIT_ASSERTION macro and kunit_do_failed_assertion().
--- include/kunit/assert.h | 28 ++++++---------------------- include/kunit/test.h | 17 +++++++++++------ lib/kunit/test.c | 7 ++++--- 3 files changed, 21 insertions(+), 31 deletions(-)
include/kunit/assert.h +6 -22
@@ -42,16 +42,15 @@ struct kunit_loc {/** * struct kunit_assert - Data for printing a failed assertion or expectation. -* @format: a function which formats the data in this kunit_assert to a string. * * Represents a failed expectation/assertion. Contains all the data necessary to * format a string to a user reporting the failure. */ -struct kunit_assert { -void (*format)(const struct kunit_assert *assert, -const struct va_format *message, -struct string_stream *stream); -}; +struct kunit_assert {}; + +typedef void (*assert_format_t )(const struct kunit_assert *assert, +const struct va_format *message, +struct string_stream *stream); void kunit_assert_prologue(const struct kunit_loc *loc, enum kunit_assert_type type,
@@ -71,16 +70,6 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_FAIL_ASSERT_STRUCT - Initializer for &struct kunit_fail_assert. -* -* Initializes a &struct kunit_fail_assert. Intended to be used in -* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. -*/ -#define KUNIT_INIT_FAIL_ASSERT_STRUCT { \ - .assert = { .format = kunit_fail_assert_format }, \ -} -/** * struct kunit_unary_assert - Represents a KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE} * @assert: The parent of this type.
@@ -110,7 +99,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. */ #define KUNIT_INIT_UNARY_ASSERT_STRUCT (cond, expect_true) { \ - .assert = { .format = kunit_unary_assert_format }, \ .condition = cond, \ .expected_true = expect_true \ }
@@ -145,7 +133,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. */ #define KUNIT_INIT_PTR_NOT_ERR_STRUCT (txt, val) { \ - .assert = { .format = kunit_ptr_not_err_assert_format }, \ .text = txt, \ .value = val \ }
@@ -190,7 +177,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a binary assert like * kunit_binary_assert, kunit_binary_ptr_assert, etc. * -* @format_func: a function which formats the assert to a string. * @text_: Pointer to a kunit_binary_assert_text. * @left_val: The actual evaluated value of the expression in the left slot. * @right_val: The actual evaluated value of the expression in the right slot.
@@ -200,11 +186,9 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,* fields but with different types for left_val/right_val. * This is ultimately used by binary assertion macros like KUNIT_EXPECT_EQ, etc. */ -#define KUNIT_INIT_BINARY_ASSERT_STRUCT (format_func, \ - text_, \ +#define KUNIT_INIT_BINARY_ASSERT_STRUCT (text_, \ left_val, \ right_val) { \ - .assert = { .format = format_func }, \ .text = text_, \ .left_value = left_val, \ .right_value = right_val \
include/kunit/test.h +11 -6
@@ -472,9 +472,10 @@ void kunit_do_failed_assertion(struct kunit *test,const struct kunit_loc *loc, enum kunit_assert_type type, const struct kunit_assert *assert, + assert_format_t assert_format, const char *fmt, ...); -#define KUNIT_ASSERTION (test, assert_type, pass, assert_class,INITIALIZER , fmt, ...) do { \ +#define KUNIT_ASSERTION (test, assert_type, pass, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ if (unlikely(!(pass))) { \ static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ struct assert_class __assertion = INITIALIZER; \
@@ -482,6 +483,7 @@ void kunit_do_failed_assertion(struct kunit *test, &__loc, \ assert_type, \ &__assertion.assert, \ + assert_format, \ fmt, \ ##__VA_ARGS__); \ } \
@@ -493,7 +495,8 @@ void kunit_do_failed_assertion(struct kunit *test, assert_type, \ false, \ kunit_fail_assert, \ -KUNIT_INIT_FAIL_ASSERT_STRUCT , \ + kunit_fail_assert_format, \ + {}, \ fmt, \ ##__VA_ARGS__)
@@ -524,6 +527,7 @@ void kunit_do_failed_assertion(struct kunit *test, assert_type, \ !!(condition) == !!expected_true, \ kunit_unary_assert, \ + kunit_unary_assert_format, \ KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ expected_true), \ fmt, \
@@ -581,8 +585,8 @@ do { \ assert_type, \ __left op __right, \ assert_class, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (format_func, \ - &__text, \ + format_func, \ +KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ __left, \ __right), \ fmt, \
@@ -639,8 +643,8 @@ do { \ assert_type, \ strcmp(__left, __right) op 0, \ kunit_binary_str_assert, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (kunit_binary_str_assert_format,\ - &__text, \ + kunit_binary_str_assert_format, \ +KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ __left, \ __right), \ fmt, \
@@ -659,6 +663,7 @@ do { \ assert_type, \ !IS_ERR_OR_NULL(__ptr), \ kunit_ptr_not_err_assert, \ + kunit_ptr_not_err_assert_format, \ KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \ __ptr), \ fmt, \
lib/kunit/test.c +4 -3
@@ -247,7 +247,7 @@ static void kunit_print_string_stream(struct kunit *test,static void kunit_fail (struct kunit *test,const struct kunit_loc *loc,enum kunit_assert_type type,const struct kunit_assert *assert, -const struct va_format *message) +assert_format_t assert_format,const struct va_format *message) {struct string_stream *stream;
@@ -263,7 +263,7 @@ static void kunit_fail(struct kunit *test, const struct kunit_loc *loc, }kunit_assert_prologue (loc, type, stream); - assert->format (assert, message, stream); +assert_format (assert, message, stream);kunit_print_string_stream (test, stream);
@@ -287,6 +287,7 @@ void kunit_do_failed_assertion(struct kunit *test,const struct kunit_loc *loc, enum kunit_assert_type type, const struct kunit_assert *assert, + assert_format_t assert_format, const char *fmt, ...) { va_list args;
@@ -296,7 +297,7 @@ void kunit_do_failed_assertion(struct kunit *test, message.fmt = fmt; message.va = &args; -kunit_fail (test, loc, type, assert, &message); +kunit_fail (test, loc, type, assert, assert_format, &message);va_end (args);
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
Re: [PATCH 1/4] kunit: remove format func from struct kunit_assert, get it to 0 bytes
Quoted 16 lines · Daniel Latypov
Each calll to a KUNIT_EXPECT_*() macro creates a local variable which contains a struct
kunit_assert.Normally, we'd hope the compiler would be able to optimize this away, but we've seen cases where it hasn't, see
https://groups.google.com/g/kunit-dev/c/i3fZXgvBrfA/m/GbrMNej2BAAJ.In changes like commit
21957f90b28f("kunit: split out part ofkunit_assertinto a static const"), we've moved more and more parts out of structkunit_assertand its children types (kunit_binary_assert).This patch removes the final field and gets us to:
sizeof(struct kunit_assert)== 0
sizeof(struct kunit_binary_assert)== 24 (on UMLx86_64).
Quoted 6 lines
This also reduces the amount of macro plumbing going on at the cost of passing in one more arg to the base
KUNIT_ASSERTIONmacro andkunit_do_failed_assertion().Signed-off-by Daniel Latypov <[email protected]>---
Very glad to see this finally happening: we've definitely still been seeing these stack size warnings, so reducing the stack use is good
And as someone who has always been a little uneasy with the number of nested macros, the simplification is also a big win.
Cheers,
-- David
Quoted 199 lines
include/kunit/assert.h | 28 ++++++---------------------- include/kunit/test.h | 17 +++++++++++------ lib/kunit/test.c | 7 ++++--- 3 files changed, 21 insertions(+), 31 deletions(-)include/kunit/assert.h +6
-22@@ -42,16 +42,15 @@ struct kunit_loc {/** * struct kunit_assert - Data for printing a failed assertion or expectation. -* @format: a function which formats the data in this kunit_assert to a string. * * Represents a failed expectation/assertion. Contains all the data necessary to * format a string to a user reporting the failure. */ -struct kunit_assert { -void (*format)(const struct kunit_assert *assert, -const struct va_format *message, -struct string_stream *stream); -}; +struct kunit_assert {}; + +typedef void (*assert_format_t )(const struct kunit_assert *assert, +const struct va_format *message, +struct string_stream *stream); void kunit_assert_prologue(const struct kunit_loc *loc, enum kunit_assert_type type,@@ -71,16 +70,6 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_FAIL_ASSERT_STRUCT - Initializer for &struct kunit_fail_assert. -* -* Initializes a &struct kunit_fail_assert. Intended to be used in -* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. -*/ -#define KUNIT_INIT_FAIL_ASSERT_STRUCT { \ - .assert = { .format = kunit_fail_assert_format }, \ -} -/** * struct kunit_unary_assert - Represents a KUNIT_{EXPECT|ASSERT}_{TRUE|FALSE} * @assert: The parent of this type. @@ -110,7 +99,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. */ #define KUNIT_INIT_UNARY_ASSERT_STRUCT (cond, expect_true) { \ - .assert = { .format = kunit_unary_assert_format }, \ .condition = cond, \ .expected_true = expect_true \ }@@ -145,7 +133,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. */ #define KUNIT_INIT_PTR_NOT_ERR_STRUCT (txt, val) { \ - .assert = { .format = kunit_ptr_not_err_assert_format }, \ .text = txt, \ .value = val \ }@@ -190,7 +177,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a binary assert like * kunit_binary_assert, kunit_binary_ptr_assert, etc. * -* @format_func: a function which formats the assert to a string. * @text_: Pointer to a kunit_binary_assert_text. * @left_val: The actual evaluated value of the expression in the left slot. * @right_val: The actual evaluated value of the expression in the right slot. @@ -200,11 +186,9 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,* fields but with different types for left_val/right_val. * This is ultimately used by binary assertion macros like KUNIT_EXPECT_EQ, etc. */ -#define KUNIT_INIT_BINARY_ASSERT_STRUCT (format_func, \ - text_, \ +#define KUNIT_INIT_BINARY_ASSERT_STRUCT (text_, \ left_val, \ right_val) { \ - .assert = { .format = format_func }, \ .text = text_, \ .left_value = left_val, \ .right_value = right_val \include/kunit/test.h +11
-6@@ -472,9 +472,10 @@ void kunit_do_failed_assertion(struct kunit *test,const struct kunit_loc *loc, enum kunit_assert_type type, const struct kunit_assert *assert, + assert_format_t assert_format, const char *fmt, ...); -#define KUNIT_ASSERTION (test, assert_type, pass, assert_class,INITIALIZER , fmt, ...) do { \ +#define KUNIT_ASSERTION (test, assert_type, pass, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ if (unlikely(!(pass))) { \ static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ struct assert_class __assertion = INITIALIZER; \@@ -482,6 +483,7 @@ void kunit_do_failed_assertion(struct kunit *test, &__loc, \ assert_type, \ &__assertion.assert, \ + assert_format, \ fmt, \ ##__VA_ARGS__); \ } \@@ -493,7 +495,8 @@ void kunit_do_failed_assertion(struct kunit *test, assert_type, \ false, \ kunit_fail_assert, \ -KUNIT_INIT_FAIL_ASSERT_STRUCT , \ + kunit_fail_assert_format, \ + {}, \ fmt, \ ##__VA_ARGS__)@@ -524,6 +527,7 @@ void kunit_do_failed_assertion(struct kunit *test, assert_type, \ !!(condition) == !!expected_true, \ kunit_unary_assert, \ + kunit_unary_assert_format, \ KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ expected_true), \ fmt, \@@ -581,8 +585,8 @@ do { \ assert_type, \ __left op __right, \ assert_class, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (format_func, \ - &__text, \ + format_func, \ +KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ __left, \ __right), \ fmt, \@@ -639,8 +643,8 @@ do { \ assert_type, \ strcmp(__left, __right) op 0, \ kunit_binary_str_assert, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (kunit_binary_str_assert_format,\ - &__text, \ + kunit_binary_str_assert_format, \ +KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ __left, \ __right), \ fmt, \@@ -659,6 +663,7 @@ do { \ assert_type, \ !IS_ERR_OR_NULL(__ptr), \ kunit_ptr_not_err_assert, \ + kunit_ptr_not_err_assert_format, \ KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \ __ptr), \ fmt, \lib/kunit/test.c +4
-4@@ -247,7 +247,7 @@ static void kunit_print_string_stream(struct kunit *test,static void kunit_fail (struct kunit *test,const struct kunit_loc *loc,enum kunit_assert_type type,const struct kunit_assert *assert, -const struct va_format *message) +assert_format_t assert_format,const struct va_format *message) {struct string_stream *stream;@@ -263,7 +263,7 @@ static void kunit_fail(struct kunit *test, const struct kunit_loc *loc, }kunit_assert_prologue (loc, type, stream); - assert->format (assert, message, stream); +assert_format (assert, message, stream);kunit_print_string_stream (test, stream);@@ -287,6 +287,7 @@ void kunit_do_failed_assertion(struct kunit *test,const struct kunit_loc *loc, enum kunit_assert_type type, const struct kunit_assert *assert, + assert_format_t assert_format, const char *fmt, ...) { va_list args;@@ -296,7 +297,7 @@ void kunit_do_failed_assertion(struct kunit *test, message.fmt = fmt; message.va = &args; -kunit_fail (test, loc, type, assert, &message); +kunit_fail (test, loc, type, assert, assert_format, &message);va_end (args); --2.38.0.rc1.362.ged0d419d3c-goog
PATCH 2/4 kunit: rename base KUNIT_ASSERTION macro to _KUNIT_FAILED
In reply to Daniel LatypovContext:
Currently this macro's name, KUNIT_ASSERTION conflicts with the name of an enum whose values are {KUNIT_EXPECTATION, KUNIT_ASSERTION}.
It's hard to think of a better name for the enum, so rename this macro. It's also a bit strange that the macro might do nothing depending on the boolean argument pass. Why not have callers check themselves?
This patch:
Moves the pass/fail checking into the callers of KUNIT_ASSERTION, so now we only call it when the check has failed.
Then we rename the macro the _KUNIT_FAILED() to reflect the new semantics.
--- include/kunit/test.h | 123 +++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 58 deletions(-)
include/kunit/test.h +65 -58
@@ -475,30 +475,27 @@ void kunit_do_failed_assertion(struct kunit *test,assert_format_t assert_format, const char *fmt, ...); -#define KUNIT_ASSERTION (test, assert_type, pass, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ - if (unlikely(!(pass))) { \ - static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ - struct assert_class __assertion = INITIALIZER; \ - kunit_do_failed_assertion(test, \ - &__loc, \ - assert_type, \ - &__assertion.assert, \ - assert_format, \ - fmt, \ - ##__VA_ARGS__); \ - } \ +#define _KUNIT_FAILED (test, assert_type, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ + static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ + struct assert_class __assertion = INITIALIZER; \ + kunit_do_failed_assertion(test, \ + &__loc, \ + assert_type, \ + &__assertion.assert, \ + assert_format, \ + fmt, \ + ##__VA_ARGS__); \ } while (0)#define KUNIT_FAIL_ASSERTION (test, assert_type, fmt, ...) \ - KUNIT_ASSERTION(test, \ - assert_type, \ - false, \ - kunit_fail_assert, \ - kunit_fail_assert_format, \ - {}, \ - fmt, \ - ##__VA_ARGS__) + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_fail_assert, \ + kunit_fail_assert_format, \ + {}, \ + fmt, \ + ##__VA_ARGS__)/** * KUNIT_FAIL() - Always causes a test to fail when evaluated.
@@ -523,15 +520,19 @@ void kunit_do_failed_assertion(struct kunit *test, expected_true, \ fmt, \ ...) \ - KUNIT_ASSERTION(test, \ - assert_type, \ - !!(condition) == !!expected_true, \ - kunit_unary_assert, \ - kunit_unary_assert_format, \ - KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ - expected_true), \ - fmt, \ - ##__VA_ARGS__) +do { \ + if (likely(!!(condition) == !!expected_true)) \ + break; \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_unary_assert, \ + kunit_unary_assert_format, \ + KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ + expected_true), \ + fmt, \ + ##__VA_ARGS__); \ +} while (0)#define KUNIT_TRUE_MSG_ASSERTION (test, assert_type, condition, fmt, ...) \ KUNIT_UNARY_ASSERTION(test, \
@@ -581,16 +582,18 @@ do { \ .right_text = #right, \ }; \ \ - KUNIT_ASSERTION(test, \ - assert_type, \ - __left op __right, \ - assert_class, \ - format_func, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ - __left, \ - __right), \ - fmt, \ - ##__VA_ARGS__); \ + if (likely(__left op __right)) \ + break; \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + assert_class, \ + format_func, \ + KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ + __left, \ + __right), \ + fmt, \ + ##__VA_ARGS__); \ } while (0) #define KUNIT_BINARY_INT_ASSERTION(test, \
@@ -639,16 +642,19 @@ do { \ .right_text = #right, \ }; \ \ - KUNIT_ASSERTION(test, \ - assert_type, \ - strcmp(__left, __right) op 0, \ - kunit_binary_str_assert, \ - kunit_binary_str_assert_format, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ - __left, \ - __right), \ - fmt, \ - ##__VA_ARGS__); \ + if (likely(strcmp(__left, __right) op 0)) \ + break; \ + \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_binary_str_assert, \ + kunit_binary_str_assert_format, \ + KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ + __left, \ + __right), \ + fmt, \ + ##__VA_ARGS__); \ } while (0) #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \
@@ -659,15 +665,16 @@ do { \ do { \ const typeof(ptr) __ptr = (ptr); \ \ - KUNIT_ASSERTION(test, \ - assert_type, \ - !IS_ERR_OR_NULL(__ptr), \ - kunit_ptr_not_err_assert, \ - kunit_ptr_not_err_assert_format, \ - KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \ - __ptr), \ - fmt, \ - ##__VA_ARGS__); \ + if (!IS_ERR_OR_NULL(__ptr)) \ + break; \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_ptr_not_err_assert, \ + kunit_ptr_not_err_assert_format, \ + KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, __ptr), \ + fmt, \ + ##__VA_ARGS__); \ } while (0) /**
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
Re: [PATCH 2/4] kunit: rename base KUNIT_ASSERTION macro to _KUNIT_FAILED
Quoted 9 lines · Daniel Latypov' via KUnit Development
Context:
Currently this macro's name,KUNIT_ASSERTIONconflicts with the name of an enum whose values are {KUNIT_EXPECTATION,KUNIT_ASSERTION}.It's hard to think of a better name for the enum, so rename this macro. It's also a bit strange that the macro might do nothing depending on the boolean argument
pass. Why not have callers check themselves?
Quoted 8 lines
This patch:
Moves the pass/fail checking into the callers ofKUNIT_ASSERTION, so now we only call it when the check has failed.
Then we rename the macro the_KUNIT_FAILED()to reflect the new semantics.Signed-off-by Daniel Latypov <[email protected]>---
Looks good to me. I can't say the name _KUNIT_FAILED() feels perfect to me, but I can't think of anything better, either. We've not used a leading underscore for internal macros much thus far, as well, though I've no personal objections to starting.
Regardless, let's get this in.
Cheers,
-- David
Quoted 176 lines
include/kunit/test.h | 123 +++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 58 deletions(-)include/kunit/test.h +65
-59@@ -475,30 +475,27 @@ void kunit_do_failed_assertion(struct kunit *test,assert_format_t assert_format, const char *fmt, ...); -#define KUNIT_ASSERTION (test, assert_type, pass, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ - if (unlikely(!(pass))) { \ - static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ - struct assert_class __assertion = INITIALIZER; \ - kunit_do_failed_assertion(test, \ - &__loc, \ - assert_type, \ - &__assertion.assert, \ - assert_format, \ - fmt, \ - ##__VA_ARGS__); \ - } \ +#define _KUNIT_FAILED (test, assert_type, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ + static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ + struct assert_class __assertion = INITIALIZER; \ + kunit_do_failed_assertion(test, \ + &__loc, \ + assert_type, \ + &__assertion.assert, \ + assert_format, \ + fmt, \ + ##__VA_ARGS__); \ } while (0)#define KUNIT_FAIL_ASSERTION (test, assert_type, fmt, ...) \ - KUNIT_ASSERTION(test, \ - assert_type, \ - false, \ - kunit_fail_assert, \ - kunit_fail_assert_format, \ - {}, \ - fmt, \ - ##__VA_ARGS__) + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_fail_assert, \ + kunit_fail_assert_format, \ + {}, \ + fmt, \ + ##__VA_ARGS__)/** * KUNIT_FAIL() - Always causes a test to fail when evaluated. @@ -523,15 +520,19 @@ void kunit_do_failed_assertion(struct kunit *test, expected_true, \ fmt, \ ...) \ - KUNIT_ASSERTION(test, \ - assert_type, \ - !!(condition) == !!expected_true, \ - kunit_unary_assert, \ - kunit_unary_assert_format, \ - KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ - expected_true), \ - fmt, \ - ##__VA_ARGS__) +do { \ + if (likely(!!(condition) == !!expected_true)) \ + break; \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_unary_assert, \ + kunit_unary_assert_format, \ + KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ + expected_true), \ + fmt, \ + ##__VA_ARGS__); \ +} while (0) #define KUNIT_TRUE_MSG_ASSERTION(test, assert_type, condition, fmt, ...) \ KUNIT_UNARY_ASSERTION(test, \@@ -581,16 +582,18 @@ do { \ .right_text = #right, \ }; \ \ - KUNIT_ASSERTION(test, \ - assert_type, \ - __left op __right, \ - assert_class, \ - format_func, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ - __left, \ - __right), \ - fmt, \ - ##__VA_ARGS__); \ + if (likely(__left op __right)) \ + break; \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + assert_class, \ + format_func, \ + KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ + __left, \ + __right), \ + fmt, \ + ##__VA_ARGS__); \ } while (0) #define KUNIT_BINARY_INT_ASSERTION(test, \@@ -639,16 +642,19 @@ do { \ .right_text = #right, \ }; \ \ - KUNIT_ASSERTION(test, \ - assert_type, \ - strcmp(__left, __right) op 0, \ - kunit_binary_str_assert, \ - kunit_binary_str_assert_format, \ - KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ - __left, \ - __right), \ - fmt, \ - ##__VA_ARGS__); \ + if (likely(strcmp(__left, __right) op 0)) \ + break; \ + \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_binary_str_assert, \ + kunit_binary_str_assert_format, \ + KUNIT_INIT_BINARY_ASSERT_STRUCT(&__text, \ + __left, \ + __right), \ + fmt, \ + ##__VA_ARGS__); \ } while (0) #define KUNIT_PTR_NOT_ERR_OR_NULL_MSG_ASSERTION(test, \@@ -659,15 +665,16 @@ do { \ do { \ const typeof(ptr) __ptr = (ptr); \ \ - KUNIT_ASSERTION(test, \ - assert_type, \ - !IS_ERR_OR_NULL(__ptr), \ - kunit_ptr_not_err_assert, \ - kunit_ptr_not_err_assert_format, \ - KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \ - __ptr), \ - fmt, \ - ##__VA_ARGS__); \ + if (!IS_ERR_OR_NULL(__ptr)) \ + break; \ + \ + _KUNIT_FAILED(test, \ + assert_type, \ + kunit_ptr_not_err_assert, \ + kunit_ptr_not_err_assert_format, \ + KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, __ptr), \ + fmt, \ + ##__VA_ARGS__); \ } while (0) /** --2.38.0.rc1.362.ged0d419d3c-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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20221001002638.2881842-3-dlatypov%40google.com.
Re: [PATCH 2/4] kunit: rename base KUNIT_ASSERTION macro to _KUNIT_FAILED
Quoted 18 lines · David Gow
Quoted 15 lines · Daniel Latypov' via KUnit Development
Context:
Currently this macro's name,KUNIT_ASSERTIONconflicts with the name of an enum whose values are {KUNIT_EXPECTATION,KUNIT_ASSERTION}.It's hard to think of a better name for the enum, so rename this macro. It's also a bit strange that the macro might do nothing depending on the boolean argument
pass. Why not have callers check themselves?This patch:
Moves the pass/fail checking into the callers ofKUNIT_ASSERTION, so now we only call it when the check has failed.
Then we rename the macro the_KUNIT_FAILED()to reflect the new semantics.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Daniel Latypov <[email protected]>---
Looks good to me. I can't say the name
_KUNIT_FAILED()feels perfect to me, but I can't think of anything better, either. We've not used a leading underscore for internal macros much thus far, as well, though I've no personal objections to starting.
Yeah, I also didn't add a leading underscore on the new KUNIT_INIT_ASSERT() macro elsewhere in this series.
So I'm not necessarily proposing that we should start doing so here.
It feels like that KUNIT_FAILED is far too similar to the enum
55 enum kunit_status {
56 KUNIT_SUCCESS,
57 KUNIT_FAILURE,
58 KUNIT_SKIPPED,
59 };I.e. we'd be remove one naming conflict between a macro and enum, but basically introducing a new one in its place :P
Tbh, I was originally going to have this patch just be s/KUNIT_ASSERTION()/_KUNIT_ASSERTION() to reduce the conflict. But I figured we could reduce the number of arguments to the macro (drop pass) and have a reason to give it a different name.
I'm also not entirely convinced about _KUNIT_FAILED(), but I haven't had any significantly better ideas since I sent the RFC in May.
Daniel
Re: [PATCH 2/4] kunit: rename base KUNIT_ASSERTION macro to _KUNIT_FAILED
Quoted 23 lines · Daniel Latypov' via KUnit Development
Quoted 21 lines · David Gow
Quoted 17 lines · Daniel Latypov' via KUnit Development
Context:
Currently this macro's name,KUNIT_ASSERTIONconflicts with the name of an enum whose values are {KUNIT_EXPECTATION,KUNIT_ASSERTION}.It's hard to think of a better name for the enum, so rename this macro. It's also a bit strange that the macro might do nothing depending on the boolean argument
pass. Why not have callers check themselves?This patch:
Moves the pass/fail checking into the callers ofKUNIT_ASSERTION, so now we only call it when the check has failed.
Then we rename the macro the_KUNIT_FAILED()to reflect the new semantics.Signed-off-by Daniel Latypov <[email protected]>---
Quoted 8 lines
Quoted 4 lines
Looks good to me. I can't say the name
_KUNIT_FAILED()feels perfect to me, but I can't think of anything better, either. We've not used a leading underscore for internal macros much thus far, as well, though I've no personal objections to starting.Yeah, I also didn't add a leading underscore on the new
KUNIT_INIT_ASSERT()macro elsewhere in this series.
So I'm not necessarily proposing that we should start doing so here.
Yeah: I noticed that. In general, I think I come down slightly on the side of avoiding leading underscores. (And there's also the debate about whether to have one or two, as while two underscores is nominally "reserved for the system", the kernel uses it a lot -- probably because it considers itself "the system"). So I'd tend to lean away from making all of our "internal" macros start with underscores.
Quoted 15 lines
It feels like that
KUNIT_FAILEDis far too similar to the enum55 enum kunit_status { 56 KUNIT_SUCCESS, 57 KUNIT_FAILURE, 58 KUNIT_SKIPPED, 59 };I.e. we'd be remove one naming conflict between a macro and enum, but basically introducing a new one in its place :P
Tbh, I was originally going to have this patch just be s/KUNIT_ASSERTION()/_KUNIT_ASSERTION() to reduce the conflict. But I figured we could reduce the number of arguments to the macro (droppass) and have a reason to give it a different name.
Quoted 2 lines
I'm also not entirely convinced about
_KUNIT_FAILED(), but I haven't had any significantly better ideas since I sent the RFC in May.
Agreed: particularly since SKIPPED would seem to pair better with FAILED than FAILURE, so they conflict quite a bit.
Let's stick with what we have in this change, and we can change it later if someone comes up with a drastically better name.
Cheers,
-- David
PATCH 3/4 kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros
In reply to Daniel LatypovThese macros exist because passing an initializer list to other macros is hard.
The goal of these macros is to generate a line like
struct $ASSERT_TYPE __assertion = $APPROPRIATE_INITIALIZER;
e.g.
struct kunit_unary_assertion __assertion = {
.condition = "foo()",
.expected_true = true};
But the challenge is you can't pass {.condition=..., .expect_true=...} as a macro argument, since the comma means you're actually passing two arguments, {.condition=... and .expect_true=....}.
So we'd made custom macros for each different initializer-list shape.
But we can work around this with the following generic macro
#define KUNIT_INIT_ASSERT(initializers...) { initializers }
Note: this has the downside that we have to rename some macros arguments to not conflict with the struct field names (e.g. expected_true). It's a bit gross, but probably worth reducing the # of macros.
--- include/kunit/assert.h | 48 ------------------------------------------ include/kunit/test.h | 27 +++++++++++++----------- 2 files changed, 15 insertions(+), 60 deletions(-)
include/kunit/assert.h +0 -48
@@ -90,19 +90,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert. -* @cond: A string representation of the expression asserted true or false. -* @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise. -* -* Initializes a &struct kunit_unary_assert. Intended to be used in -* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. -*/ -#define KUNIT_INIT_UNARY_ASSERT_STRUCT (cond, expect_true) { \ - .condition = cond, \ - .expected_true = expect_true \ -} -/** * struct kunit_ptr_not_err_assert - An expectation/assertion that a pointer is * not NULL and not a -errno.
@@ -123,20 +110,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a -* &struct kunit_ptr_not_err_assert. -* @txt: A string representation of the expression passed to the expectation. -* @val: The actual evaluated pointer value of the expression. -* -* Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in -* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. -*/ -#define KUNIT_INIT_PTR_NOT_ERR_STRUCT (txt, val) { \ - .text = txt, \ - .value = val \ -} -/** * struct kunit_binary_assert_text - holds strings for &struct * kunit_binary_assert and friends to try and make the structs smaller.
@@ -173,27 +146,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a binary assert like -* kunit_binary_assert, kunit_binary_ptr_assert, etc. -* -* @text_: Pointer to a kunit_binary_assert_text. -* @left_val: The actual evaluated value of the expression in the left slot. -* @right_val: The actual evaluated value of the expression in the right slot. -* -* Initializes a binary assert like kunit_binary_assert, -* kunit_binary_ptr_assert, etc. This relies on these structs having the same -* fields but with different types for left_val/right_val. -* This is ultimately used by binary assertion macros like KUNIT_EXPECT_EQ, etc. -*/ -#define KUNIT_INIT_BINARY_ASSERT_STRUCT (text_, \ - left_val, \ - right_val) { \ - .text = text_, \ - .left_value = left_val, \ - .right_value = right_val \ -} -/** * struct kunit_binary_ptr_assert - An expectation/assertion that compares two * pointer values (for example, KUNIT_EXPECT_PTR_EQ(test, foo, bar)).
include/kunit/test.h +15 -12
@@ -514,22 +514,25 @@ void kunit_do_failed_assertion(struct kunit *test, fmt, \ ##__VA_ARGS__) +/* Helper to safely pass around an initializer list to other macros. */ +#define KUNIT_INIT_ASSERT(initializers...) { initializers } +#define KUNIT_UNARY_ASSERTION (test, \ assert_type, \ - condition, \ - expected_true, \ + condition_, \ + expected_true_, \ fmt, \ ...) \ do { \ - if (likely(!!(condition) == !!expected_true)) \ + if (likely(!!(condition_) == !!expected_true_)) \ break; \ \ _KUNIT_FAILED(test, \ assert_type, \ kunit_unary_assert, \ kunit_unary_assert_format, \ - KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ - expected_true), \ + KUNIT_INIT_ASSERT(.condition = #condition_, \ + .expected_true = expected_true_), \ fmt, \ ##__VA_ARGS__); \ } while (0)
@@ -589,9 +592,9 @@ do { \ assert_type, \ assert_class, \ format_func, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ - __left, \ - __right), \ + KUNIT_INIT_ASSERT(.text = &__text, \ + .left_value = __left, \ + .right_value = __right), \ fmt, \ ##__VA_ARGS__); \ }while (0 )
@@ -650,9 +653,9 @@ do { \ assert_type, \ kunit_binary_str_assert, \ kunit_binary_str_assert_format, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ - __left, \ - __right), \ + KUNIT_INIT_ASSERT(.text = &__text, \ + .left_value = __left, \ + .right_value = __right), \ fmt, \ ##__VA_ARGS__); \ }while (0 )
@@ -672,7 +675,7 @@ do { \ assert_type, \ kunit_ptr_not_err_assert, \ kunit_ptr_not_err_assert_format, \ - KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, __ptr), \ + KUNIT_INIT_ASSERT(.text = #ptr, .value = __ptr), \ fmt, \ ##__VA_ARGS__); \ } while (0)
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
Re: [PATCH 3/4] kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros
Quoted 20 lines · Daniel Latypov
These macros exist because passing an initializer list to other macros is hard.
The goal of these macros is to generate a line like
struct $ASSERT_TYPE__assertion= $APPROPRIATE_INITIALIZER;
e.g.
structkunit_unary_assertion__assertion= {
.condition = "foo()",
.expected_true = true
};But the challenge is you can't pass
{.condition=..., .expect_true=...}as a macro argument, since the comma means you're actually passing two arguments,{.condition=...and.expect_true=....}.
So we'd made custom macros for each different initializer-list shape.But we can work around this with the following generic macro
#defineKUNIT_INIT_ASSERT(initializers...){ initializers }
Quoted 6 lines
Note: this has the downside that we have to rename some macros arguments to not conflict with the struct field names (e.g.
expected_true). It's a bit gross, but probably worth reducing the # of macros.Signed-off-by Daniel Latypov <[email protected]>---
I agree with you on both fronts here: this is 'a bit gross', and is also 'worth it'.
Cheers,
-- David
Quoted 150 lines
include/kunit/assert.h | 48 ------------------------------------------ include/kunit/test.h | 27 +++++++++++++----------- 2 files changed, 15 insertions(+), 60 deletions(-)include/kunit/assert.h +0
-48@@ -90,19 +90,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert. -* @cond: A string representation of the expression asserted true or false. -* @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise. -* -* Initializes a &struct kunit_unary_assert. Intended to be used in -* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. -*/ -#define KUNIT_INIT_UNARY_ASSERT_STRUCT (cond, expect_true) { \ - .condition = cond, \ - .expected_true = expect_true \ -} -/** * struct kunit_ptr_not_err_assert - An expectation/assertion that a pointer is * not NULL and not a -errno. @@ -123,20 +110,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a -* &struct kunit_ptr_not_err_assert. -* @txt: A string representation of the expression passed to the expectation. -* @val: The actual evaluated pointer value of the expression. -* -* Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in -* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. -*/ -#define KUNIT_INIT_PTR_NOT_ERR_STRUCT (txt, val) { \ - .text = txt, \ - .value = val \ -} -/** * struct kunit_binary_assert_text - holds strings for &struct * kunit_binary_assert and friends to try and make the structs smaller. @@ -173,27 +146,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,const struct va_format *message, struct string_stream *stream); -/** -* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a binary assert like -* kunit_binary_assert, kunit_binary_ptr_assert, etc. -* -* @text_: Pointer to a kunit_binary_assert_text. -* @left_val: The actual evaluated value of the expression in the left slot. -* @right_val: The actual evaluated value of the expression in the right slot. -* -* Initializes a binary assert like kunit_binary_assert, -* kunit_binary_ptr_assert, etc. This relies on these structs having the same -* fields but with different types for left_val/right_val. -* This is ultimately used by binary assertion macros like KUNIT_EXPECT_EQ, etc. -*/ -#define KUNIT_INIT_BINARY_ASSERT_STRUCT (text_, \ - left_val, \ - right_val) { \ - .text = text_, \ - .left_value = left_val, \ - .right_value = right_val \ -} -/** * struct kunit_binary_ptr_assert - An expectation/assertion that compares two * pointer values (for example, KUNIT_EXPECT_PTR_EQ(test, foo, bar)). include/kunit/test.h +15
-13@@ -514,22 +514,25 @@ void kunit_do_failed_assertion(struct kunit *test, fmt, \ ##__VA_ARGS__) +/* Helper to safely pass around an initializer list to other macros. */ +#define KUNIT_INIT_ASSERT(initializers...) { initializers } +#define KUNIT_UNARY_ASSERTION (test, \ assert_type, \ - condition, \ - expected_true, \ + condition_, \ + expected_true_, \ fmt, \ ...) \ do { \ - if (likely(!!(condition) == !!expected_true)) \ + if (likely(!!(condition_) == !!expected_true_)) \ break; \ \ _KUNIT_FAILED(test, \ assert_type, \ kunit_unary_assert, \ kunit_unary_assert_format, \ - KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \ - expected_true), \ + KUNIT_INIT_ASSERT(.condition = #condition_, \ + .expected_true = expected_true_), \ fmt, \ ##__VA_ARGS__); \ } while (0)@@ -589,9 +592,9 @@ do { \ assert_type, \ assert_class, \ format_func, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ - __left, \ - __right), \ + KUNIT_INIT_ASSERT(.text = &__text, \ + .left_value = __left, \ + .right_value = __right), \ fmt, \ ##__VA_ARGS__); \ }while (0 )@@ -650,9 +653,9 @@ do { \ assert_type, \ kunit_binary_str_assert, \ kunit_binary_str_assert_format, \ -KUNIT_INIT_BINARY_ASSERT_STRUCT (&__text, \ - __left, \ - __right), \ + KUNIT_INIT_ASSERT(.text = &__text, \ + .left_value = __left, \ + .right_value = __right), \ fmt, \ ##__VA_ARGS__); \ }while (0 )@@ -672,7 +675,7 @@ do { \ assert_type, \ kunit_ptr_not_err_assert, \ kunit_ptr_not_err_assert_format, \ - KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, __ptr), \ + KUNIT_INIT_ASSERT(.text = #ptr, .value = __ptr), \ fmt, \ ##__VA_ARGS__); \ } while (0) --2.38.0.rc1.362.ged0d419d3c-goog
Re: [PATCH 3/4] kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros
In reply to Daniel LatypovQuoted 3 lines · Daniel Latypov
But we can work around this with the following generic macro
#defineKUNIT_INIT_ASSERT(initializers...){ initializers }
Is it intended to be internal, right? Should be prefixed by _ then?
Cheers,
Miguel
Re: [PATCH 3/4] kunit: eliminate KUNIT_INIT_*_ASSERT_STRUCT macros
Quoted 7 lines · Miguel Ojeda
Quoted 3 lines · Daniel Latypov
But we can work around this with the following generic macro
#defineKUNIT_INIT_ASSERT(initializers...){ initializers }Is it intended to be internal, right? Should be prefixed by
_then?
Yeah, 100% internal.
We don't have such a convention in KUnit yet, see the discussion in
https://lore.kernel.org/linux-kselftest/CABVgOSmcheQvBRKqc-0ftmbthx=EReoQ-910QV0QMNuxLWjTUQ@mail.gmail.com/T/#u
I'd be personally fine with _s, but this patch just tried to keep things consistent with what was there before.
Daniel
PATCH 4/4 kunit: declare kunit_assert structs as const
In reply to Daniel LatypovEverywhere we use the assert structs now takes them via const*, as of commit 7466886b400b ("kunit: take kunit_assert as const").
So now let's properly declare the structs as const as well.
--- include/kunit/test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/kunit/test.h +1 -1
@@ -477,7 +477,7 @@ void kunit_do_failed_assertion(struct kunit *test,#define _KUNIT_FAILED (test, assert_type, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ - struct assert_class __assertion = INITIALIZER; \ + const struct assert_class __assertion = INITIALIZER; \ kunit_do_failed_assertion(test, \ &__loc, \ assert_type, \
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
Re: [PATCH 4/4] kunit: declare kunit_assert structs as const
Quoted 8 lines · Daniel Latypov' via KUnit Development
Everywhere we use the assert structs now takes them via const*, as of commit
7466886b400b("kunit: takekunit_assertasconst").So now let's properly declare the structs as const as well.
Signed-off-by Daniel Latypov <[email protected]>---
Thanks!
Cheers,
-- David
Quoted 23 lines
include/kunit/test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/kunit/test.h +1
-2@@ -477,7 +477,7 @@ void kunit_do_failed_assertion(struct kunit *test,#define _KUNIT_FAILED (test, assert_type, assert_class, assert_format,INITIALIZER , fmt, ...) do { \ static const struct kunit_loc __loc = KUNIT_CURRENT_LOC; \ - struct assert_class __assertion = INITIALIZER; \ + const struct assert_class __assertion = INITIALIZER; \ kunit_do_failed_assertion(test, \ &__loc, \ assert_type, \ --2.38.0.rc1.362.ged0d419d3c-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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20221001002638.2881842-5-dlatypov%40google.com.
Re: [PATCH 4/4] kunit: declare kunit_assert structs as const
In reply to Daniel LatypovQuoted 5 lines · Daniel Latypov
Everywhere we use the assert structs now takes them via const*, as of commit
7466886b400b("kunit: takekunit_assertasconst").So now let's properly declare the structs as const as well.
Always good to be const-correct :)
Cheers,
Miguel
Quoted 5 lines · Daniel Latypov
Note: this does change the function signature of
kunit_do_failed_assertion, so we'd need to update the rust wrapper in
https://github.com/Rust-for-Linux/linux/blob/rust/rust/kernel/kunit.rs,
but hopefully it's just a simple change, e.g. maybe just like:
Yeah, should be simple. Thanks for pointing it out!
The series looks like a great cleanup on top of the stack reduction.
Cheers,
Miguel
Quoted 11 lines · Miguel Ojeda
Quoted 5 lines · Daniel Latypov
Note: this does change the function signature of
kunit_do_failed_assertion, so we'd need to update the rust wrapper in
https://github.com/Rust-for-Linux/linux/blob/rust/rust/kernel/kunit.rs,
but hopefully it's just a simple change, e.g. maybe just like:Yeah, should be simple. Thanks for pointing it out!
The series looks like a great cleanup on top of the stack reduction.
Thanks for taking a look at the rest of the series as well.
While I have you here, any thoughts on how to coordinate the change? I made the breaking change patch#1 so it should be easier to pull out.
One option I was thinking was:
* wait till this lands in Shuah's tree
* I create a Github PR that contains patch#1 + a patch for kunit.rs
I was not clear on how the RfL Github pulls in upstream changes or how often. But my assumption is patch#1 would fall away naturally if rebasing onto 6.1 (and maybe we can squash the kunit.rs change).
Thanks,
Daniel
Quoted 2 lines · Daniel Latypov
While I have you here, any thoughts on how to coordinate the change?
My bad, I forgot to reply to this, sorry. I noticed it again when merging 6.1-rc1 into our branch.
Normally I fix the issues when I merge back from Linus. Since we intend to keep the CI green on every PR, I added the fix for this in the merge itself.
In any case, to clarify, the rust branch in GitHub is just where we placed a lot of things that we wanted to eventually submit (and some that should not, e.g. the GitHub CI files). We will be minimizing the differences w.r.t. upstream in that branch by preparing proper patches from scratch and submitting them through rust-next and other trees, and eventually remove it (or reusing the name for the fixes branch since that is the name other trees use, but we will see).
Cheers,
Miguel
Quoted 7 lines · Miguel Ojeda
Quoted 2 lines · Daniel Latypov
While I have you here, any thoughts on how to coordinate the change?
My bad, I forgot to reply to this, sorry. I noticed it again when merging 6.1-rc1 into our branch.
No worries.
You've had a very busy couple of weeks, I imagine.
Quoted 4 lines
Normally I fix the issues when I merge back from Linus. Since we intend to keep the CI green on every PR, I added the fix for this in the merge itself.
Thanks!
Daniel
Quoted 3 lines · Daniel Latypov
No worries.
You've had a very busy couple of weeks, I imagine.
Just a bit :) Nevertheless, it was my intention to reply :(
I have linked this thread from the PR noting that you warned me about the future conflict [1], thanks again!
[1] https://github.com/Rust-for-Linux/linux/pull/915#issuecomment-1283138279
Cheers,
Miguel