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`.
Showing the changes to include (2 of 2 files). Show all
Unified · Split
| @@ -30,7 +30,6 @@ enum kunit_assert_type { · 29 unmodified lines | |||
| 30 | 30 | ||
| 31 | /** | 31 | /** |
| 32 | * struct kunit_assert - Data for printing a failed assertion or expectation. | 32 | * struct kunit_assert - Data for printing a failed assertion or expectation. |
| 33 | * @test: the test case this expectation/assertion is associated with. | ||
| 34 | * @type: the type (either an expectation or an assertion) of this kunit_assert. | 33 | * @type: the type (either an expectation or an assertion) of this kunit_assert. |
| 35 | * @line: the source code line number that the expectation/assertion is at. | 34 | * @line: the source code line number that the expectation/assertion is at. |
| 36 | * @file: the file path of the source file that the expectation/assertion is in. | 35 | * @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 | |||
| 41 | * format a string to a user reporting the failure. | 40 | * format a string to a user reporting the failure. |
| 42 | */ | 41 | */ |
| 43 | struct kunit_assert { | 42 | struct kunit_assert { |
| 44 | struct kunit *test; | ||
| 45 | enum kunit_assert_type type; | 43 | enum kunit_assert_type type; |
| 46 | int line; | 44 | int line; |
| 47 | const char *file; | 45 | const char *file; |
| @@ -60,14 +58,12 @@ struct kunit_assert { · 12 unmodified lines | |||
| 60 | 58 | ||
| 61 | /** | 59 | /** |
| 62 | * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert. | 60 | * KUNIT_INIT_ASSERT_STRUCT() - Initializer for a &struct kunit_assert. |
| 63 | * @kunit: The test case that this expectation/assertion is associated with. | ||
| 64 | * @assert_type: The type (assertion or expectation) of this kunit_assert. | 61 | * @assert_type: The type (assertion or expectation) of this kunit_assert. |
| 65 | * @fmt: The formatting function which builds a string out of this kunit_assert. | 62 | * @fmt: The formatting function which builds a string out of this kunit_assert. |
| 66 | * | 63 | * |
| 67 | * The base initializer for a &struct kunit_assert. | 64 | * The base initializer for a &struct kunit_assert. |
| 68 | */ | 65 | */ |
| 69 | #define KUNIT_INIT_ASSERT_STRUCT(kunit, assert_type, fmt) { \ | 66 | #define KUNIT_INIT_ASSERT_STRUCT(assert_type, fmt) { \ |
| 70 | .test = kunit, \ | ||
| 71 | .type = assert_type, \ | 67 | .type = assert_type, \ |
| 72 | .file = __FILE__, \ | 68 | .file = __FILE__, \ |
| 73 | .line = __LINE__, \ | 69 | .line = __LINE__, \ |
| @@ -96,15 +92,13 @@ void kunit_fail_assert_format(const struct kunit_assert *assert, · 22 unmodified lines | |||
| 96 | 92 | ||
| 97 | /** | 93 | /** |
| 98 | * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert. | 94 | * KUNIT_INIT_FAIL_ASSERT_STRUCT() - Initializer for &struct kunit_fail_assert. |
| 99 | * @test: The test case that this expectation/assertion is associated with. | ||
| 100 | * @type: The type (assertion or expectation) of this kunit_assert. | 95 | * @type: The type (assertion or expectation) of this kunit_assert. |
| 101 | * | 96 | * |
| 102 | * Initializes a &struct kunit_fail_assert. Intended to be used in | 97 | * Initializes a &struct kunit_fail_assert. Intended to be used in |
| 103 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. | 98 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. |
| 104 | */ | 99 | */ |
| 105 | #define KUNIT_INIT_FAIL_ASSERT_STRUCT(test, type) { \ | 100 | #define KUNIT_INIT_FAIL_ASSERT_STRUCT(type) { \ |
| 106 | .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ | 101 | .assert = KUNIT_INIT_ASSERT_STRUCT(type, \ |
| 107 | type, \ | ||
| 108 | kunit_fail_assert_format) \ | 102 | kunit_fail_assert_format) \ |
| 109 | } | 103 | } |
| 110 | 104 | ||
| @@ -129,7 +123,6 @@ void kunit_unary_assert_format(const struct kunit_assert *assert, · 18 unmodified lines | |||
| 129 | 123 | ||
| 130 | /** | 124 | /** |
| 131 | * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert. | 125 | * KUNIT_INIT_UNARY_ASSERT_STRUCT() - Initializes &struct kunit_unary_assert. |
| 132 | * @test: The test case that this expectation/assertion is associated with. | ||
| 133 | * @type: The type (assertion or expectation) of this kunit_assert. | 126 | * @type: The type (assertion or expectation) of this kunit_assert. |
| 134 | * @cond: A string representation of the expression asserted true or false. | 127 | * @cond: A string representation of the expression asserted true or false. |
| 135 | * @expect_true: True if of type KUNIT_{EXPECT|ASSERT}_TRUE, false otherwise. | 128 | * @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 | |||
| 137 | * Initializes a &struct kunit_unary_assert. Intended to be used in | 130 | * Initializes a &struct kunit_unary_assert. Intended to be used in |
| 138 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. | 131 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. |
| 139 | */ | 132 | */ |
| 140 | #define KUNIT_INIT_UNARY_ASSERT_STRUCT(test, type, cond, expect_true) { \ | 133 | #define KUNIT_INIT_UNARY_ASSERT_STRUCT(type, cond, expect_true) { \ |
| 141 | .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ | 134 | .assert = KUNIT_INIT_ASSERT_STRUCT(type, \ |
| 142 | type, \ | ||
| 143 | kunit_unary_assert_format), \ | 135 | kunit_unary_assert_format), \ |
| 144 | .condition = cond, \ | 136 | .condition = cond, \ |
| 145 | .expected_true = expect_true \ | 137 | .expected_true = expect_true \ |
| @@ -167,7 +159,6 @@ void kunit_ptr_not_err_assert_format(const struct kunit_assert *assert, · 21 unmodified lines | |||
| 167 | /** | 159 | /** |
| 168 | * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a | 160 | * KUNIT_INIT_PTR_NOT_ERR_ASSERT_STRUCT() - Initializes a |
| 169 | * &struct kunit_ptr_not_err_assert. | 161 | * &struct kunit_ptr_not_err_assert. |
| 170 | * @test: The test case that this expectation/assertion is associated with. | ||
| 171 | * @type: The type (assertion or expectation) of this kunit_assert. | 162 | * @type: The type (assertion or expectation) of this kunit_assert. |
| 172 | * @txt: A string representation of the expression passed to the expectation. | 163 | * @txt: A string representation of the expression passed to the expectation. |
| 173 | * @val: The actual evaluated pointer value of the expression. | 164 | * @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 | |||
| 175 | * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in | 166 | * Initializes a &struct kunit_ptr_not_err_assert. Intended to be used in |
| 176 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. | 167 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. |
| 177 | */ | 168 | */ |
| 178 | #define KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, type, txt, val) { \ | 169 | #define KUNIT_INIT_PTR_NOT_ERR_STRUCT(type, txt, val) { \ |
| 179 | .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ | 170 | .assert = KUNIT_INIT_ASSERT_STRUCT(type, \ |
| 180 | type, \ | ||
| 181 | kunit_ptr_not_err_assert_format), \ | 171 | kunit_ptr_not_err_assert_format), \ |
| 182 | .text = txt, \ | 172 | .text = txt, \ |
| 183 | .value = val \ | 173 | .value = val \ |
| @@ -212,7 +202,6 @@ void kunit_binary_assert_format(const struct kunit_assert *assert, · 28 unmodified lines | |||
| 212 | /** | 202 | /** |
| 213 | * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a | 203 | * KUNIT_INIT_BINARY_ASSERT_STRUCT() - Initializes a |
| 214 | * &struct kunit_binary_assert. | 204 | * &struct kunit_binary_assert. |
| 215 | * @test: The test case that this expectation/assertion is associated with. | ||
| 216 | * @type: The type (assertion or expectation) of this kunit_assert. | 205 | * @type: The type (assertion or expectation) of this kunit_assert. |
| 217 | * @op_str: A string representation of the comparison operator (e.g. "=="). | 206 | * @op_str: A string representation of the comparison operator (e.g. "=="). |
| 218 | * @left_str: A string representation of the expression in the left slot. | 207 | * @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 | |||
| 223 | * Initializes a &struct kunit_binary_assert. Intended to be used in | 212 | * Initializes a &struct kunit_binary_assert. Intended to be used in |
| 224 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. | 213 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. |
| 225 | */ | 214 | */ |
| 226 | #define KUNIT_INIT_BINARY_ASSERT_STRUCT(test, \ | 215 | #define KUNIT_INIT_BINARY_ASSERT_STRUCT(type, \ |
| 227 | type, \ | ||
| 228 | op_str, \ | 216 | op_str, \ |
| 229 | left_str, \ | 217 | left_str, \ |
| 230 | left_val, \ | 218 | left_val, \ |
| 231 | right_str, \ | 219 | right_str, \ |
| 232 | right_val) { \ | 220 | right_val) { \ |
| 233 | .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ | 221 | .assert = KUNIT_INIT_ASSERT_STRUCT(type, \ |
| 234 | type, \ | ||
| 235 | kunit_binary_assert_format), \ | 222 | kunit_binary_assert_format), \ |
| 236 | .operation = op_str, \ | 223 | .operation = op_str, \ |
| 237 | .left_text = left_str, \ | 224 | .left_text = left_str, \ |
| @@ -269,7 +256,6 @@ void kunit_binary_ptr_assert_format(const struct kunit_assert *assert, · 31 unmodified lines | |||
| 269 | /** | 256 | /** |
| 270 | * KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT() - Initializes a | 257 | * KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT() - Initializes a |
| 271 | * &struct kunit_binary_ptr_assert. | 258 | * &struct kunit_binary_ptr_assert. |
| 272 | * @test: The test case that this expectation/assertion is associated with. | ||
| 273 | * @type: The type (assertion or expectation) of this kunit_assert. | 259 | * @type: The type (assertion or expectation) of this kunit_assert. |
| 274 | * @op_str: A string representation of the comparison operator (e.g. "=="). | 260 | * @op_str: A string representation of the comparison operator (e.g. "=="). |
| 275 | * @left_str: A string representation of the expression in the left slot. | 261 | * @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 | |||
| 280 | * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in | 266 | * Initializes a &struct kunit_binary_ptr_assert. Intended to be used in |
| 281 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. | 267 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. |
| 282 | */ | 268 | */ |
| 283 | #define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(test, \ | 269 | #define KUNIT_INIT_BINARY_PTR_ASSERT_STRUCT(type, \ |
| 284 | type, \ | ||
| 285 | op_str, \ | 270 | op_str, \ |
| 286 | left_str, \ | 271 | left_str, \ |
| 287 | left_val, \ | 272 | left_val, \ |
| 288 | right_str, \ | 273 | right_str, \ |
| 289 | right_val) { \ | 274 | right_val) { \ |
| 290 | .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ | 275 | .assert = KUNIT_INIT_ASSERT_STRUCT(type, \ |
| 291 | type, \ | ||
| 292 | kunit_binary_ptr_assert_format), \ | 276 | kunit_binary_ptr_assert_format), \ |
| 293 | .operation = op_str, \ | 277 | .operation = op_str, \ |
| 294 | .left_text = left_str, \ | 278 | .left_text = left_str, \ |
| @@ -326,7 +310,6 @@ void kunit_binary_str_assert_format(const struct kunit_assert *assert, · 31 unmodified lines | |||
| 326 | /** | 310 | /** |
| 327 | * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a | 311 | * KUNIT_INIT_BINARY_STR_ASSERT_STRUCT() - Initializes a |
| 328 | * &struct kunit_binary_str_assert. | 312 | * &struct kunit_binary_str_assert. |
| 329 | * @test: The test case that this expectation/assertion is associated with. | ||
| 330 | * @type: The type (assertion or expectation) of this kunit_assert. | 313 | * @type: The type (assertion or expectation) of this kunit_assert. |
| 331 | * @op_str: A string representation of the comparison operator (e.g. "=="). | 314 | * @op_str: A string representation of the comparison operator (e.g. "=="). |
| 332 | * @left_str: A string representation of the expression in the left slot. | 315 | * @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 | |||
| 337 | * Initializes a &struct kunit_binary_str_assert. Intended to be used in | 320 | * Initializes a &struct kunit_binary_str_assert. Intended to be used in |
| 338 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. | 321 | * KUNIT_EXPECT_* and KUNIT_ASSERT_* macros. |
| 339 | */ | 322 | */ |
| 340 | #define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test, \ | 323 | #define KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(type, \ |
| 341 | type, \ | ||
| 342 | op_str, \ | 324 | op_str, \ |
| 343 | left_str, \ | 325 | left_str, \ |
| 344 | left_val, \ | 326 | left_val, \ |
| 345 | right_str, \ | 327 | right_str, \ |
| 346 | right_val) { \ | 328 | right_val) { \ |
| 347 | .assert = KUNIT_INIT_ASSERT_STRUCT(test, \ | 329 | .assert = KUNIT_INIT_ASSERT_STRUCT(type, \ |
| 348 | type, \ | ||
| 349 | kunit_binary_str_assert_format), \ | 330 | kunit_binary_str_assert_format), \ |
| 350 | .operation = op_str, \ | 331 | .operation = op_str, \ |
| 351 | .left_text = left_str, \ | 332 | .left_text = left_str, \ |
| @@ -790,7 +790,7 @@ void kunit_do_failed_assertion(struct kunit *test, · 789 unmodified lines | |||
| 790 | KUNIT_ASSERTION(test, \ | 790 | KUNIT_ASSERTION(test, \ |
| 791 | false, \ | 791 | false, \ |
| 792 | kunit_fail_assert, \ | 792 | kunit_fail_assert, \ |
| 793 | KUNIT_INIT_FAIL_ASSERT_STRUCT(test, assert_type), \ | 793 | KUNIT_INIT_FAIL_ASSERT_STRUCT(assert_type), \ |
| 794 | fmt, \ | 794 | fmt, \ |
| 795 | ##__VA_ARGS__) | 795 | ##__VA_ARGS__) |
| 796 | 796 | ||
| @@ -820,8 +820,7 @@ void kunit_do_failed_assertion(struct kunit *test, · 23 unmodified lines | |||
| 820 | KUNIT_ASSERTION(test, \ | 820 | KUNIT_ASSERTION(test, \ |
| 821 | !!(condition) == !!expected_true, \ | 821 | !!(condition) == !!expected_true, \ |
| 822 | kunit_unary_assert, \ | 822 | kunit_unary_assert, \ |
| 823 | KUNIT_INIT_UNARY_ASSERT_STRUCT(test, \ | 823 | KUNIT_INIT_UNARY_ASSERT_STRUCT(assert_type, \ |
| 824 | assert_type, \ | ||
| 825 | #condition, \ | 824 | #condition, \ |
| 826 | expected_true), \ | 825 | expected_true), \ |
| 827 | fmt, \ | 826 | fmt, \ |
| @@ -879,8 +878,7 @@ do { \ · 51 unmodified lines | |||
| 879 | KUNIT_ASSERTION(test, \ | 878 | KUNIT_ASSERTION(test, \ |
| 880 | __left op __right, \ | 879 | __left op __right, \ |
| 881 | assert_class, \ | 880 | assert_class, \ |
| 882 | ASSERT_CLASS_INIT(test, \ | 881 | ASSERT_CLASS_INIT(assert_type, \ |
| 883 | assert_type, \ | ||
| 884 | #op, \ | 882 | #op, \ |
| 885 | #left, \ | 883 | #left, \ |
| 886 | __left, \ | 884 | __left, \ |
| @@ -1234,8 +1232,7 @@ do { \ · 347 unmodified lines | |||
| 1234 | KUNIT_ASSERTION(test, \ | 1232 | KUNIT_ASSERTION(test, \ |
| 1235 | strcmp(__left, __right) op 0, \ | 1233 | strcmp(__left, __right) op 0, \ |
| 1236 | kunit_binary_str_assert, \ | 1234 | kunit_binary_str_assert, \ |
| 1237 | KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(test, \ | 1235 | KUNIT_INIT_BINARY_STR_ASSERT_STRUCT(assert_type, \ |
| 1238 | assert_type, \ | ||
| 1239 | #op, \ | 1236 | #op, \ |
| 1240 | #left, \ | 1237 | #left, \ |
| 1241 | __left, \ | 1238 | __left, \ |
| @@ -1294,8 +1291,7 @@ do { \ · 52 unmodified lines | |||
| 1294 | KUNIT_ASSERTION(test, \ | 1291 | KUNIT_ASSERTION(test, \ |
| 1295 | !IS_ERR_OR_NULL(__ptr), \ | 1292 | !IS_ERR_OR_NULL(__ptr), \ |
| 1296 | kunit_ptr_not_err_assert, \ | 1293 | kunit_ptr_not_err_assert, \ |
| 1297 | KUNIT_INIT_PTR_NOT_ERR_STRUCT(test, \ | 1294 | KUNIT_INIT_PTR_NOT_ERR_STRUCT(assert_type, \ |
| 1298 | assert_type, \ | ||
| 1299 | #ptr, \ | 1295 | #ptr, \ |
| 1300 | __ptr), \ | 1296 | __ptr), \ |
| 1301 | fmt, \ | 1297 | fmt, \ |