Skip to content

Commit 05a7da8

Browse files
dlatypovshuahkh
authored andcommitted
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: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 21957f9 commit 05a7da8

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

include/kunit/assert.h

+14-34
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,13 @@ struct kunit_loc {
4242

4343
/**
4444
* struct kunit_assert - Data for printing a failed assertion or expectation.
45-
* @type: the type (either an expectation or an assertion) of this kunit_assert.
4645
* @message: an optional message to provide additional context.
4746
* @format: a function which formats the data in this kunit_assert to a string.
4847
*
4948
* Represents a failed expectation/assertion. Contains all the data necessary to
5049
* format a string to a user reporting the failure.
5150
*/
5251
struct kunit_assert {
53-
// TODO(dlatypov@google.com): delete this unused field when we've
54-
// updated all the related KUNIT_INIT_ASSERT* macros.
55-
enum kunit_assert_type type;
5652
struct va_format message;
5753
void (*format)(const struct kunit_assert *assert,
5854
struct string_stream *stream);
@@ -68,13 +64,11 @@ struct kunit_assert {
6864

6965
/**
7066
* KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert.
71-
* @assert_type: The type (assertion or expectation) of this kunit_assert.
7267
* @fmt: The formatting function which builds a string out of this kunit_assert.
7368
*
7469
* The base initializer for a &struct kunit_assert.
7570
*/
76-
#define KUNIT_INIT_ASSERT_STRUCT(assert_type, fmt) { \
77-
.type = assert_type, \
71+
#define KUNIT_INIT_ASSERT_STRUCT(fmt) { \
7872
.message = KUNIT_INIT_VA_FMT_NULL, \
7973
.format = fmt \
8074
}
@@ -100,15 +94,13 @@ void kunit_fail_assert_format(const struct kunit_assert *assert,
10094
struct string_stream *stream);
10195

10296
/**
103-
* KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert.
104-
* @type: The type (assertion or expectation) of this kunit_assert.
97+
* KUNIT_INIT_FAIL_ASSERT_STRUCT - Initializer for &struct kunit_fail_assert.
10598
*
10699
* Initializes a &struct kunit_fail_assert. Intended to be used in
107100
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
108101
*/
109-
#define KUNIT_INIT_FAIL_ASSERT_STRUCT(type) { \
110-
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \
111-
kunit_fail_assert_format) \
102+
#define KUNIT_INIT_FAIL_ASSERT_STRUCT { \
103+
.assert = KUNIT_INIT_ASSERT_STRUCT(kunit_fail_assert_format) \
112104
}
113105

114106
/**
@@ -132,16 +124,14 @@ void kunit_unary_assert_format(const struct kunit_assert *assert,
132124

133125
/**
134126
* KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert.
135-
* @type: The type (assertion or expectation) of this kunit_assert.
136127
* @cond: A string representation of the expression asserted true or false.
137128
* @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise.
138129
*
139130
* Initializes a &struct kunit_unary_assert. Intended to be used in
140131
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
141132
*/
142-
#define KUNIT_INIT_UNARY_ASSERT_STRUCT(type, cond, expect_true) { \
143-
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \
144-
kunit_unary_assert_format), \
133+
#define KUNIT_INIT_UNARY_ASSERT_STRUCT(cond, expect_true) { \
134+
.assert = KUNIT_INIT_ASSERT_STRUCT(kunit_unary_assert_format), \
145135
.condition = cond, \
146136
.expected_true = expect_true \
147137
}
@@ -168,16 +158,14 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert,
168158
/**
169159
* KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a
170160
* &struct kunit_ptr_not_err_assert.
171-
* @type: The type (assertion or expectation) of this kunit_assert.
172161
* @txt: A string representation of the expression passed to the expectation.
173162
* @val: The actual evaluated pointer value of the expression.
174163
*
175164
* Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in
176165
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
177166
*/
178-
#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(type, txt, val) { \
179-
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \
180-
kunit_ptr_not_err_assert_format), \
167+
#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(txt, val) { \
168+
.assert = KUNIT_INIT_ASSERT_STRUCT(kunit_ptr_not_err_assert_format), \
181169
.text = txt, \
182170
.value = val \
183171
}
@@ -211,7 +199,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert,
211199
/**
212200
* KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a
213201
* &struct kunit_binary_assert.
214-
* @type: The type (assertion or expectation) of this kunit_assert.
215202
* @op_str: A string representation of the comparison operator (e.g. "==").
216203
* @left_str: A string representation of the expression in the left slot.
217204
* @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,
221208
* Initializes a &struct kunit_binary_assert. Intended to be used in
222209
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
223210
*/
224-
#define KUNIT_INIT_BINARY_ASSERT_STRUCT(type, \
225-
op_str, \
211+
#define KUNIT_INIT_BINARY_ASSERT_STRUCT(op_str, \
226212
left_str, \
227213
left_val, \
228214
right_str, \
229215
right_val) { \
230-
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \
231-
kunit_binary_assert_format), \
216+
.assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_assert_format), \
232217
.operation = op_str, \
233218
.left_text = left_str, \
234219
.left_value = left_val, \
@@ -275,14 +260,12 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert,
275260
* Initializes a &struct kunit_binary_ptr_assert. Intended to be used in
276261
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
277262
*/
278-
#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(type, \
279-
op_str, \
263+
#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(op_str, \
280264
left_str, \
281265
left_val, \
282266
right_str, \
283267
right_val) { \
284-
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \
285-
kunit_binary_ptr_assert_format), \
268+
.assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_ptr_assert_format), \
286269
.operation = op_str, \
287270
.left_text = left_str, \
288271
.left_value = left_val, \
@@ -319,7 +302,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert,
319302
/**
320303
* KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a
321304
* &struct kunit_binary_str_assert.
322-
* @type: The type (assertion or expectation) of this kunit_assert.
323305
* @op_str: A string representation of the comparison operator (e.g. "==").
324306
* @left_str: A string representation of the expression in the left slot.
325307
* @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,
329311
* Initializes a &struct kunit_binary_str_assert. Intended to be used in
330312
* KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
331313
*/
332-
#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(type, \
333-
op_str, \
314+
#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(op_str, \
334315
left_str, \
335316
left_val, \
336317
right_str, \
337318
right_val) { \
338-
.assert = KUNIT_INIT_ASSERT_STRUCT(type, \
339-
kunit_binary_str_assert_format), \
319+
.assert = KUNIT_INIT_ASSERT_STRUCT(kunit_binary_str_assert_format), \
340320
.operation = op_str, \
341321
.left_text = left_str, \
342322
.left_value = left_val, \

include/kunit/test.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ void kunit_do_failed_assertion(struct kunit *test,
796796
assert_type, \
797797
false, \
798798
kunit_fail_assert, \
799-
KUNIT_INIT_FAIL_ASSERT_STRUCT(assert_type), \
799+
KUNIT_INIT_FAIL_ASSERT_STRUCT, \
800800
fmt, \
801801
##__VA_ARGS__)
802802

@@ -827,8 +827,7 @@ void kunit_do_failed_assertion(struct kunit *test,
827827
assert_type, \
828828
!!(condition) == !!expected_true, \
829829
kunit_unary_assert, \
830-
KUNIT_INIT_UNARY_ASSERT_STRUCT(assert_type, \
831-
#condition, \
830+
KUNIT_INIT_UNARY_ASSERT_STRUCT(#condition, \
832831
expected_true), \
833832
fmt, \
834833
##__VA_ARGS__)
@@ -886,8 +885,7 @@ do { \
886885
assert_type, \
887886
__left op __right, \
888887
assert_class, \
889-
ASSERT_CLASS_INIT(assert_type, \
890-
#op, \
888+
ASSERT_CLASS_INIT(#op, \
891889
#left, \
892890
__left, \
893891
#right, \
@@ -1241,8 +1239,7 @@ do { \
12411239
assert_type, \
12421240
strcmp(__left, __right) op 0, \
12431241
kunit_binary_str_assert, \
1244-
KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(assert_type, \
1245-
#op, \
1242+
KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(#op, \
12461243
#left, \
12471244
__left, \
12481245
#right, \
@@ -1301,8 +1298,7 @@ do { \
13011298
assert_type, \
13021299
!IS_ERR_OR_NULL(__ptr), \
13031300
kunit_ptr_not_err_assert, \
1304-
KUNIT_INIT_PTR_NOT_ERR_STRUCT(assert_type, \
1305-
#ptr, \
1301+
KUNIT_INIT_PTR_NOT_ERR_STRUCT(#ptr, \
13061302
__ptr), \
13071303
fmt, \
13081304
##__VA_ARGS__); \

0 commit comments

Comments
 (0)