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