diff options
author | Matthew Wilcox <willy@infradead.org> | 2018-09-09 01:52:17 -0400 |
---|---|---|
committer | Matthew Wilcox <willy@infradead.org> | 2018-10-21 10:46:46 -0400 |
commit | 4f06d6302da682157890f72c0573e12a73536814 (patch) | |
tree | ad61fcd160cb757cf34f173f596c927885742af3 /lib/test_xarray.c | |
parent | 93eb07f72c8d86f8fe5e90907df1cc037f6ffbb7 (diff) |
xarray: Move multiorder_check to in-kernel tests
This version is a little less thorough in order to be a little quicker,
but tests the important edge cases. Also test adding a multiorder entry
at a non-canonical index, and erasing it.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r-- | lib/test_xarray.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index ff94b54a926d..0f06a93b4d0e 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
@@ -422,6 +422,43 @@ static noinline void check_xas_erase(struct xarray *xa) | |||
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | #ifdef CONFIG_XARRAY_MULTI | ||
426 | static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, | ||
427 | unsigned int order) | ||
428 | { | ||
429 | XA_STATE(xas, xa, index); | ||
430 | unsigned long min = index & ~((1UL << order) - 1); | ||
431 | unsigned long max = min + (1UL << order); | ||
432 | |||
433 | xa_store_order(xa, index, order, xa_mk_value(index), GFP_KERNEL); | ||
434 | XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(index)); | ||
435 | XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(index)); | ||
436 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); | ||
437 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); | ||
438 | |||
439 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(min)) != xa_mk_value(index)); | ||
440 | XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(min)); | ||
441 | XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(min)); | ||
442 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); | ||
443 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); | ||
444 | |||
445 | xa_erase_index(xa, min); | ||
446 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
447 | } | ||
448 | |||
449 | static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, | ||
450 | unsigned int order) | ||
451 | { | ||
452 | XA_STATE(xas, xa, index); | ||
453 | xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); | ||
454 | |||
455 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(1)) != xa_mk_value(0)); | ||
456 | XA_BUG_ON(xa, xas.xa_index != index); | ||
457 | XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1)); | ||
458 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
459 | } | ||
460 | #endif | ||
461 | |||
425 | static noinline void check_multi_store(struct xarray *xa) | 462 | static noinline void check_multi_store(struct xarray *xa) |
426 | { | 463 | { |
427 | #ifdef CONFIG_XARRAY_MULTI | 464 | #ifdef CONFIG_XARRAY_MULTI |
@@ -487,6 +524,13 @@ static noinline void check_multi_store(struct xarray *xa) | |||
487 | XA_BUG_ON(xa, !xa_empty(xa)); | 524 | XA_BUG_ON(xa, !xa_empty(xa)); |
488 | } | 525 | } |
489 | } | 526 | } |
527 | |||
528 | for (i = 0; i < 20; i++) { | ||
529 | check_multi_store_1(xa, 200, i); | ||
530 | check_multi_store_1(xa, 0, i); | ||
531 | check_multi_store_1(xa, (1UL << i) + 1, i); | ||
532 | } | ||
533 | check_multi_store_2(xa, 4095, 9); | ||
490 | #endif | 534 | #endif |
491 | } | 535 | } |
492 | 536 | ||