Commit 05a7da89 authored by Daniel Latypov's avatar Daniel Latypov Committed by Shuah Khan

kunit: drop unused assert_type from kunit_assert and clean up macros

This field has been split out from kunit_assert to make the struct less
heavy along with the filename and line number.

This change drops the assert_type field and cleans up all the macros
that were plumbing assert_type into kunit_assert.
Signed-off-by: default avatarDaniel Latypov <dlatypov@google.com>
Reviewed-by: default avatarDavid Gow <davidgow@google.com>
Reviewed-by: default avatarBrendan Higgins <brendanhiggins@google.com>
Signed-off-by: default avatarShuah Khan <skhan@linuxfoundation.org>
parent 21957f90
...@@ -42,7 +42,6 @@ struct kunit_loc { ...@@ -42,7 +42,6 @@ struct kunit_loc {
/** /**
* struct kunit_assert - Data for printing a failed assertion or expectation. * struct kunit_assert - Data for printing a failed assertion or expectation.
* @type: the type (either an expectation or an assertion) of this kunit_assert.
* @message: an optional message to provide additional context. * @message: an optional message to provide additional context.
* @format: a function which formats the data in this kunit_assert to a string. * @format: a function which formats the data in this kunit_assert to a string.
* *
...@@ -50,9 +49,6 @@ struct kunit_loc { ...@@ -50,9 +49,6 @@ struct kunit_loc {
* format a string to a user reporting the failure. * format a string to a user reporting the failure.
*/ */
struct kunit_assert { struct kunit_assert {
// TODO(dlatypov@google.com): delete this unused field when we've
// updated all the related KUNIT_INIT_ASSERT* macros.
enum kunit_assert_type type;
struct va_format message; struct va_format message;
void (*format)(const struct kunit_assert *assert, void (*format)(const struct kunit_assert *assert,
struct string_stream *stream); struct string_stream *stream);
...@@ -68,13 +64,11 @@ struct kunit_assert { ...@@ -68,13 +64,11 @@ struct kunit_assert {
/** /**
* KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert. * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert.
* @assert_type: The type (assertion or expectation) of this kunit_assert.
* @fmt: The formatting function which builds a string out of this kunit_assert. * @fmt: The formatting function which builds a string out of this kunit_assert.
* *
* The base initializer for a &struct kunit_assert. * The base initializer for a &struct kunit_assert.
*/ */
#define KUNIT_INIT_ASSERT_STRUCT(assert_type, fmt) { \ #define KUNIT_INIT_ASSERT_STRUCT(fmt) { \
.type = assert_type, \
.message = KUNIT_INIT_VA_FMT_NULL, \ .message = KUNIT_INIT_VA_FMT_NULL, \
.format = fmt \ .format = fmt \
} }
...@@ -100,15 +94,13 @@ void kunit_fail_assert_format(const struct kunit_assert *assert, ...@@ -100,15 +94,13 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,
struct string_stream *stream); struct string_stream *stream);
/** /**
* KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert. * KUNIT_INIT_FAIL_ASSERT_STRUCT - Initializer for &struct kunit_fail_assert.
* @type: The type (assertion or expectation) of this kunit_assert.
* *
* Initializes a &struct kunit_fail_assert. Intended to be used in * Initializes a &struct kunit_fail_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_FAIL_ASSERT_STRUCT(type) { \ #define KUNIT_INIT_FAIL_ASSERT_STRUCT { \
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \ .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_fail_assert_format) \
kunit_fail_assert_format) \
} }
/** /**
...@@ -132,16 +124,14 @@ void kunit_unary_assert_format(const struct kunit_assert *assert, ...@@ -132,16 +124,14 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,
/** /**
* KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert. * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert.
* @type: The type (assertion or expectation) of this kunit_assert.
* @cond: A string representation of the expression asserted true or false. * @cond: A string representation of the expression asserted true or false.
* @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise. * @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise.
* *
* Initializes a &struct kunit_unary_assert. Intended to be used in * Initializes a &struct kunit_unary_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_UNARY_ASSERT_STRUCT(type, cond, expect_true) { \ #define KUNIT_INIT_UNARY_ASSERT_STRUCT(cond, expect_true) { \
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \ .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_unary_assert_format), \
kunit_unary_assert_format), \
.condition = cond, \ .condition = cond, \
.expected_true = expect_true \ .expected_true = expect_true \
} }
...@@ -168,16 +158,14 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, ...@@ -168,16 +158,14 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
/** /**
* KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a
* &struct kunit_ptr_not_err_assert. * &struct kunit_ptr_not_err_assert.
* @type: The type (assertion or expectation) of this kunit_assert.
* @txt: A string representation of the expression passed to the expectation. * @txt: A string representation of the expression passed to the expectation.
* @val: The actual evaluated pointer value of the expression. * @val: The actual evaluated pointer value of the expression.
* *
* Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(type, txt, val) { \ #define KUNIT_INIT_PTR_NOT_ERR_STRUCT(txt, val) { \
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \ .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_ptr_not_err_assert_format), \
kunit_ptr_not_err_assert_format), \
.text = txt, \ .text = txt, \
.value = val \ .value = val \
} }
...@@ -211,7 +199,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, ...@@ -211,7 +199,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
/** /**
* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a
* &struct kunit_binary_assert. * &struct kunit_binary_assert.
* @type: The type (assertion or expectation) of this kunit_assert.
* @op_str: A string representation of the comparison operator (e.g. "=="). * @op_str: A string representation of the comparison operator (e.g. "==").
* @left_str: A string representation of the expression in the left slot. * @left_str: A string representation of the expression in the left slot.
* @left_val: The actual evaluated value of the expression in the left slot. * @left_val: The actual evaluated value of the expression in the left slot.
...@@ -221,14 +208,12 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, ...@@ -221,14 +208,12 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
* Initializes a &struct kunit_binary_assert. Intended to be used in * Initializes a &struct kunit_binary_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_BINARY_ASSERT_STRUCT(type, \ #define KUNIT_INIT_BINARY_ASSERT_STRUCT(op_str, \
op_str, \
left_str, \ left_str, \
left_val, \ left_val, \
right_str, \ right_str, \
right_val) { \ right_val) { \
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \ .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_assert_format), \
kunit_binary_assert_format), \
.operation = op_str, \ .operation = op_str, \
.left_text = left_str, \ .left_text = left_str, \
.left_value = left_val, \ .left_value = left_val, \
...@@ -275,14 +260,12 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert, ...@@ -275,14 +260,12 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
* Initializes a &struct kunit_binary_ptr_assert. Intended to be used in * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(type, \ #define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(op_str, \
op_str, \
left_str, \ left_str, \
left_val, \ left_val, \
right_str, \ right_str, \
right_val) { \ right_val) { \
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \ .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_ptr_assert_format), \
kunit_binary_ptr_assert_format), \
.operation = op_str, \ .operation = op_str, \
.left_text = left_str, \ .left_text = left_str, \
.left_value = left_val, \ .left_value = left_val, \
...@@ -319,7 +302,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert, ...@@ -319,7 +302,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
/** /**
* KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a
* &struct kunit_binary_str_assert. * &struct kunit_binary_str_assert.
* @type: The type (assertion or expectation) of this kunit_assert.
* @op_str: A string representation of the comparison operator (e.g. "=="). * @op_str: A string representation of the comparison operator (e.g. "==").
* @left_str: A string representation of the expression in the left slot. * @left_str: A string representation of the expression in the left slot.
* @left_val: The actual evaluated value of the expression in the left slot. * @left_val: The actual evaluated value of the expression in the left slot.
...@@ -329,14 +311,12 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert, ...@@ -329,14 +311,12 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
* Initializes a &struct kunit_binary_str_assert. Intended to be used in * Initializes a &struct kunit_binary_str_assert. Intended to be used in
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
*/ */
#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(type, \ #define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(op_str, \
op_str, \
left_str, \ left_str, \
left_val, \ left_val, \
right_str, \ right_str, \
right_val) { \ right_val) { \
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \ .assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_str_assert_format), \
kunit_binary_str_assert_format), \
.operation = op_str, \ .operation = op_str, \
.left_text = left_str, \ .left_text = left_str, \
.left_value = left_val, \ .left_value = left_val, \
......
...@@ -796,7 +796,7 @@ void kunit_do_failed_assertion(struct kunit *test, ...@@ -796,7 +796,7 @@ void kunit_do_failed_assertion(struct kunit *test,
assert_type, \ assert_type, \
false, \ false, \
kunit_fail_assert, \ kunit_fail_assert, \
KUNIT_INIT_FAIL_ASSERT_STRUCT(assert_type), \ KUNIT_INIT_FAIL_ASSERT_STRUCT, \
fmt, \ fmt, \
##__VA_ARGS__) ##__VA_ARGS__)
...@@ -827,8 +827,7 @@ void kunit_do_failed_assertion(struct kunit *test, ...@@ -827,8 +827,7 @@ void kunit_do_failed_assertion(struct kunit *test,
assert_type, \ assert_type, \
!!(condition) == !!expected_true, \ !!(condition) == !!expected_true, \
kunit_unary_assert, \ kunit_unary_assert, \
KUNIT_INIT_UNARY_ASSERT_STRUCT(assert_type, \ KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \
#condition, \
expected_true), \ expected_true), \
fmt, \ fmt, \
##__VA_ARGS__) ##__VA_ARGS__)
...@@ -886,8 +885,7 @@ do { \ ...@@ -886,8 +885,7 @@ do { \
assert_type, \ assert_type, \
__left op __right, \ __left op __right, \
assert_class, \ assert_class, \
ASSERT_CLASS_INIT(assert_type, \ ASSERT_CLASS_INIT(#op, \
#op, \
#left, \ #left, \
__left, \ __left, \
#right, \ #right, \
...@@ -1241,8 +1239,7 @@ do { \ ...@@ -1241,8 +1239,7 @@ do { \
assert_type, \ assert_type, \
strcmp(__left, __right) op 0, \ strcmp(__left, __right) op 0, \
kunit_binary_str_assert, \ kunit_binary_str_assert, \
KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(assert_type, \ KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(#op, \
#op, \
#left, \ #left, \
__left, \ __left, \
#right, \ #right, \
...@@ -1301,8 +1298,7 @@ do { \ ...@@ -1301,8 +1298,7 @@ do { \
assert_type, \ assert_type, \
!IS_ERR_OR_NULL(__ptr), \ !IS_ERR_OR_NULL(__ptr), \
kunit_ptr_not_err_assert, \ kunit_ptr_not_err_assert, \
KUNIT_INIT_PTR_NOT_ERR_STRUCT(assert_type, \ KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \
#ptr, \
__ptr), \ __ptr), \
fmt, \ fmt, \
##__VA_ARGS__); \ ##__VA_ARGS__); \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment