Minimally rewrite the XArray unit tests to use kunit. This integrates nicely with existing kunit tools which produce nicer human-readable output compared to the existing machinery. Running the xarray tests before this change requires an obscure invocation ``` tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 \ --kconfig_add CONFIG_TEST_XARRAY=y --raw_output=all nothing ``` which on failure produces ``` BUG at check_reserve:513 ... XArray: 6782340 of 6782364 tests passed ``` and exits 0. Running the xarray tests after this change requires a simpler invocation ``` tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 \ xarray ``` which on failure produces (colors omitted) ``` [09:50:53] ====================== check_reserve ====================== [09:50:53] [FAILED] param-0 [09:50:53] # check_reserve: EXPECTATION FAILED at lib/test_xarray.c:536 [09:50:53] xa_erase(xa, 12345678) != NULL ... [09:50:53] # module: test_xarray [09:50:53] # xarray: pass:26 fail:3 skip:0 total:29 [09:50:53] # Totals: pass:28 fail:3 skip:0 total:31 [09:50:53] ===================== [FAILED] xarray ====================== ``` and exits 1. Use of richer kunit assertions is intentionally omitted to reduce the scope of the change. [akpm@linux-foundation.org: fix cocci warning] Link: https://lore.kernel.org/oe-kbuild-all/202412081700.YXB3vBbg-lkp@intel.com/ Link: https://lkml.kernel.org/r/20241205-xarray-kunit-port-v1-1-ee44bc7aa201@gmail.com Signed-off-by: Tamir Duberstein <tamird@gmail.com> Cc: Bill Wendling <morbo@google.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Justin Stitt <justinstitt@google.com> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Nathan Chancellor <nathan@kernel.org> Cc: Naveen N Rao <naveen@kernel.org> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Showing the changes to lib/test_xarray.c (1 of 16 files). Show all
Unified · Split
| @@ -6,11 +6,10 @@ · 5 unmodified lines | ||
| 6 | 6 | * Author: Matthew Wilcox <willy@infradead.org> |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | −#include <linux/xarray.h> | |
| 10 | −#include <linux/module.h> | |
| 9 | +#include <kunit/test.h> | |
| 11 | 10 | |
| 12 | −static unsigned int tests_run; | |
| 13 | −static unsigned int tests_passed; | |
| 11 | +#include <linux/module.h> | |
| 12 | +#include <linux/xarray.h> | |
| 14 | 13 | |
| 15 | 14 | static const unsigned int order_limit = |
| 16 | 15 | IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1; |
| @@ -20,15 +19,12 @@ static const unsigned int order_limit = · 3 unmodified lines | ||
| 20 | 19 | void xa_dump(const struct xarray *xa) { } |
| 21 | 20 | # endif |
| 22 | 21 | #undef XA_BUG_ON |
| 23 | −#define XA_BUG_ON(xa, x) do { \ | |
| 24 | − tests_run++; \ | |
| 25 | − if (x) { \ | |
| 26 | − printk("BUG at %s:%d\n", __func__, __LINE__); \ | |
| 27 | − xa_dump(xa); \ | |
| 28 | − dump_stack(); \ | |
| 29 | − } else { \ | |
| 30 | − tests_passed++; \ | |
| 31 | − } \ | |
| 22 | +#define XA_BUG_ON(xa, x) do { \ | |
| 23 | + if (x) { \ | |
| 24 | + KUNIT_FAIL(test, #x); \ | |
| 25 | + xa_dump(xa); \ | |
| 26 | + dump_stack(); \ | |
| 27 | + } \ | |
| 32 | 28 | } while (0) |
| 33 | 29 | #endif |
| 34 | 30 | |
| @@ -42,13 +38,13 @@ static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) · 7 unmodified lines | ||
| 42 | 38 | return xa_store(xa, index, xa_mk_index(index), gfp); |
| 43 | 39 | } |
| 44 | 40 | |
| 45 | −static void xa_insert_index(struct xarray *xa, unsigned long index) | |
| 41 | +static void xa_insert_index(struct kunit *test, struct xarray *xa, unsigned long index) | |
| 46 | 42 | { |
| 47 | 43 | XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index), |
| 48 | 44 | GFP_KERNEL) != 0); |
| 49 | 45 | } |
| 50 | 46 | |
| 51 | −static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) | |
| 47 | +static void xa_alloc_index(struct kunit *test, struct xarray *xa, unsigned long index, gfp_t gfp) | |
| 52 | 48 | { |
| 53 | 49 | u32 id; |
| 54 | 50 | |
| @@ -57,7 +53,7 @@ static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) · 2 unmodified lines | ||
| 57 | 53 | XA_BUG_ON(xa, id != index); |
| 58 | 54 | } |
| 59 | 55 | |
| 60 | −static void xa_erase_index(struct xarray *xa, unsigned long index) | |
| 56 | +static void xa_erase_index(struct kunit *test, struct xarray *xa, unsigned long index) | |
| 61 | 57 | { |
| 62 | 58 | XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index)); |
| 63 | 59 | XA_BUG_ON(xa, xa_load(xa, index) != NULL); |
| @@ -83,8 +79,15 @@ static void *xa_store_order(struct xarray *xa, unsigned long index, · 19 unmodified lines | ||
| 83 | 79 | return curr; |
| 84 | 80 | } |
| 85 | 81 | |
| 86 | −static noinline void check_xa_err(struct xarray *xa) | |
| 82 | +static inline struct xarray *xa_param(struct kunit *test) | |
| 87 | 83 | { |
| 84 | + return *(struct xarray **)test->param_value; | |
| 85 | +} | |
| 86 | + | |
| 87 | +static noinline void check_xa_err(struct kunit *test) | |
| 88 | +{ | |
| 89 | + struct xarray *xa = xa_param(test); | |
| 90 | + | |
| 88 | 91 | XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0); |
| 89 | 92 | XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0); |
| 90 | 93 | #ifndef __KERNEL__ |
| @@ -99,8 +102,10 @@ static noinline void check_xa_err(struct xarray *xa) · 8 unmodified lines | ||
| 99 | 102 | // XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL); |
| 100 | 103 | } |
| 101 | 104 | |
| 102 | −static noinline void check_xas_retry(struct xarray *xa) | |
| 105 | +static noinline void check_xas_retry(struct kunit *test) | |
| 103 | 106 | { |
| 107 | + struct xarray *xa = xa_param(test); | |
| 108 | + | |
| 104 | 109 | XA_STATE(xas, xa, 0); |
| 105 | 110 | void *entry; |
| 106 | 111 | |
| @@ -109,7 +114,7 @@ static noinline void check_xas_retry(struct xarray *xa) · 2 unmodified lines | ||
| 109 | 114 | |
| 110 | 115 | rcu_read_lock(); |
| 111 | 116 | XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_value(0)); |
| 112 | − xa_erase_index(xa, 1); | |
| 117 | + xa_erase_index(test, xa, 1); | |
| 113 | 118 | XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas))); |
| 114 | 119 | XA_BUG_ON(xa, xas_retry(&xas, NULL)); |
| 115 | 120 | XA_BUG_ON(xa, xas_retry(&xas, xa_mk_value(0))); |
| @@ -140,12 +145,14 @@ static noinline void check_xas_retry(struct xarray *xa) · 24 unmodified lines | ||
| 140 | 145 | } |
| 141 | 146 | xas_unlock(&xas); |
| 142 | 147 | |
| 143 | − xa_erase_index(xa, 0); | |
| 144 | − xa_erase_index(xa, 1); | |
| 148 | + xa_erase_index(test, xa, 0); | |
| 149 | + xa_erase_index(test, xa, 1); | |
| 145 | 150 | } |
| 146 | 151 | |
| 147 | −static noinline void check_xa_load(struct xarray *xa) | |
| 152 | +static noinline void check_xa_load(struct kunit *test) | |
| 148 | 153 | { |
| 154 | + struct xarray *xa = xa_param(test); | |
| 155 | + | |
| 149 | 156 | unsigned long i, j; |
| 150 | 157 | |
| 151 | 158 | for (i = 0; i < 1024; i++) { |
| @@ -167,13 +174,15 @@ static noinline void check_xa_load(struct xarray *xa) · 15 unmodified lines | ||
| 167 | 174 | else |
| 168 | 175 | XA_BUG_ON(xa, entry); |
| 169 | 176 | } |
| 170 | − xa_erase_index(xa, i); | |
| 177 | + xa_erase_index(test, xa, i); | |
| 171 | 178 | } |
| 172 | 179 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 173 | 180 | } |
| 174 | 181 | |
| 175 | −static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) | |
| 182 | +static noinline void check_xa_mark_1(struct kunit *test, unsigned long index) | |
| 176 | 183 | { |
| 184 | + struct xarray *xa = xa_param(test); | |
| 185 | + | |
| 177 | 186 | unsigned int order; |
| 178 | 187 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 8 : 1; |
| 179 | 188 | |
| @@ -193,7 +202,7 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) · 13 unmodified lines | ||
| 193 | 202 | XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1)); |
| 194 | 203 | |
| 195 | 204 | /* Storing NULL clears marks, and they can't be set again */ |
| 196 | − xa_erase_index(xa, index); | |
| 205 | + xa_erase_index(test, xa, index); | |
| 197 | 206 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 198 | 207 | XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); |
| 199 | 208 | xa_set_mark(xa, index, XA_MARK_0); |
| @@ -244,15 +253,17 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) · 44 unmodified lines | ||
| 244 | 253 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0)); |
| 245 | 254 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1)); |
| 246 | 255 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2)); |
| 247 | − xa_erase_index(xa, index); | |
| 248 | − xa_erase_index(xa, next); | |
| 256 | + xa_erase_index(test, xa, index); | |
| 257 | + xa_erase_index(test, xa, next); | |
| 249 | 258 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 250 | 259 | } |
| 251 | 260 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 252 | 261 | } |
| 253 | 262 | |
| 254 | −static noinline void check_xa_mark_2(struct xarray *xa) | |
| 263 | +static noinline void check_xa_mark_2(struct kunit *test) | |
| 255 | 264 | { |
| 265 | + struct xarray *xa = xa_param(test); | |
| 266 | + | |
| 256 | 267 | XA_STATE(xas, xa, 0); |
| 257 | 268 | unsigned long index; |
| 258 | 269 | unsigned int count = 0; |
| @@ -289,9 +300,11 @@ static noinline void check_xa_mark_2(struct xarray *xa) · 30 unmodified lines | ||
| 289 | 300 | xa_destroy(xa); |
| 290 | 301 | } |
| 291 | 302 | |
| 292 | −static noinline void check_xa_mark_3(struct xarray *xa) | |
| 303 | +static noinline void check_xa_mark_3(struct kunit *test) | |
| 293 | 304 | { |
| 294 | 305 | #ifdef CONFIG_XARRAY_MULTI |
| 306 | + struct xarray *xa = xa_param(test); | |
| 307 | + | |
| 295 | 308 | XA_STATE(xas, xa, 0x41); |
| 296 | 309 | void *entry; |
| 297 | 310 | int count = 0; |
| @@ -310,19 +323,21 @@ static noinline void check_xa_mark_3(struct xarray *xa) · 12 unmodified lines | ||
| 310 | 323 | #endif |
| 311 | 324 | } |
| 312 | 325 | |
| 313 | −static noinline void check_xa_mark(struct xarray *xa) | |
| 326 | +static noinline void check_xa_mark(struct kunit *test) | |
| 314 | 327 | { |
| 315 | 328 | unsigned long index; |
| 316 | 329 | |
| 317 | 330 | for (index = 0; index < 16384; index += 4) |
| 318 | − check_xa_mark_1(xa, index); | |
| 331 | + check_xa_mark_1(test, index); | |
| 319 | 332 | |
| 320 | − check_xa_mark_2(xa); | |
| 321 | − check_xa_mark_3(xa); | |
| 333 | + check_xa_mark_2(test); | |
| 334 | + check_xa_mark_3(test); | |
| 322 | 335 | } |
| 323 | 336 | |
| 324 | −static noinline void check_xa_shrink(struct xarray *xa) | |
| 337 | +static noinline void check_xa_shrink(struct kunit *test) | |
| 325 | 338 | { |
| 339 | + struct xarray *xa = xa_param(test); | |
| 340 | + | |
| 326 | 341 | XA_STATE(xas, xa, 1); |
| 327 | 342 | struct xa_node *node; |
| 328 | 343 | unsigned int order; |
| @@ -347,7 +362,7 @@ static noinline void check_xa_shrink(struct xarray *xa) · 18 unmodified lines | ||
| 347 | 362 | XA_BUG_ON(xa, xas_load(&xas) != NULL); |
| 348 | 363 | xas_unlock(&xas); |
| 349 | 364 | XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0)); |
| 350 | − xa_erase_index(xa, 0); | |
| 365 | + xa_erase_index(test, xa, 0); | |
| 351 | 366 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 352 | 367 | |
| 353 | 368 | for (order = 0; order < max_order; order++) { |
| @@ -364,45 +379,49 @@ static noinline void check_xa_shrink(struct xarray *xa) · 10 unmodified lines | ||
| 364 | 379 | XA_BUG_ON(xa, xa_head(xa) == node); |
| 365 | 380 | rcu_read_unlock(); |
| 366 | 381 | XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL); |
| 367 | − xa_erase_index(xa, ULONG_MAX); | |
| 382 | + xa_erase_index(test, xa, ULONG_MAX); | |
| 368 | 383 | XA_BUG_ON(xa, xa->xa_head != node); |
| 369 | − xa_erase_index(xa, 0); | |
| 384 | + xa_erase_index(test, xa, 0); | |
| 370 | 385 | } |
| 371 | 386 | } |
| 372 | 387 | |
| 373 | −static noinline void check_insert(struct xarray *xa) | |
| 388 | +static noinline void check_insert(struct kunit *test) | |
| 374 | 389 | { |
| 390 | + struct xarray *xa = xa_param(test); | |
| 391 | + | |
| 375 | 392 | unsigned long i; |
| 376 | 393 | |
| 377 | 394 | for (i = 0; i < 1024; i++) { |
| 378 | − xa_insert_index(xa, i); | |
| 395 | + xa_insert_index(test, xa, i); | |
| 379 | 396 | XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL); |
| 380 | 397 | XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL); |
| 381 | − xa_erase_index(xa, i); | |
| 398 | + xa_erase_index(test, xa, i); | |
| 382 | 399 | } |
| 383 | 400 | |
| 384 | 401 | for (i = 10; i < BITS_PER_LONG; i++) { |
| 385 | − xa_insert_index(xa, 1UL << i); | |
| 402 | + xa_insert_index(test, xa, 1UL << i); | |
| 386 | 403 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL); |
| 387 | 404 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL); |
| 388 | − xa_erase_index(xa, 1UL << i); | |
| 405 | + xa_erase_index(test, xa, 1UL << i); | |
| 389 | 406 | |
| 390 | − xa_insert_index(xa, (1UL << i) - 1); | |
| 407 | + xa_insert_index(test, xa, (1UL << i) - 1); | |
| 391 | 408 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL); |
| 392 | 409 | XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL); |
| 393 | − xa_erase_index(xa, (1UL << i) - 1); | |
| 410 | + xa_erase_index(test, xa, (1UL << i) - 1); | |
| 394 | 411 | } |
| 395 | 412 | |
| 396 | − xa_insert_index(xa, ~0UL); | |
| 413 | + xa_insert_index(test, xa, ~0UL); | |
| 397 | 414 | XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL); |
| 398 | 415 | XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL); |
| 399 | − xa_erase_index(xa, ~0UL); | |
| 416 | + xa_erase_index(test, xa, ~0UL); | |
| 400 | 417 | |
| 401 | 418 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 402 | 419 | } |
| 403 | 420 | |
| 404 | −static noinline void check_cmpxchg(struct xarray *xa) | |
| 421 | +static noinline void check_cmpxchg(struct kunit *test) | |
| 405 | 422 | { |
| 423 | + struct xarray *xa = xa_param(test); | |
| 424 | + | |
| 406 | 425 | void *FIVE = xa_mk_value(5); |
| 407 | 426 | void *SIX = xa_mk_value(6); |
| 408 | 427 | void *LOTS = xa_mk_value(12345678); |
| @@ -418,14 +437,16 @@ static noinline void check_cmpxchg(struct xarray *xa) · 9 unmodified lines | ||
| 418 | 437 | XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY); |
| 419 | 438 | XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE); |
| 420 | 439 | XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY); |
| 421 | − xa_erase_index(xa, 12345678); | |
| 422 | − xa_erase_index(xa, 5); | |
| 440 | + xa_erase_index(test, xa, 12345678); | |
| 441 | + xa_erase_index(test, xa, 5); | |
| 423 | 442 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 424 | 443 | } |
| 425 | 444 | |
| 426 | −static noinline void check_cmpxchg_order(struct xarray *xa) | |
| 445 | +static noinline void check_cmpxchg_order(struct kunit *test) | |
| 427 | 446 | { |
| 428 | 447 | #ifdef CONFIG_XARRAY_MULTI |
| 448 | + struct xarray *xa = xa_param(test); | |
| 449 | + | |
| 429 | 450 | void *FIVE = xa_mk_value(5); |
| 430 | 451 | unsigned int i, order = 3; |
| 431 | 452 | |
| @@ -476,8 +497,10 @@ static noinline void check_cmpxchg_order(struct xarray *xa) · 44 unmodified lines | ||
| 476 | 497 | #endif |
| 477 | 498 | } |
| 478 | 499 | |
| 479 | −static noinline void check_reserve(struct xarray *xa) | |
| 500 | +static noinline void check_reserve(struct kunit *test) | |
| 480 | 501 | { |
| 502 | + struct xarray *xa = xa_param(test); | |
| 503 | + | |
| 481 | 504 | void *entry; |
| 482 | 505 | unsigned long index; |
| 483 | 506 | int count; |
| @@ -494,7 +517,7 @@ static noinline void check_reserve(struct xarray *xa) · 10 unmodified lines | ||
| 494 | 517 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); |
| 495 | 518 | XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL); |
| 496 | 519 | xa_release(xa, 12345678); |
| 497 | − xa_erase_index(xa, 12345678); | |
| 520 | + xa_erase_index(test, xa, 12345678); | |
| 498 | 521 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 499 | 522 | |
| 500 | 523 | /* cmpxchg sees a reserved entry as ZERO */ |
| @@ -502,7 +525,7 @@ static noinline void check_reserve(struct xarray *xa) · 1 unmodified line | ||
| 502 | 525 | XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY, |
| 503 | 526 | xa_mk_value(12345678), GFP_NOWAIT) != NULL); |
| 504 | 527 | xa_release(xa, 12345678); |
| 505 | − xa_erase_index(xa, 12345678); | |
| 528 | + xa_erase_index(test, xa, 12345678); | |
| 506 | 529 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 507 | 530 | |
| 508 | 531 | /* xa_insert treats it as busy */ |
| @@ -542,8 +565,10 @@ static noinline void check_reserve(struct xarray *xa) · 33 unmodified lines | ||
| 542 | 565 | xa_destroy(xa); |
| 543 | 566 | } |
| 544 | 567 | |
| 545 | −static noinline void check_xas_erase(struct xarray *xa) | |
| 568 | +static noinline void check_xas_erase(struct kunit *test) | |
| 546 | 569 | { |
| 570 | + struct xarray *xa = xa_param(test); | |
| 571 | + | |
| 547 | 572 | XA_STATE(xas, xa, 0); |
| 548 | 573 | void *entry; |
| 549 | 574 | unsigned long i, j; |
| @@ -581,9 +606,11 @@ static noinline void check_xas_erase(struct xarray *xa) · 31 unmodified lines | ||
| 581 | 606 | } |
| 582 | 607 | |
| 583 | 608 | #ifdef CONFIG_XARRAY_MULTI |
| 584 | −static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, | |
| 609 | +static noinline void check_multi_store_1(struct kunit *test, unsigned long index, | |
| 585 | 610 | unsigned int order) |
| 586 | 611 | { |
| 612 | + struct xarray *xa = xa_param(test); | |
| 613 | + | |
| 587 | 614 | XA_STATE(xas, xa, index); |
| 588 | 615 | unsigned long min = index & ~((1UL << order) - 1); |
| 589 | 616 | unsigned long max = min + (1UL << order); |
| @@ -602,13 +629,15 @@ static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, · 12 unmodified lines | ||
| 602 | 629 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); |
| 603 | 630 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); |
| 604 | 631 | |
| 605 | − xa_erase_index(xa, min); | |
| 632 | + xa_erase_index(test, xa, min); | |
| 606 | 633 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 607 | 634 | } |
| 608 | 635 | |
| 609 | −static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, | |
| 636 | +static noinline void check_multi_store_2(struct kunit *test, unsigned long index, | |
| 610 | 637 | unsigned int order) |
| 611 | 638 | { |
| 639 | + struct xarray *xa = xa_param(test); | |
| 640 | + | |
| 612 | 641 | XA_STATE(xas, xa, index); |
| 613 | 642 | xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); |
| 614 | 643 | |
| @@ -620,9 +649,11 @@ static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, · 5 unmodified lines | ||
| 620 | 649 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 621 | 650 | } |
| 622 | 651 | |
| 623 | −static noinline void check_multi_store_3(struct xarray *xa, unsigned long index, | |
| 652 | +static noinline void check_multi_store_3(struct kunit *test, unsigned long index, | |
| 624 | 653 | unsigned int order) |
| 625 | 654 | { |
| 655 | + struct xarray *xa = xa_param(test); | |
| 656 | + | |
| 626 | 657 | XA_STATE(xas, xa, 0); |
| 627 | 658 | void *entry; |
| 628 | 659 | int n = 0; |
| @@ -647,9 +678,11 @@ static noinline void check_multi_store_3(struct xarray *xa, unsigned long index, · 18 unmodified lines | ||
| 647 | 678 | } |
| 648 | 679 | #endif |
| 649 | 680 | |
| 650 | −static noinline void check_multi_store(struct xarray *xa) | |
| 681 | +static noinline void check_multi_store(struct kunit *test) | |
| 651 | 682 | { |
| 652 | 683 | #ifdef CONFIG_XARRAY_MULTI |
| 684 | + struct xarray *xa = xa_param(test); | |
| 685 | + | |
| 653 | 686 | unsigned long i, j, k; |
| 654 | 687 | unsigned int max_order = (sizeof(long) == 4) ? 30 : 60; |
| 655 | 688 | |
| @@ -714,26 +747,28 @@ static noinline void check_multi_store(struct xarray *xa) · 58 unmodified lines | ||
| 714 | 747 | } |
| 715 | 748 | |
| 716 | 749 | for (i = 0; i < 20; i++) { |
| 717 | − check_multi_store_1(xa, 200, i); | |
| 718 | − check_multi_store_1(xa, 0, i); | |
| 719 | − check_multi_store_1(xa, (1UL << i) + 1, i); | |
| 750 | + check_multi_store_1(test, 200, i); | |
| 751 | + check_multi_store_1(test, 0, i); | |
| 752 | + check_multi_store_1(test, (1UL << i) + 1, i); | |
| 720 | 753 | } |
| 721 | − check_multi_store_2(xa, 4095, 9); | |
| 754 | + check_multi_store_2(test, 4095, 9); | |
| 722 | 755 | |
| 723 | 756 | for (i = 1; i < 20; i++) { |
| 724 | − check_multi_store_3(xa, 0, i); | |
| 725 | − check_multi_store_3(xa, 1UL << i, i); | |
| 757 | + check_multi_store_3(test, 0, i); | |
| 758 | + check_multi_store_3(test, 1UL << i, i); | |
| 726 | 759 | } |
| 727 | 760 | #endif |
| 728 | 761 | } |
| 729 | 762 | |
| 730 | 763 | #ifdef CONFIG_XARRAY_MULTI |
| 731 | 764 | /* mimics page cache __filemap_add_folio() */ |
| 732 | −static noinline void check_xa_multi_store_adv_add(struct xarray *xa, | |
| 765 | +static noinline void check_xa_multi_store_adv_add(struct kunit *test, | |
| 733 | 766 | unsigned long index, |
| 734 | 767 | unsigned int order, |
| 735 | 768 | void *p) |
| 736 | 769 | { |
| 770 | + struct xarray *xa = xa_param(test); | |
| 771 | + | |
| 737 | 772 | XA_STATE(xas, xa, index); |
| 738 | 773 | unsigned int nrpages = 1UL << order; |
| 739 | 774 | |
| @@ -761,10 +796,12 @@ static noinline void check_xa_multi_store_adv_add(struct xarray *xa, · 21 unmodified lines | ||
| 761 | 796 | } |
| 762 | 797 | |
| 763 | 798 | /* mimics page_cache_delete() */ |
| 764 | −static noinline void check_xa_multi_store_adv_del_entry(struct xarray *xa, | |
| 799 | +static noinline void check_xa_multi_store_adv_del_entry(struct kunit *test, | |
| 765 | 800 | unsigned long index, |
| 766 | 801 | unsigned int order) |
| 767 | 802 | { |
| 803 | + struct xarray *xa = xa_param(test); | |
| 804 | + | |
| 768 | 805 | XA_STATE(xas, xa, index); |
| 769 | 806 | |
| 770 | 807 | xas_set_order(&xas, index, order); |
| @@ -772,12 +809,14 @@ static noinline void check_xa_multi_store_adv_del_entry(struct xarray *xa, · 1 unmodified line | ||
| 772 | 809 | xas_init_marks(&xas); |
| 773 | 810 | } |
| 774 | 811 | |
| 775 | −static noinline void check_xa_multi_store_adv_delete(struct xarray *xa, | |
| 812 | +static noinline void check_xa_multi_store_adv_delete(struct kunit *test, | |
| 776 | 813 | unsigned long index, |
| 777 | 814 | unsigned int order) |
| 778 | 815 | { |
| 816 | + struct xarray *xa = xa_param(test); | |
| 817 | + | |
| 779 | 818 | xa_lock_irq(xa); |
| 780 | − check_xa_multi_store_adv_del_entry(xa, index, order); | |
| 819 | + check_xa_multi_store_adv_del_entry(test, index, order); | |
| 781 | 820 | xa_unlock_irq(xa); |
| 782 | 821 | } |
| 783 | 822 | |
| @@ -814,10 +853,12 @@ static unsigned long some_val = 0xdeadbeef; · 30 unmodified lines | ||
| 814 | 853 | static unsigned long some_val_2 = 0xdeaddead; |
| 815 | 854 | |
| 816 | 855 | /* mimics the page cache usage */ |
| 817 | −static noinline void check_xa_multi_store_adv(struct xarray *xa, | |
| 856 | +static noinline void check_xa_multi_store_adv(struct kunit *test, | |
| 818 | 857 | unsigned long pos, |
| 819 | 858 | unsigned int order) |
| 820 | 859 | { |
| 860 | + struct xarray *xa = xa_param(test); | |
| 861 | + | |
| 821 | 862 | unsigned int nrpages = 1UL << order; |
| 822 | 863 | unsigned long index, base, next_index, next_next_index; |
| 823 | 864 | unsigned int i; |
| @@ -827,7 +868,7 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 3 unmodified lines | ||
| 827 | 868 | next_index = round_down(base + nrpages, nrpages); |
| 828 | 869 | next_next_index = round_down(next_index + nrpages, nrpages); |
| 829 | 870 | |
| 830 | − check_xa_multi_store_adv_add(xa, base, order, &some_val); | |
| 871 | + check_xa_multi_store_adv_add(test, base, order, &some_val); | |
| 831 | 872 | |
| 832 | 873 | for (i = 0; i < nrpages; i++) |
| 833 | 874 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != &some_val); |
| @@ -835,20 +876,20 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 1 unmodified line | ||
| 835 | 876 | XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL); |
| 836 | 877 | |
| 837 | 878 | /* Use order 0 for the next item */ |
| 838 | − check_xa_multi_store_adv_add(xa, next_index, 0, &some_val_2); | |
| 879 | + check_xa_multi_store_adv_add(test, next_index, 0, &some_val_2); | |
| 839 | 880 | XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2); |
| 840 | 881 | |
| 841 | 882 | /* Remove the next item */ |
| 842 | − check_xa_multi_store_adv_delete(xa, next_index, 0); | |
| 883 | + check_xa_multi_store_adv_delete(test, next_index, 0); | |
| 843 | 884 | |
| 844 | 885 | /* Now use order for a new pointer */ |
| 845 | − check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); | |
| 886 | + check_xa_multi_store_adv_add(test, next_index, order, &some_val_2); | |
| 846 | 887 | |
| 847 | 888 | for (i = 0; i < nrpages; i++) |
| 848 | 889 | XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); |
| 849 | 890 | |
| 850 | − check_xa_multi_store_adv_delete(xa, next_index, order); | |
| 851 | − check_xa_multi_store_adv_delete(xa, base, order); | |
| 891 | + check_xa_multi_store_adv_delete(test, next_index, order); | |
| 892 | + check_xa_multi_store_adv_delete(test, base, order); | |
| 852 | 893 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 853 | 894 | |
| 854 | 895 | /* starting fresh again */ |
| @@ -856,7 +897,7 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 1 unmodified line | ||
| 856 | 897 | /* let's test some holes now */ |
| 857 | 898 | |
| 858 | 899 | /* hole at base and next_next */ |
| 859 | − check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); | |
| 900 | + check_xa_multi_store_adv_add(test, next_index, order, &some_val_2); | |
| 860 | 901 | |
| 861 | 902 | for (i = 0; i < nrpages; i++) |
| 862 | 903 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); |
| @@ -867,12 +908,12 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 4 unmodified lines | ||
| 867 | 908 | for (i = 0; i < nrpages; i++) |
| 868 | 909 | XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL); |
| 869 | 910 | |
| 870 | − check_xa_multi_store_adv_delete(xa, next_index, order); | |
| 911 | + check_xa_multi_store_adv_delete(test, next_index, order); | |
| 871 | 912 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 872 | 913 | |
| 873 | 914 | /* hole at base and next */ |
| 874 | 915 | |
| 875 | − check_xa_multi_store_adv_add(xa, next_next_index, order, &some_val_2); | |
| 916 | + check_xa_multi_store_adv_add(test, next_next_index, order, &some_val_2); | |
| 876 | 917 | |
| 877 | 918 | for (i = 0; i < nrpages; i++) |
| 878 | 919 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); |
| @@ -883,12 +924,12 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 4 unmodified lines | ||
| 883 | 924 | for (i = 0; i < nrpages; i++) |
| 884 | 925 | XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2); |
| 885 | 926 | |
| 886 | − check_xa_multi_store_adv_delete(xa, next_next_index, order); | |
| 927 | + check_xa_multi_store_adv_delete(test, next_next_index, order); | |
| 887 | 928 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 888 | 929 | } |
| 889 | 930 | #endif |
| 890 | 931 | |
| 891 | −static noinline void check_multi_store_advanced(struct xarray *xa) | |
| 932 | +static noinline void check_multi_store_advanced(struct kunit *test) | |
| 892 | 933 | { |
| 893 | 934 | #ifdef CONFIG_XARRAY_MULTI |
| 894 | 935 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| @@ -900,59 +941,59 @@ static noinline void check_multi_store_advanced(struct xarray *xa) · 5 unmodified lines | ||
| 900 | 941 | */ |
| 901 | 942 | for (pos = 7; pos < end; pos = (pos * pos) + 564) { |
| 902 | 943 | for (i = 0; i < max_order; i++) { |
| 903 | − check_xa_multi_store_adv(xa, pos, i); | |
| 904 | − check_xa_multi_store_adv(xa, pos + 157, i); | |
| 944 | + check_xa_multi_store_adv(test, pos, i); | |
| 945 | + check_xa_multi_store_adv(test, pos + 157, i); | |
| 905 | 946 | } |
| 906 | 947 | } |
| 907 | 948 | #endif |
| 908 | 949 | } |
| 909 | 950 | |
| 910 | −static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) | |
| 951 | +static noinline void check_xa_alloc_1(struct kunit *test, struct xarray *xa, unsigned int base) | |
| 911 | 952 | { |
| 912 | 953 | int i; |
| 913 | 954 | u32 id; |
| 914 | 955 | |
| 915 | 956 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 916 | 957 | /* An empty array should assign %base to the first alloc */ |
| 917 | − xa_alloc_index(xa, base, GFP_KERNEL); | |
| 958 | + xa_alloc_index(test, xa, base, GFP_KERNEL); | |
| 918 | 959 | |
| 919 | 960 | /* Erasing it should make the array empty again */ |
| 920 | − xa_erase_index(xa, base); | |
| 961 | + xa_erase_index(test, xa, base); | |
| 921 | 962 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 922 | 963 | |
| 923 | 964 | /* And it should assign %base again */ |
| 924 | − xa_alloc_index(xa, base, GFP_KERNEL); | |
| 965 | + xa_alloc_index(test, xa, base, GFP_KERNEL); | |
| 925 | 966 | |
| 926 | 967 | /* Allocating and then erasing a lot should not lose base */ |
| 927 | 968 | for (i = base + 1; i < 2 * XA_CHUNK_SIZE; i++) |
| 928 | − xa_alloc_index(xa, i, GFP_KERNEL); | |
| 969 | + xa_alloc_index(test, xa, i, GFP_KERNEL); | |
| 929 | 970 | for (i = base; i < 2 * XA_CHUNK_SIZE; i++) |
| 930 | − xa_erase_index(xa, i); | |
| 931 | − xa_alloc_index(xa, base, GFP_KERNEL); | |
| 971 | + xa_erase_index(test, xa, i); | |
| 972 | + xa_alloc_index(test, xa, base, GFP_KERNEL); | |
| 932 | 973 | |
| 933 | 974 | /* Destroying the array should do the same as erasing */ |
| 934 | 975 | xa_destroy(xa); |
| 935 | 976 | |
| 936 | 977 | /* And it should assign %base again */ |
| 937 | − xa_alloc_index(xa, base, GFP_KERNEL); | |
| 978 | + xa_alloc_index(test, xa, base, GFP_KERNEL); | |
| 938 | 979 | |
| 939 | 980 | /* The next assigned ID should be base+1 */ |
| 940 | − xa_alloc_index(xa, base + 1, GFP_KERNEL); | |
| 941 | − xa_erase_index(xa, base + 1); | |
| 981 | + xa_alloc_index(test, xa, base + 1, GFP_KERNEL); | |
| 982 | + xa_erase_index(test, xa, base + 1); | |
| 942 | 983 | |
| 943 | 984 | /* Storing a value should mark it used */ |
| 944 | 985 | xa_store_index(xa, base + 1, GFP_KERNEL); |
| 945 | − xa_alloc_index(xa, base + 2, GFP_KERNEL); | |
| 986 | + xa_alloc_index(test, xa, base + 2, GFP_KERNEL); | |
| 946 | 987 | |
| 947 | 988 | /* If we then erase base, it should be free */ |
| 948 | − xa_erase_index(xa, base); | |
| 949 | − xa_alloc_index(xa, base, GFP_KERNEL); | |
| 989 | + xa_erase_index(test, xa, base); | |
| 990 | + xa_alloc_index(test, xa, base, GFP_KERNEL); | |
| 950 | 991 | |
| 951 | − xa_erase_index(xa, base + 1); | |
| 952 | − xa_erase_index(xa, base + 2); | |
| 992 | + xa_erase_index(test, xa, base + 1); | |
| 993 | + xa_erase_index(test, xa, base + 2); | |
| 953 | 994 | |
| 954 | 995 | for (i = 1; i < 5000; i++) { |
| 955 | − xa_alloc_index(xa, base + i, GFP_KERNEL); | |
| 996 | + xa_alloc_index(test, xa, base + i, GFP_KERNEL); | |
| 956 | 997 | } |
| 957 | 998 | |
| 958 | 999 | xa_destroy(xa); |
| @@ -975,14 +1016,14 @@ static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) · 16 unmodified lines | ||
| 975 | 1016 | |
| 976 | 1017 | XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), |
| 977 | 1018 | GFP_KERNEL) != -EBUSY); |
| 978 | − XA_BUG_ON(xa, xa_store_index(xa, 3, GFP_KERNEL) != 0); | |
| 1019 | + XA_BUG_ON(xa, xa_store_index(xa, 3, GFP_KERNEL) != NULL); | |
| 979 | 1020 | XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), |
| 980 | 1021 | GFP_KERNEL) != -EBUSY); |
| 981 | − xa_erase_index(xa, 3); | |
| 1022 | + xa_erase_index(test, xa, 3); | |
| 982 | 1023 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 983 | 1024 | } |
| 984 | 1025 | |
| 985 | −static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base) | |
| 1026 | +static noinline void check_xa_alloc_2(struct kunit *test, struct xarray *xa, unsigned int base) | |
| 986 | 1027 | { |
| 987 | 1028 | unsigned int i, id; |
| 988 | 1029 | unsigned long index; |
| @@ -1018,7 +1059,7 @@ static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base) · 29 unmodified lines | ||
| 1018 | 1059 | XA_BUG_ON(xa, id != 5); |
| 1019 | 1060 | |
| 1020 | 1061 | xa_for_each(xa, index, entry) { |
| 1021 | − xa_erase_index(xa, index); | |
| 1062 | + xa_erase_index(test, xa, index); | |
| 1022 | 1063 | } |
| 1023 | 1064 | |
| 1024 | 1065 | for (i = base; i < base + 9; i++) { |
| @@ -1033,7 +1074,7 @@ static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base) · 8 unmodified lines | ||
| 1033 | 1074 | xa_destroy(xa); |
| 1034 | 1075 | } |
| 1035 | 1076 | |
| 1036 | −static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) | |
| 1077 | +static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, unsigned int base) | |
| 1037 | 1078 | { |
| 1038 | 1079 | struct xa_limit limit = XA_LIMIT(1, 0x3fff); |
| 1039 | 1080 | u32 next = 0; |
| @@ -1049,8 +1090,8 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) · 9 unmodified lines | ||
| 1049 | 1090 | XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit, |
| 1050 | 1091 | &next, GFP_KERNEL) != 0); |
| 1051 | 1092 | XA_BUG_ON(xa, id != 0x3ffd); |
| 1052 | − xa_erase_index(xa, 0x3ffd); | |
| 1053 | − xa_erase_index(xa, 1); | |
| 1093 | + xa_erase_index(test, xa, 0x3ffd); | |
| 1094 | + xa_erase_index(test, xa, 1); | |
| 1054 | 1095 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1055 | 1096 | |
| 1056 | 1097 | for (i = 0x3ffe; i < 0x4003; i++) { |
| @@ -1065,8 +1106,8 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) · 8 unmodified lines | ||
| 1065 | 1106 | |
| 1066 | 1107 | /* Check wrap-around is handled correctly */ |
| 1067 | 1108 | if (base != 0) |
| 1068 | − xa_erase_index(xa, base); | |
| 1069 | − xa_erase_index(xa, base + 1); | |
| 1109 | + xa_erase_index(test, xa, base); | |
| 1110 | + xa_erase_index(test, xa, base + 1); | |
| 1070 | 1111 | next = UINT_MAX; |
| 1071 | 1112 | XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX), |
| 1072 | 1113 | xa_limit_32b, &next, GFP_KERNEL) != 0); |
| @@ -1079,7 +1120,7 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) · 6 unmodified lines | ||
| 1079 | 1120 | XA_BUG_ON(xa, id != base + 1); |
| 1080 | 1121 | |
| 1081 | 1122 | xa_for_each(xa, index, entry) |
| 1082 | − xa_erase_index(xa, index); | |
| 1123 | + xa_erase_index(test, xa, index); | |
| 1083 | 1124 | |
| 1084 | 1125 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1085 | 1126 | } |
| @@ -1087,19 +1128,21 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) · 1 unmodified line | ||
| 1087 | 1128 | static DEFINE_XARRAY_ALLOC(xa0); |
| 1088 | 1129 | static DEFINE_XARRAY_ALLOC1(xa1); |
| 1089 | 1130 | |
| 1090 | −static noinline void check_xa_alloc(void) | |
| 1131 | +static noinline void check_xa_alloc(struct kunit *test) | |
| 1091 | 1132 | { |
| 1092 | − check_xa_alloc_1(&xa0, 0); | |
| 1093 | − check_xa_alloc_1(&xa1, 1); | |
| 1094 | − check_xa_alloc_2(&xa0, 0); | |
| 1095 | − check_xa_alloc_2(&xa1, 1); | |
| 1096 | − check_xa_alloc_3(&xa0, 0); | |
| 1097 | − check_xa_alloc_3(&xa1, 1); | |
| 1133 | + check_xa_alloc_1(test, &xa0, 0); | |
| 1134 | + check_xa_alloc_1(test, &xa1, 1); | |
| 1135 | + check_xa_alloc_2(test, &xa0, 0); | |
| 1136 | + check_xa_alloc_2(test, &xa1, 1); | |
| 1137 | + check_xa_alloc_3(test, &xa0, 0); | |
| 1138 | + check_xa_alloc_3(test, &xa1, 1); | |
| 1098 | 1139 | } |
| 1099 | 1140 | |
| 1100 | −static noinline void __check_store_iter(struct xarray *xa, unsigned long start, | |
| 1141 | +static noinline void __check_store_iter(struct kunit *test, unsigned long start, | |
| 1101 | 1142 | unsigned int order, unsigned int present) |
| 1102 | 1143 | { |
| 1144 | + struct xarray *xa = xa_param(test); | |
| 1145 | + | |
| 1103 | 1146 | XA_STATE_ORDER(xas, xa, start, order); |
| 1104 | 1147 | void *entry; |
| 1105 | 1148 | unsigned int count = 0; |
| @@ -1123,50 +1166,54 @@ retry: · 17 unmodified lines | ||
| 1123 | 1166 | XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start)); |
| 1124 | 1167 | XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) != |
| 1125 | 1168 | xa_mk_index(start)); |
| 1126 | − xa_erase_index(xa, start); | |
| 1169 | + xa_erase_index(test, xa, start); | |
| 1127 | 1170 | } |
| 1128 | 1171 | |
| 1129 | −static noinline void check_store_iter(struct xarray *xa) | |
| 1172 | +static noinline void check_store_iter(struct kunit *test) | |
| 1130 | 1173 | { |
| 1174 | + struct xarray *xa = xa_param(test); | |
| 1175 | + | |
| 1131 | 1176 | unsigned int i, j; |
| 1132 | 1177 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| 1133 | 1178 | |
| 1134 | 1179 | for (i = 0; i < max_order; i++) { |
| 1135 | 1180 | unsigned int min = 1 << i; |
| 1136 | 1181 | unsigned int max = (2 << i) - 1; |
| 1137 | − __check_store_iter(xa, 0, i, 0); | |
| 1182 | + __check_store_iter(test, 0, i, 0); | |
| 1138 | 1183 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1139 | − __check_store_iter(xa, min, i, 0); | |
| 1184 | + __check_store_iter(test, min, i, 0); | |
| 1140 | 1185 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1141 | 1186 | |
| 1142 | 1187 | xa_store_index(xa, min, GFP_KERNEL); |
| 1143 | − __check_store_iter(xa, min, i, 1); | |
| 1188 | + __check_store_iter(test, min, i, 1); | |
| 1144 | 1189 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1145 | 1190 | xa_store_index(xa, max, GFP_KERNEL); |
| 1146 | − __check_store_iter(xa, min, i, 1); | |
| 1191 | + __check_store_iter(test, min, i, 1); | |
| 1147 | 1192 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1148 | 1193 | |
| 1149 | 1194 | for (j = 0; j < min; j++) |
| 1150 | 1195 | xa_store_index(xa, j, GFP_KERNEL); |
| 1151 | − __check_store_iter(xa, 0, i, min); | |
| 1196 | + __check_store_iter(test, 0, i, min); | |
| 1152 | 1197 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1153 | 1198 | for (j = 0; j < min; j++) |
| 1154 | 1199 | xa_store_index(xa, min + j, GFP_KERNEL); |
| 1155 | − __check_store_iter(xa, min, i, min); | |
| 1200 | + __check_store_iter(test, min, i, min); | |
| 1156 | 1201 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1157 | 1202 | } |
| 1158 | 1203 | #ifdef CONFIG_XARRAY_MULTI |
| 1159 | 1204 | xa_store_index(xa, 63, GFP_KERNEL); |
| 1160 | 1205 | xa_store_index(xa, 65, GFP_KERNEL); |
| 1161 | − __check_store_iter(xa, 64, 2, 1); | |
| 1162 | − xa_erase_index(xa, 63); | |
| 1206 | + __check_store_iter(test, 64, 2, 1); | |
| 1207 | + xa_erase_index(test, xa, 63); | |
| 1163 | 1208 | #endif |
| 1164 | 1209 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1165 | 1210 | } |
| 1166 | 1211 | |
| 1167 | −static noinline void check_multi_find_1(struct xarray *xa, unsigned order) | |
| 1212 | +static noinline void check_multi_find_1(struct kunit *test, unsigned int order) | |
| 1168 | 1213 | { |
| 1169 | 1214 | #ifdef CONFIG_XARRAY_MULTI |
| 1215 | + struct xarray *xa = xa_param(test); | |
| 1216 | + | |
| 1170 | 1217 | unsigned long multi = 3 << order; |
| 1171 | 1218 | unsigned long next = 4 << order; |
| 1172 | 1219 | unsigned long index; |
| @@ -1189,15 +1236,17 @@ static noinline void check_multi_find_1(struct xarray *xa, unsigned order) · 16 unmodified lines | ||
| 1189 | 1236 | XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL); |
| 1190 | 1237 | XA_BUG_ON(xa, index != next); |
| 1191 | 1238 | |
| 1192 | − xa_erase_index(xa, multi); | |
| 1193 | − xa_erase_index(xa, next); | |
| 1194 | − xa_erase_index(xa, next + 1); | |
| 1239 | + xa_erase_index(test, xa, multi); | |
| 1240 | + xa_erase_index(test, xa, next); | |
| 1241 | + xa_erase_index(test, xa, next + 1); | |
| 1195 | 1242 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1196 | 1243 | #endif |
| 1197 | 1244 | } |
| 1198 | 1245 | |
| 1199 | −static noinline void check_multi_find_2(struct xarray *xa) | |
| 1246 | +static noinline void check_multi_find_2(struct kunit *test) | |
| 1200 | 1247 | { |
| 1248 | + struct xarray *xa = xa_param(test); | |
| 1249 | + | |
| 1201 | 1250 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1; |
| 1202 | 1251 | unsigned int i, j; |
| 1203 | 1252 | void *entry; |
| @@ -1211,17 +1260,19 @@ static noinline void check_multi_find_2(struct xarray *xa) · 7 unmodified lines | ||
| 1211 | 1260 | GFP_KERNEL); |
| 1212 | 1261 | rcu_read_lock(); |
| 1213 | 1262 | xas_for_each(&xas, entry, ULONG_MAX) { |
| 1214 | − xa_erase_index(xa, index); | |
| 1263 | + xa_erase_index(test, xa, index); | |
| 1215 | 1264 | } |
| 1216 | 1265 | rcu_read_unlock(); |
| 1217 | − xa_erase_index(xa, index - 1); | |
| 1266 | + xa_erase_index(test, xa, index - 1); | |
| 1218 | 1267 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1219 | 1268 | } |
| 1220 | 1269 | } |
| 1221 | 1270 | } |
| 1222 | 1271 | |
| 1223 | −static noinline void check_multi_find_3(struct xarray *xa) | |
| 1272 | +static noinline void check_multi_find_3(struct kunit *test) | |
| 1224 | 1273 | { |
| 1274 | + struct xarray *xa = xa_param(test); | |
| 1275 | + | |
| 1225 | 1276 | unsigned int order; |
| 1226 | 1277 | |
| 1227 | 1278 | for (order = 5; order < order_limit; order++) { |
| @@ -1230,12 +1281,14 @@ static noinline void check_multi_find_3(struct xarray *xa) · 2 unmodified lines | ||
| 1230 | 1281 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1231 | 1282 | xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL); |
| 1232 | 1283 | XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT)); |
| 1233 | − xa_erase_index(xa, 0); | |
| 1284 | + xa_erase_index(test, xa, 0); | |
| 1234 | 1285 | } |
| 1235 | 1286 | } |
| 1236 | 1287 | |
| 1237 | −static noinline void check_find_1(struct xarray *xa) | |
| 1288 | +static noinline void check_find_1(struct kunit *test) | |
| 1238 | 1289 | { |
| 1290 | + struct xarray *xa = xa_param(test); | |
| 1291 | + | |
| 1239 | 1292 | unsigned long i, j, k; |
| 1240 | 1293 | |
| 1241 | 1294 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -1272,18 +1325,20 @@ static noinline void check_find_1(struct xarray *xa) · 30 unmodified lines | ||
| 1272 | 1325 | else |
| 1273 | 1326 | XA_BUG_ON(xa, entry != NULL); |
| 1274 | 1327 | } |
| 1275 | − xa_erase_index(xa, j); | |
| 1328 | + xa_erase_index(test, xa, j); | |
| 1276 | 1329 | XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0)); |
| 1277 | 1330 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); |
| 1278 | 1331 | } |
| 1279 | − xa_erase_index(xa, i); | |
| 1332 | + xa_erase_index(test, xa, i); | |
| 1280 | 1333 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0)); |
| 1281 | 1334 | } |
| 1282 | 1335 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1283 | 1336 | } |
| 1284 | 1337 | |
| 1285 | −static noinline void check_find_2(struct xarray *xa) | |
| 1338 | +static noinline void check_find_2(struct kunit *test) | |
| 1286 | 1339 | { |
| 1340 | + struct xarray *xa = xa_param(test); | |
| 1341 | + | |
| 1287 | 1342 | void *entry; |
| 1288 | 1343 | unsigned long i, j, index; |
| 1289 | 1344 | |
| @@ -1303,8 +1358,10 @@ static noinline void check_find_2(struct xarray *xa) · 13 unmodified lines | ||
| 1303 | 1358 | xa_destroy(xa); |
| 1304 | 1359 | } |
| 1305 | 1360 | |
| 1306 | −static noinline void check_find_3(struct xarray *xa) | |
| 1361 | +static noinline void check_find_3(struct kunit *test) | |
| 1307 | 1362 | { |
| 1363 | + struct xarray *xa = xa_param(test); | |
| 1364 | + | |
| 1308 | 1365 | XA_STATE(xas, xa, 0); |
| 1309 | 1366 | unsigned long i, j, k; |
| 1310 | 1367 | void *entry; |
| @@ -1328,8 +1385,10 @@ static noinline void check_find_3(struct xarray *xa) · 17 unmodified lines | ||
| 1328 | 1385 | xa_destroy(xa); |
| 1329 | 1386 | } |
| 1330 | 1387 | |
| 1331 | −static noinline void check_find_4(struct xarray *xa) | |
| 1388 | +static noinline void check_find_4(struct kunit *test) | |
| 1332 | 1389 | { |
| 1390 | + struct xarray *xa = xa_param(test); | |
| 1391 | + | |
| 1333 | 1392 | unsigned long index = 0; |
| 1334 | 1393 | void *entry; |
| 1335 | 1394 | |
| @@ -1341,22 +1400,22 @@ static noinline void check_find_4(struct xarray *xa) · 5 unmodified lines | ||
| 1341 | 1400 | entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT); |
| 1342 | 1401 | XA_BUG_ON(xa, entry); |
| 1343 | 1402 | |
| 1344 | − xa_erase_index(xa, ULONG_MAX); | |
| 1403 | + xa_erase_index(test, xa, ULONG_MAX); | |
| 1345 | 1404 | } |
| 1346 | 1405 | |
| 1347 | −static noinline void check_find(struct xarray *xa) | |
| 1406 | +static noinline void check_find(struct kunit *test) | |
| 1348 | 1407 | { |
| 1349 | 1408 | unsigned i; |
| 1350 | 1409 | |
| 1351 | − check_find_1(xa); | |
| 1352 | − check_find_2(xa); | |
| 1353 | − check_find_3(xa); | |
| 1354 | − check_find_4(xa); | |
| 1410 | + check_find_1(test); | |
| 1411 | + check_find_2(test); | |
| 1412 | + check_find_3(test); | |
| 1413 | + check_find_4(test); | |
| 1355 | 1414 | |
| 1356 | 1415 | for (i = 2; i < 10; i++) |
| 1357 | − check_multi_find_1(xa, i); | |
| 1358 | − check_multi_find_2(xa); | |
| 1359 | − check_multi_find_3(xa); | |
| 1416 | + check_multi_find_1(test, i); | |
| 1417 | + check_multi_find_2(test); | |
| 1418 | + check_multi_find_3(test); | |
| 1360 | 1419 | } |
| 1361 | 1420 | |
| 1362 | 1421 | /* See find_swap_entry() in mm/shmem.c */ |
| @@ -1382,8 +1441,10 @@ static noinline unsigned long xa_find_entry(struct xarray *xa, void *item) · 19 unmodified lines | ||
| 1382 | 1441 | return entry ? xas.xa_index : -1; |
| 1383 | 1442 | } |
| 1384 | 1443 | |
| 1385 | −static noinline void check_find_entry(struct xarray *xa) | |
| 1444 | +static noinline void check_find_entry(struct kunit *test) | |
| 1386 | 1445 | { |
| 1446 | + struct xarray *xa = xa_param(test); | |
| 1447 | + | |
| 1387 | 1448 | #ifdef CONFIG_XARRAY_MULTI |
| 1388 | 1449 | unsigned int order; |
| 1389 | 1450 | unsigned long offset, index; |
| @@ -1410,12 +1471,14 @@ static noinline void check_find_entry(struct xarray *xa) · 20 unmodified lines | ||
| 1410 | 1471 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); |
| 1411 | 1472 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); |
| 1412 | 1473 | XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1); |
| 1413 | − xa_erase_index(xa, ULONG_MAX); | |
| 1474 | + xa_erase_index(test, xa, ULONG_MAX); | |
| 1414 | 1475 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1415 | 1476 | } |
| 1416 | 1477 | |
| 1417 | −static noinline void check_pause(struct xarray *xa) | |
| 1478 | +static noinline void check_pause(struct kunit *test) | |
| 1418 | 1479 | { |
| 1480 | + struct xarray *xa = xa_param(test); | |
| 1481 | + | |
| 1419 | 1482 | XA_STATE(xas, xa, 0); |
| 1420 | 1483 | void *entry; |
| 1421 | 1484 | unsigned int order; |
| @@ -1450,8 +1513,10 @@ static noinline void check_pause(struct xarray *xa) · 28 unmodified lines | ||
| 1450 | 1513 | xa_destroy(xa); |
| 1451 | 1514 | } |
| 1452 | 1515 | |
| 1453 | −static noinline void check_move_tiny(struct xarray *xa) | |
| 1516 | +static noinline void check_move_tiny(struct kunit *test) | |
| 1454 | 1517 | { |
| 1518 | + struct xarray *xa = xa_param(test); | |
| 1519 | + | |
| 1455 | 1520 | XA_STATE(xas, xa, 0); |
| 1456 | 1521 | |
| 1457 | 1522 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -1468,12 +1533,14 @@ static noinline void check_move_tiny(struct xarray *xa) · 10 unmodified lines | ||
| 1468 | 1533 | XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0)); |
| 1469 | 1534 | XA_BUG_ON(xa, xas_prev(&xas) != NULL); |
| 1470 | 1535 | rcu_read_unlock(); |
| 1471 | − xa_erase_index(xa, 0); | |
| 1536 | + xa_erase_index(test, xa, 0); | |
| 1472 | 1537 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1473 | 1538 | } |
| 1474 | 1539 | |
| 1475 | −static noinline void check_move_max(struct xarray *xa) | |
| 1540 | +static noinline void check_move_max(struct kunit *test) | |
| 1476 | 1541 | { |
| 1542 | + struct xarray *xa = xa_param(test); | |
| 1543 | + | |
| 1477 | 1544 | XA_STATE(xas, xa, 0); |
| 1478 | 1545 | |
| 1479 | 1546 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); |
| @@ -1489,12 +1556,14 @@ static noinline void check_move_max(struct xarray *xa) · 9 unmodified lines | ||
| 1489 | 1556 | XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL); |
| 1490 | 1557 | rcu_read_unlock(); |
| 1491 | 1558 | |
| 1492 | − xa_erase_index(xa, ULONG_MAX); | |
| 1559 | + xa_erase_index(test, xa, ULONG_MAX); | |
| 1493 | 1560 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1494 | 1561 | } |
| 1495 | 1562 | |
| 1496 | −static noinline void check_move_small(struct xarray *xa, unsigned long idx) | |
| 1563 | +static noinline void check_move_small(struct kunit *test, unsigned long idx) | |
| 1497 | 1564 | { |
| 1565 | + struct xarray *xa = xa_param(test); | |
| 1566 | + | |
| 1498 | 1567 | XA_STATE(xas, xa, 0); |
| 1499 | 1568 | unsigned long i; |
| 1500 | 1569 | |
| @@ -1536,13 +1605,15 @@ static noinline void check_move_small(struct xarray *xa, unsigned long idx) · 35 unmodified lines | ||
| 1536 | 1605 | XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); |
| 1537 | 1606 | rcu_read_unlock(); |
| 1538 | 1607 | |
| 1539 | − xa_erase_index(xa, 0); | |
| 1540 | − xa_erase_index(xa, idx); | |
| 1608 | + xa_erase_index(test, xa, 0); | |
| 1609 | + xa_erase_index(test, xa, idx); | |
| 1541 | 1610 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1542 | 1611 | } |
| 1543 | 1612 | |
| 1544 | −static noinline void check_move(struct xarray *xa) | |
| 1613 | +static noinline void check_move(struct kunit *test) | |
| 1545 | 1614 | { |
| 1615 | + struct xarray *xa = xa_param(test); | |
| 1616 | + | |
| 1546 | 1617 | XA_STATE(xas, xa, (1 << 16) - 1); |
| 1547 | 1618 | unsigned long i; |
| 1548 | 1619 | |
| @@ -1569,7 +1640,7 @@ static noinline void check_move(struct xarray *xa) · 20 unmodified lines | ||
| 1569 | 1640 | rcu_read_unlock(); |
| 1570 | 1641 | |
| 1571 | 1642 | for (i = (1 << 8); i < (1 << 15); i++) |
| 1572 | − xa_erase_index(xa, i); | |
| 1643 | + xa_erase_index(test, xa, i); | |
| 1573 | 1644 | |
| 1574 | 1645 | i = xas.xa_index; |
| 1575 | 1646 | |
| @@ -1600,17 +1671,17 @@ static noinline void check_move(struct xarray *xa) · 24 unmodified lines | ||
| 1600 | 1671 | |
| 1601 | 1672 | xa_destroy(xa); |
| 1602 | 1673 | |
| 1603 | − check_move_tiny(xa); | |
| 1604 | − check_move_max(xa); | |
| 1674 | + check_move_tiny(test); | |
| 1675 | + check_move_max(test); | |
| 1605 | 1676 | |
| 1606 | 1677 | for (i = 0; i < 16; i++) |
| 1607 | − check_move_small(xa, 1UL << i); | |
| 1678 | + check_move_small(test, 1UL << i); | |
| 1608 | 1679 | |
| 1609 | 1680 | for (i = 2; i < 16; i++) |
| 1610 | − check_move_small(xa, (1UL << i) - 1); | |
| 1681 | + check_move_small(test, (1UL << i) - 1); | |
| 1611 | 1682 | } |
| 1612 | 1683 | |
| 1613 | −static noinline void xa_store_many_order(struct xarray *xa, | |
| 1684 | +static noinline void xa_store_many_order(struct kunit *test, struct xarray *xa, | |
| 1614 | 1685 | unsigned long index, unsigned order) |
| 1615 | 1686 | { |
| 1616 | 1687 | XA_STATE_ORDER(xas, xa, index, order); |
| @@ -1633,30 +1704,34 @@ unlock: · 16 unmodified lines | ||
| 1633 | 1704 | XA_BUG_ON(xa, xas_error(&xas)); |
| 1634 | 1705 | } |
| 1635 | 1706 | |
| 1636 | −static noinline void check_create_range_1(struct xarray *xa, | |
| 1707 | +static noinline void check_create_range_1(struct kunit *test, | |
| 1637 | 1708 | unsigned long index, unsigned order) |
| 1638 | 1709 | { |
| 1710 | + struct xarray *xa = xa_param(test); | |
| 1711 | + | |
| 1639 | 1712 | unsigned long i; |
| 1640 | 1713 | |
| 1641 | − xa_store_many_order(xa, index, order); | |
| 1714 | + xa_store_many_order(test, xa, index, order); | |
| 1642 | 1715 | for (i = index; i < index + (1UL << order); i++) |
| 1643 | − xa_erase_index(xa, i); | |
| 1716 | + xa_erase_index(test, xa, i); | |
| 1644 | 1717 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1645 | 1718 | } |
| 1646 | 1719 | |
| 1647 | −static noinline void check_create_range_2(struct xarray *xa, unsigned order) | |
| 1720 | +static noinline void check_create_range_2(struct kunit *test, unsigned int order) | |
| 1648 | 1721 | { |
| 1722 | + struct xarray *xa = xa_param(test); | |
| 1723 | + | |
| 1649 | 1724 | unsigned long i; |
| 1650 | 1725 | unsigned long nr = 1UL << order; |
| 1651 | 1726 | |
| 1652 | 1727 | for (i = 0; i < nr * nr; i += nr) |
| 1653 | − xa_store_many_order(xa, i, order); | |
| 1728 | + xa_store_many_order(test, xa, i, order); | |
| 1654 | 1729 | for (i = 0; i < nr * nr; i++) |
| 1655 | − xa_erase_index(xa, i); | |
| 1730 | + xa_erase_index(test, xa, i); | |
| 1656 | 1731 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1657 | 1732 | } |
| 1658 | 1733 | |
| 1659 | −static noinline void check_create_range_3(void) | |
| 1734 | +static noinline void check_create_range_3(struct kunit *test) | |
| 1660 | 1735 | { |
| 1661 | 1736 | XA_STATE(xas, NULL, 0); |
| 1662 | 1737 | xas_set_err(&xas, -EEXIST); |
| @@ -1664,9 +1739,11 @@ static noinline void check_create_range_3(void) · 1 unmodified line | ||
| 1664 | 1739 | XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST); |
| 1665 | 1740 | } |
| 1666 | 1741 | |
| 1667 | −static noinline void check_create_range_4(struct xarray *xa, | |
| 1742 | +static noinline void check_create_range_4(struct kunit *test, | |
| 1668 | 1743 | unsigned long index, unsigned order) |
| 1669 | 1744 | { |
| 1745 | + struct xarray *xa = xa_param(test); | |
| 1746 | + | |
| 1670 | 1747 | XA_STATE_ORDER(xas, xa, index, order); |
| 1671 | 1748 | unsigned long base = xas.xa_index; |
| 1672 | 1749 | unsigned long i = 0; |
| @@ -1692,13 +1769,15 @@ unlock: · 19 unmodified lines | ||
| 1692 | 1769 | XA_BUG_ON(xa, xas_error(&xas)); |
| 1693 | 1770 | |
| 1694 | 1771 | for (i = base; i < base + (1UL << order); i++) |
| 1695 | − xa_erase_index(xa, i); | |
| 1772 | + xa_erase_index(test, xa, i); | |
| 1696 | 1773 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1697 | 1774 | } |
| 1698 | 1775 | |
| 1699 | −static noinline void check_create_range_5(struct xarray *xa, | |
| 1776 | +static noinline void check_create_range_5(struct kunit *test, | |
| 1700 | 1777 | unsigned long index, unsigned int order) |
| 1701 | 1778 | { |
| 1779 | + struct xarray *xa = xa_param(test); | |
| 1780 | + | |
| 1702 | 1781 | XA_STATE_ORDER(xas, xa, index, order); |
| 1703 | 1782 | unsigned int i; |
| 1704 | 1783 | |
| @@ -1715,44 +1794,46 @@ static noinline void check_create_range_5(struct xarray *xa, · 10 unmodified lines | ||
| 1715 | 1794 | xa_destroy(xa); |
| 1716 | 1795 | } |
| 1717 | 1796 | |
| 1718 | −static noinline void check_create_range(struct xarray *xa) | |
| 1797 | +static noinline void check_create_range(struct kunit *test) | |
| 1719 | 1798 | { |
| 1720 | 1799 | unsigned int order; |
| 1721 | 1800 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1; |
| 1722 | 1801 | |
| 1723 | 1802 | for (order = 0; order < max_order; order++) { |
| 1724 | − check_create_range_1(xa, 0, order); | |
| 1725 | − check_create_range_1(xa, 1U << order, order); | |
| 1726 | − check_create_range_1(xa, 2U << order, order); | |
| 1727 | − check_create_range_1(xa, 3U << order, order); | |
| 1728 | − check_create_range_1(xa, 1U << 24, order); | |
| 1803 | + check_create_range_1(test, 0, order); | |
| 1804 | + check_create_range_1(test, 1U << order, order); | |
| 1805 | + check_create_range_1(test, 2U << order, order); | |
| 1806 | + check_create_range_1(test, 3U << order, order); | |
| 1807 | + check_create_range_1(test, 1U << 24, order); | |
| 1729 | 1808 | if (order < 10) |
| 1730 | − check_create_range_2(xa, order); | |
| 1731 | − | |
| 1732 | − check_create_range_4(xa, 0, order); | |
| 1733 | − check_create_range_4(xa, 1U << order, order); | |
| 1734 | − check_create_range_4(xa, 2U << order, order); | |
| 1735 | − check_create_range_4(xa, 3U << order, order); | |
| 1736 | − check_create_range_4(xa, 1U << 24, order); | |
| 1737 | − | |
| 1738 | − check_create_range_4(xa, 1, order); | |
| 1739 | − check_create_range_4(xa, (1U << order) + 1, order); | |
| 1740 | − check_create_range_4(xa, (2U << order) + 1, order); | |
| 1741 | − check_create_range_4(xa, (2U << order) - 1, order); | |
| 1742 | − check_create_range_4(xa, (3U << order) + 1, order); | |
| 1743 | − check_create_range_4(xa, (3U << order) - 1, order); | |
| 1744 | − check_create_range_4(xa, (1U << 24) + 1, order); | |
| 1745 | − | |
| 1746 | − check_create_range_5(xa, 0, order); | |
| 1747 | − check_create_range_5(xa, (1U << order), order); | |
| 1809 | + check_create_range_2(test, order); | |
| 1810 | + | |
| 1811 | + check_create_range_4(test, 0, order); | |
| 1812 | + check_create_range_4(test, 1U << order, order); | |
| 1813 | + check_create_range_4(test, 2U << order, order); | |
| 1814 | + check_create_range_4(test, 3U << order, order); | |
| 1815 | + check_create_range_4(test, 1U << 24, order); | |
| 1816 | + | |
| 1817 | + check_create_range_4(test, 1, order); | |
| 1818 | + check_create_range_4(test, (1U << order) + 1, order); | |
| 1819 | + check_create_range_4(test, (2U << order) + 1, order); | |
| 1820 | + check_create_range_4(test, (2U << order) - 1, order); | |
| 1821 | + check_create_range_4(test, (3U << order) + 1, order); | |
| 1822 | + check_create_range_4(test, (3U << order) - 1, order); | |
| 1823 | + check_create_range_4(test, (1U << 24) + 1, order); | |
| 1824 | + | |
| 1825 | + check_create_range_5(test, 0, order); | |
| 1826 | + check_create_range_5(test, (1U << order), order); | |
| 1748 | 1827 | } |
| 1749 | 1828 | |
| 1750 | − check_create_range_3(); | |
| 1829 | + check_create_range_3(test); | |
| 1751 | 1830 | } |
| 1752 | 1831 | |
| 1753 | −static noinline void __check_store_range(struct xarray *xa, unsigned long first, | |
| 1832 | +static noinline void __check_store_range(struct kunit *test, unsigned long first, | |
| 1754 | 1833 | unsigned long last) |
| 1755 | 1834 | { |
| 1835 | + struct xarray *xa = xa_param(test); | |
| 1836 | + | |
| 1756 | 1837 | #ifdef CONFIG_XARRAY_MULTI |
| 1757 | 1838 | xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL); |
| 1758 | 1839 | |
| @@ -1767,26 +1848,28 @@ static noinline void __check_store_range(struct xarray *xa, unsigned long first, · 8 unmodified lines | ||
| 1767 | 1848 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1768 | 1849 | } |
| 1769 | 1850 | |
| 1770 | −static noinline void check_store_range(struct xarray *xa) | |
| 1851 | +static noinline void check_store_range(struct kunit *test) | |
| 1771 | 1852 | { |
| 1772 | 1853 | unsigned long i, j; |
| 1773 | 1854 | |
| 1774 | 1855 | for (i = 0; i < 128; i++) { |
| 1775 | 1856 | for (j = i; j < 128; j++) { |
| 1776 | − __check_store_range(xa, i, j); | |
| 1777 | − __check_store_range(xa, 128 + i, 128 + j); | |
| 1778 | − __check_store_range(xa, 4095 + i, 4095 + j); | |
| 1779 | − __check_store_range(xa, 4096 + i, 4096 + j); | |
| 1780 | − __check_store_range(xa, 123456 + i, 123456 + j); | |
| 1781 | − __check_store_range(xa, (1 << 24) + i, (1 << 24) + j); | |
| 1857 | + __check_store_range(test, i, j); | |
| 1858 | + __check_store_range(test, 128 + i, 128 + j); | |
| 1859 | + __check_store_range(test, 4095 + i, 4095 + j); | |
| 1860 | + __check_store_range(test, 4096 + i, 4096 + j); | |
| 1861 | + __check_store_range(test, 123456 + i, 123456 + j); | |
| 1862 | + __check_store_range(test, (1 << 24) + i, (1 << 24) + j); | |
| 1782 | 1863 | } |
| 1783 | 1864 | } |
| 1784 | 1865 | } |
| 1785 | 1866 | |
| 1786 | 1867 | #ifdef CONFIG_XARRAY_MULTI |
| 1787 | −static void check_split_1(struct xarray *xa, unsigned long index, | |
| 1868 | +static void check_split_1(struct kunit *test, unsigned long index, | |
| 1788 | 1869 | unsigned int order, unsigned int new_order) |
| 1789 | 1870 | { |
| 1871 | + struct xarray *xa = xa_param(test); | |
| 1872 | + | |
| 1790 | 1873 | XA_STATE_ORDER(xas, xa, index, new_order); |
| 1791 | 1874 | unsigned int i, found; |
| 1792 | 1875 | void *entry; |
| @@ -1822,26 +1905,30 @@ static void check_split_1(struct xarray *xa, unsigned long index, · 29 unmodified lines | ||
| 1822 | 1905 | xa_destroy(xa); |
| 1823 | 1906 | } |
| 1824 | 1907 | |
| 1825 | −static noinline void check_split(struct xarray *xa) | |
| 1908 | +static noinline void check_split(struct kunit *test) | |
| 1826 | 1909 | { |
| 1910 | + struct xarray *xa = xa_param(test); | |
| 1911 | + | |
| 1827 | 1912 | unsigned int order, new_order; |
| 1828 | 1913 | |
| 1829 | 1914 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1830 | 1915 | |
| 1831 | 1916 | for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) { |
| 1832 | 1917 | for (new_order = 0; new_order < order; new_order++) { |
| 1833 | − check_split_1(xa, 0, order, new_order); | |
| 1834 | − check_split_1(xa, 1UL << order, order, new_order); | |
| 1835 | − check_split_1(xa, 3UL << order, order, new_order); | |
| 1918 | + check_split_1(test, 0, order, new_order); | |
| 1919 | + check_split_1(test, 1UL << order, order, new_order); | |
| 1920 | + check_split_1(test, 3UL << order, order, new_order); | |
| 1836 | 1921 | } |
| 1837 | 1922 | } |
| 1838 | 1923 | } |
| 1839 | 1924 | #else |
| 1840 | −static void check_split(struct xarray *xa) { } | |
| 1925 | +static void check_split(struct kunit *test) { } | |
| 1841 | 1926 | #endif |
| 1842 | 1927 | |
| 1843 | −static void check_align_1(struct xarray *xa, char *name) | |
| 1928 | +static void check_align_1(struct kunit *test, char *name) | |
| 1844 | 1929 | { |
| 1930 | + struct xarray *xa = xa_param(test); | |
| 1931 | + | |
| 1845 | 1932 | int i; |
| 1846 | 1933 | unsigned int id; |
| 1847 | 1934 | unsigned long index; |
| @@ -1861,8 +1948,10 @@ static void check_align_1(struct xarray *xa, char *name) · 13 unmodified lines | ||
| 1861 | 1948 | * We should always be able to store without allocating memory after |
| 1862 | 1949 | * reserving a slot. |
| 1863 | 1950 | */ |
| 1864 | −static void check_align_2(struct xarray *xa, char *name) | |
| 1951 | +static void check_align_2(struct kunit *test, char *name) | |
| 1865 | 1952 | { |
| 1953 | + struct xarray *xa = xa_param(test); | |
| 1954 | + | |
| 1866 | 1955 | int i; |
| 1867 | 1956 | |
| 1868 | 1957 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -1881,15 +1970,15 @@ static void check_align_2(struct xarray *xa, char *name) · 12 unmodified lines | ||
| 1881 | 1970 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1882 | 1971 | } |
| 1883 | 1972 | |
| 1884 | −static noinline void check_align(struct xarray *xa) | |
| 1973 | +static noinline void check_align(struct kunit *test) | |
| 1885 | 1974 | { |
| 1886 | 1975 | char name[] = "Motorola 68000"; |
| 1887 | 1976 | |
| 1888 | − check_align_1(xa, name); | |
| 1889 | − check_align_1(xa, name + 1); | |
| 1890 | − check_align_1(xa, name + 2); | |
| 1891 | − check_align_1(xa, name + 3); | |
| 1892 | − check_align_2(xa, name); | |
| 1977 | + check_align_1(test, name); | |
| 1978 | + check_align_1(test, name + 1); | |
| 1979 | + check_align_1(test, name + 2); | |
| 1980 | + check_align_1(test, name + 3); | |
| 1981 | + check_align_2(test, name); | |
| 1893 | 1982 | } |
| 1894 | 1983 | |
| 1895 | 1984 | static LIST_HEAD(shadow_nodes); |
| @@ -1905,7 +1994,7 @@ static void test_update_node(struct xa_node *node) · 9 unmodified lines | ||
| 1905 | 1994 | } |
| 1906 | 1995 | } |
| 1907 | 1996 | |
| 1908 | −static noinline void shadow_remove(struct xarray *xa) | |
| 1997 | +static noinline void shadow_remove(struct kunit *test, struct xarray *xa) | |
| 1909 | 1998 | { |
| 1910 | 1999 | struct xa_node *node; |
| 1911 | 2000 | |
| @@ -1919,8 +2008,17 @@ static noinline void shadow_remove(struct xarray *xa) · 7 unmodified lines | ||
| 1919 | 2008 | xa_unlock(xa); |
| 1920 | 2009 | } |
| 1921 | 2010 | |
| 1922 | −static noinline void check_workingset(struct xarray *xa, unsigned long index) | |
| 2011 | +struct workingset_testcase { | |
| 2012 | + struct xarray *xa; | |
| 2013 | + unsigned long index; | |
| 2014 | +}; | |
| 2015 | + | |
| 2016 | +static noinline void check_workingset(struct kunit *test) | |
| 1923 | 2017 | { |
| 2018 | + struct workingset_testcase tc = *(struct workingset_testcase *)test->param_value; | |
| 2019 | + struct xarray *xa = tc.xa; | |
| 2020 | + unsigned long index = tc.index; | |
| 2021 | + | |
| 1924 | 2022 | XA_STATE(xas, xa, index); |
| 1925 | 2023 | xas_set_update(&xas, test_update_node); |
| 1926 | 2024 | |
| @@ -1943,7 +2041,7 @@ static noinline void check_workingset(struct xarray *xa, unsigned long index) · 16 unmodified lines | ||
| 1943 | 2041 | xas_unlock(&xas); |
| 1944 | 2042 | XA_BUG_ON(xa, list_empty(&shadow_nodes)); |
| 1945 | 2043 | |
| 1946 | − shadow_remove(xa); | |
| 2044 | + shadow_remove(test, xa); | |
| 1947 | 2045 | XA_BUG_ON(xa, !list_empty(&shadow_nodes)); |
| 1948 | 2046 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1949 | 2047 | } |
| @@ -1952,9 +2050,11 @@ static noinline void check_workingset(struct xarray *xa, unsigned long index) · 2 unmodified lines | ||
| 1952 | 2050 | * Check that the pointer / value / sibling entries are accounted the |
| 1953 | 2051 | * way we expect them to be. |
| 1954 | 2052 | */ |
| 1955 | −static noinline void check_account(struct xarray *xa) | |
| 2053 | +static noinline void check_account(struct kunit *test) | |
| 1956 | 2054 | { |
| 1957 | 2055 | #ifdef CONFIG_XARRAY_MULTI |
| 2056 | + struct xarray *xa = xa_param(test); | |
| 2057 | + | |
| 1958 | 2058 | unsigned int order; |
| 1959 | 2059 | |
| 1960 | 2060 | for (order = 1; order < 12; order++) { |
| @@ -1981,8 +2081,10 @@ static noinline void check_account(struct xarray *xa) · 20 unmodified lines | ||
| 1981 | 2081 | #endif |
| 1982 | 2082 | } |
| 1983 | 2083 | |
| 1984 | −static noinline void check_get_order(struct xarray *xa) | |
| 2084 | +static noinline void check_get_order(struct kunit *test) | |
| 1985 | 2085 | { |
| 2086 | + struct xarray *xa = xa_param(test); | |
| 2087 | + | |
| 1986 | 2088 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| 1987 | 2089 | unsigned int order; |
| 1988 | 2090 | unsigned long i, j; |
| @@ -2001,8 +2103,10 @@ static noinline void check_get_order(struct xarray *xa) · 12 unmodified lines | ||
| 2001 | 2103 | } |
| 2002 | 2104 | } |
| 2003 | 2105 | |
| 2004 | −static noinline void check_xas_get_order(struct xarray *xa) | |
| 2106 | +static noinline void check_xas_get_order(struct kunit *test) | |
| 2005 | 2107 | { |
| 2108 | + struct xarray *xa = xa_param(test); | |
| 2109 | + | |
| 2006 | 2110 | XA_STATE(xas, xa, 0); |
| 2007 | 2111 | |
| 2008 | 2112 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| @@ -2034,8 +2138,10 @@ static noinline void check_xas_get_order(struct xarray *xa) · 25 unmodified lines | ||
| 2034 | 2138 | } |
| 2035 | 2139 | } |
| 2036 | 2140 | |
| 2037 | −static noinline void check_xas_conflict_get_order(struct xarray *xa) | |
| 2141 | +static noinline void check_xas_conflict_get_order(struct kunit *test) | |
| 2038 | 2142 | { |
| 2143 | + struct xarray *xa = xa_param(test); | |
| 2144 | + | |
| 2039 | 2145 | XA_STATE(xas, xa, 0); |
| 2040 | 2146 | |
| 2041 | 2147 | void *entry; |
| @@ -2092,8 +2198,10 @@ static noinline void check_xas_conflict_get_order(struct xarray *xa) · 50 unmodified lines | ||
| 2092 | 2198 | } |
| 2093 | 2199 | |
| 2094 | 2200 | |
| 2095 | −static noinline void check_destroy(struct xarray *xa) | |
| 2201 | +static noinline void check_destroy(struct kunit *test) | |
| 2096 | 2202 | { |
| 2203 | + struct xarray *xa = xa_param(test); | |
| 2204 | + | |
| 2097 | 2205 | unsigned long index; |
| 2098 | 2206 | |
| 2099 | 2207 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -2126,52 +2234,59 @@ static noinline void check_destroy(struct xarray *xa) · 26 unmodified lines | ||
| 2126 | 2234 | } |
| 2127 | 2235 | |
| 2128 | 2236 | static DEFINE_XARRAY(array); |
| 2237 | +static struct xarray *arrays[] = { &array }; | |
| 2238 | +KUNIT_ARRAY_PARAM(array, arrays, NULL); | |
| 2239 | + | |
| 2240 | +static struct xarray *xa0s[] = { &xa0 }; | |
| 2241 | +KUNIT_ARRAY_PARAM(xa0, xa0s, NULL); | |
| 2242 | + | |
| 2243 | +static struct workingset_testcase workingset_testcases[] = { | |
| 2244 | + { &array, 0 }, | |
| 2245 | + { &array, 64 }, | |
| 2246 | + { &array, 4096 }, | |
| 2247 | +}; | |
| 2248 | +KUNIT_ARRAY_PARAM(workingset, workingset_testcases, NULL); | |
| 2249 | + | |
| 2250 | +static struct kunit_case xarray_cases[] = { | |
| 2251 | + KUNIT_CASE_PARAM(check_xa_err, array_gen_params), | |
| 2252 | + KUNIT_CASE_PARAM(check_xas_retry, array_gen_params), | |
| 2253 | + KUNIT_CASE_PARAM(check_xa_load, array_gen_params), | |
| 2254 | + KUNIT_CASE_PARAM(check_xa_mark, array_gen_params), | |
| 2255 | + KUNIT_CASE_PARAM(check_xa_shrink, array_gen_params), | |
| 2256 | + KUNIT_CASE_PARAM(check_xas_erase, array_gen_params), | |
| 2257 | + KUNIT_CASE_PARAM(check_insert, array_gen_params), | |
| 2258 | + KUNIT_CASE_PARAM(check_cmpxchg, array_gen_params), | |
| 2259 | + KUNIT_CASE_PARAM(check_cmpxchg_order, array_gen_params), | |
| 2260 | + KUNIT_CASE_PARAM(check_reserve, array_gen_params), | |
| 2261 | + KUNIT_CASE_PARAM(check_reserve, xa0_gen_params), | |
| 2262 | + KUNIT_CASE_PARAM(check_multi_store, array_gen_params), | |
| 2263 | + KUNIT_CASE_PARAM(check_multi_store_advanced, array_gen_params), | |
| 2264 | + KUNIT_CASE_PARAM(check_get_order, array_gen_params), | |
| 2265 | + KUNIT_CASE_PARAM(check_xas_get_order, array_gen_params), | |
| 2266 | + KUNIT_CASE_PARAM(check_xas_conflict_get_order, array_gen_params), | |
| 2267 | + KUNIT_CASE(check_xa_alloc), | |
| 2268 | + KUNIT_CASE_PARAM(check_find, array_gen_params), | |
| 2269 | + KUNIT_CASE_PARAM(check_find_entry, array_gen_params), | |
| 2270 | + KUNIT_CASE_PARAM(check_pause, array_gen_params), | |
| 2271 | + KUNIT_CASE_PARAM(check_account, array_gen_params), | |
| 2272 | + KUNIT_CASE_PARAM(check_destroy, array_gen_params), | |
| 2273 | + KUNIT_CASE_PARAM(check_move, array_gen_params), | |
| 2274 | + KUNIT_CASE_PARAM(check_create_range, array_gen_params), | |
| 2275 | + KUNIT_CASE_PARAM(check_store_range, array_gen_params), | |
| 2276 | + KUNIT_CASE_PARAM(check_store_iter, array_gen_params), | |
| 2277 | + KUNIT_CASE_PARAM(check_align, xa0_gen_params), | |
| 2278 | + KUNIT_CASE_PARAM(check_split, array_gen_params), | |
| 2279 | + KUNIT_CASE_PARAM(check_workingset, workingset_gen_params), | |
| 2280 | + {}, | |
| 2281 | +}; | |
| 2282 | + | |
| 2283 | +static struct kunit_suite xarray_suite = { | |
| 2284 | + .name = "xarray", | |
| 2285 | + .test_cases = xarray_cases, | |
| 2286 | +}; | |
| 2287 | + | |
| 2288 | +kunit_test_suite(xarray_suite); | |
| 2129 | 2289 | |
| 2130 | −static int xarray_checks(void) | |
| 2131 | −{ | |
| 2132 | − check_xa_err(&array); | |
| 2133 | − check_xas_retry(&array); | |
| 2134 | − check_xa_load(&array); | |
| 2135 | − check_xa_mark(&array); | |
| 2136 | − check_xa_shrink(&array); | |
| 2137 | − check_xas_erase(&array); | |
| 2138 | − check_insert(&array); | |
| 2139 | − check_cmpxchg(&array); | |
| 2140 | − check_cmpxchg_order(&array); | |
| 2141 | − check_reserve(&array); | |
| 2142 | − check_reserve(&xa0); | |
| 2143 | − check_multi_store(&array); | |
| 2144 | − check_multi_store_advanced(&array); | |
| 2145 | − check_get_order(&array); | |
| 2146 | − check_xas_get_order(&array); | |
| 2147 | − check_xas_conflict_get_order(&array); | |
| 2148 | − check_xa_alloc(); | |
| 2149 | − check_find(&array); | |
| 2150 | − check_find_entry(&array); | |
| 2151 | − check_pause(&array); | |
| 2152 | − check_account(&array); | |
| 2153 | − check_destroy(&array); | |
| 2154 | − check_move(&array); | |
| 2155 | − check_create_range(&array); | |
| 2156 | − check_store_range(&array); | |
| 2157 | − check_store_iter(&array); | |
| 2158 | − check_align(&xa0); | |
| 2159 | − check_split(&array); | |
| 2160 | − | |
| 2161 | − check_workingset(&array, 0); | |
| 2162 | − check_workingset(&array, 64); | |
| 2163 | − check_workingset(&array, 4096); | |
| 2164 | − | |
| 2165 | − printk("XArray: %u of %u tests passed\n", tests_passed, tests_run); | |
| 2166 | − return (tests_run == tests_passed) ? 0 : -EINVAL; | |
| 2167 | −} | |
| 2168 | − | |
| 2169 | −static void xarray_exit(void) | |
| 2170 | −{ | |
| 2171 | −} | |
| 2172 | − | |
| 2173 | −module_init(xarray_checks); | |
| 2174 | −module_exit(xarray_exit); | |
| 2175 | 2290 | MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>"); |
| 2176 | 2291 | MODULE_DESCRIPTION("XArray API test module"); |
| 2177 | 2292 | MODULE_LICENSE("GPL"); |