History

kunit: drop unused kunit* field in kunit_assert

The `struct kunit* test` field in kunit_assert is unused. Note: string_stream needs it, but it has its own `test` field. I assume `test` in `kunit_assert` predates this and was leftover after some refactoring. This patch removes the field and cleans up the macros to avoid needlessly passing around `test`.

Daniel Latypov committed 4 years ago

Commit a91e9ad1 parent 4fdacef2 files · +18 −41Browse files

Showing the changes to include (2 of 2 files). Show all

Unified · Split

2 files
  1. include/kunit/assert.h +13 −32
  2. include/kunit/test.h +5 −9
include/kunit/assert.h+13−32
@@ -30,7 +30,6 @@ enum kunit_assert_type { · 29 unmodified lines
3030
3131 /**
3232 * struct kunit_assert - Data for printing a failed assertion or expectation.
33− * @test: the test case this expectation/assertion is associated with.
3433 * @type: the type (either an expectation or an assertion) of this kunit_assert.
3534 * @line: the source code line number that the expectation/assertion is at.
3635 * @file: the file path of the source file that the expectation/assertion is in.
@@ -41,7 +40,6 @@ enum kunit_assert_type { · 4 unmodified lines
4140 * format a string to a user reporting the failure.
4241 */
4342 struct kunit_assert {
44− struct kunit *test;
4543 enum kunit_assert_type type;
4644 int line;
4745 const char *file;
@@ -60,14 +58,12 @@ struct kunit_assert { · 12 unmodified lines
6058
6159 /**
6260 * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert.
63− * @kunit: The test case that this expectation/assertion is associated with.
6461 * @assert_type: The type (assertion or expectation) of this kunit_assert.
6562 * @fmt: The formatting function which builds a string out of this kunit_assert.
6663 *
6764 * The base initializer for a &struct kunit_assert.
6865 */
69−#define KUNIT_INIT_ASSERT_STRUCT(kunit, assert_type, fmt) { \
70− .test = kunit, \
66+#define KUNIT_INIT_ASSERT_STRUCT(assert_type, fmt) { \
7167 .type = assert_type, \
7268 .file = __FILE__, \
7369 .line = __LINE__, \
@@ -96,15 +92,13 @@ void kunit_fail_assert_format(const struct kunit_assert *assert, · 22 unmodified lines
9692
9793 /**
9894 * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert.
99− * @test: The test case that this expectation/assertion is associated with.
10095 * @type: The type (assertion or expectation) of this kunit_assert.
10196 *
10297 * Initializes a &struct kunit_fail_assert. Intended to be used in
10398 * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
10499 */
105−#define KUNIT_INIT_FAIL_ASSERT_STRUCT(test, type) { \
106− .assert = KUNIT_INIT_ASSERT_STRUCT(test, \
107− type, \
100+#define KUNIT_INIT_FAIL_ASSERT_STRUCT(type) { \
101+ .assert = KUNIT_INIT_ASSERT_STRUCT(type, \
108102 kunit_fail_assert_format) \
109103 }
110104
@@ -129,7 +123,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert, · 18 unmodified lines
129123
130124 /**
131125 * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert.
132− * @test: The test case that this expectation/assertion is associated with.
133126 * @type: The type (assertion or expectation) of this kunit_assert.
134127 * @cond: A string representation of the expression asserted true or false.
135128 * @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise.
@@ -137,9 +130,8 @@ void kunit_unary_assert_format(const struct kunit_assert *assert, · 1 unmodified line
137130 * Initializes a &struct kunit_unary_assert. Intended to be used in
138131 * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
139132 */
140−#define KUNIT_INIT_UNARY_ASSERT_STRUCT(test, type, cond, expect_true) { \
141− .assert = KUNIT_INIT_ASSERT_STRUCT(test, \
142− type, \
133+#define KUNIT_INIT_UNARY_ASSERT_STRUCT(type, cond, expect_true) { \
134+ .assert = KUNIT_INIT_ASSERT_STRUCT(type, \
143135 kunit_unary_assert_format), \
144136 .condition = cond, \
145137 .expected_true = expect_true \
@@ -167,7 +159,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, · 21 unmodified lines
167159 /**
168160 * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a
169161 * &struct kunit_ptr_not_err_assert.
170− * @test: The test case that this expectation/assertion is associated with.
171162 * @type: The type (assertion or expectation) of this kunit_assert.
172163 * @txt: A string representation of the expression passed to the expectation.
173164 * @val: The actual evaluated pointer value of the expression.
@@ -175,9 +166,8 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, · 1 unmodified line
175166 * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in
176167 * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
177168 */
178−#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, type, txt, val) { \
179− .assert = KUNIT_INIT_ASSERT_STRUCT(test, \
180− type, \
169+#define KUNIT_INIT_PTR_NOT_ERR_STRUCT(type, txt, val) { \
170+ .assert = KUNIT_INIT_ASSERT_STRUCT(type, \
181171 kunit_ptr_not_err_assert_format), \
182172 .text = txt, \
183173 .value = val \
@@ -212,7 +202,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, · 28 unmodified lines
212202 /**
213203 * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a
214204 * &struct kunit_binary_assert.
215− * @test: The test case that this expectation/assertion is associated with.
216205 * @type: The type (assertion or expectation) of this kunit_assert.
217206 * @op_str: A string representation of the comparison operator (e.g. "==").
218207 * @left_str: A string representation of the expression in the left slot.
@@ -223,15 +212,13 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, · 4 unmodified lines
223212 * Initializes a &struct kunit_binary_assert. Intended to be used in
224213 * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
225214 */
226−#define KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \
227− type, \
215+#define KUNIT_INIT_BINARY_ASSERT_STRUCT(type, \
228216 op_str, \
229217 left_str, \
230218 left_val, \
231219 right_str, \
232220 right_val) { \
233− .assert = KUNIT_INIT_ASSERT_STRUCT(test, \
234− type, \
221+ .assert = KUNIT_INIT_ASSERT_STRUCT(type, \
235222 kunit_binary_assert_format), \
236223 .operation = op_str, \
237224 .left_text = left_str, \
@@ -269,7 +256,6 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert, · 31 unmodified lines
269256 /**
270257 * KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT() - Initializes a
271258 * &struct kunit_binary_ptr_assert.
272− * @test: The test case that this expectation/assertion is associated with.
273259 * @type: The type (assertion or expectation) of this kunit_assert.
274260 * @op_str: A string representation of the comparison operator (e.g. "==").
275261 * @left_str: A string representation of the expression in the left slot.
@@ -280,15 +266,13 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert, · 4 unmodified lines
280266 * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in
281267 * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
282268 */
283−#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(test, \
284− type, \
269+#define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(type, \
285270 op_str, \
286271 left_str, \
287272 left_val, \
288273 right_str, \
289274 right_val) { \
290− .assert = KUNIT_INIT_ASSERT_STRUCT(test, \
291− type, \
275+ .assert = KUNIT_INIT_ASSERT_STRUCT(type, \
292276 kunit_binary_ptr_assert_format), \
293277 .operation = op_str, \
294278 .left_text = left_str, \
@@ -326,7 +310,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert, · 31 unmodified lines
326310 /**
327311 * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a
328312 * &struct kunit_binary_str_assert.
329− * @test: The test case that this expectation/assertion is associated with.
330313 * @type: The type (assertion or expectation) of this kunit_assert.
331314 * @op_str: A string representation of the comparison operator (e.g. "==").
332315 * @left_str: A string representation of the expression in the left slot.
@@ -337,15 +320,13 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert, · 4 unmodified lines
337320 * Initializes a &struct kunit_binary_str_assert. Intended to be used in
338321 * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros.
339322 */
340−#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test, \
341− type, \
323+#define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(type, \
342324 op_str, \
343325 left_str, \
344326 left_val, \
345327 right_str, \
346328 right_val) { \
347− .assert = KUNIT_INIT_ASSERT_STRUCT(test, \
348− type, \
329+ .assert = KUNIT_INIT_ASSERT_STRUCT(type, \
349330 kunit_binary_str_assert_format), \
350331 .operation = op_str, \
351332 .left_text = left_str, \
include/kunit/test.h+5−9
@@ -790,7 +790,7 @@ void kunit_do_failed_assertion(struct kunit *test, · 789 unmodified lines
790790 KUNIT_ASSERTION(test, \
791791 false, \
792792 kunit_fail_assert, \
793− KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \
793+ KUNIT_INIT_FAIL_ASSERT_STRUCT(assert_type), \
794794 fmt, \
795795 ##__VA_ARGS__)
796796
@@ -820,8 +820,7 @@ void kunit_do_failed_assertion(struct kunit *test, · 23 unmodified lines
820820 KUNIT_ASSERTION(test, \
821821 !!(condition) == !!expected_true, \
822822 kunit_unary_assert, \
823− KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \
824− assert_type, \
823+ KUNIT_INIT_UNARY_ASSERT_STRUCT(assert_type, \
825824 #condition, \
826825 expected_true), \
827826 fmt, \
@@ -879,8 +878,7 @@ do { \ · 51 unmodified lines
879878 KUNIT_ASSERTION(test, \
880879 __left op __right, \
881880 assert_class, \
882− ASSERT_CLASS_INIT(test, \
883− assert_type, \
881+ ASSERT_CLASS_INIT(assert_type, \
884882 #op, \
885883 #left, \
886884 __left, \
@@ -1234,8 +1232,7 @@ do { \ · 347 unmodified lines
12341232 KUNIT_ASSERTION(test, \
12351233 strcmp(__left, __right) op 0, \
12361234 kunit_binary_str_assert, \
1237− KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test, \
1238− assert_type, \
1235+ KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(assert_type, \
12391236 #op, \
12401237 #left, \
12411238 __left, \
@@ -1294,8 +1291,7 @@ do { \ · 52 unmodified lines
12941291 KUNIT_ASSERTION(test, \
12951292 !IS_ERR_OR_NULL(__ptr), \
12961293 kunit_ptr_not_err_assert, \
1297− KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \
1298− assert_type, \
1294+ KUNIT_INIT_PTR_NOT_ERR_STRUCT(assert_type, \
12991295 #ptr, \
13001296 __ptr), \
13011297 fmt, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t