History

xarray: port tests to kunit

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>

Tamir Duberstein committed 1 year ago

Commit c7bb5cf1 parent 7a77edf16 files · +410 −294Browse files

Showing the changes to lib/test_xarray.c (1 of 16 files). Show all

Unified · Split

lib/test_xarray.c+393−278
@@ -6,11 +6,10 @@ · 5 unmodified lines
66 * Author: Matthew Wilcox <willy@infradead.org>
77 */
88
9−#include <linux/xarray.h>
10−#include <linux/module.h>
9+#include <kunit/test.h>
1110
12−static unsigned int tests_run;
13−static unsigned int tests_passed;
11+#include <linux/module.h>
12+#include <linux/xarray.h>
1413
1514 static const unsigned int order_limit =
1615 IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1;
@@ -20,15 +19,12 @@ static const unsigned int order_limit = · 3 unmodified lines
2019 void xa_dump(const struct xarray *xa) { }
2120 # endif
2221 #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+ } \
3228 } while (0)
3329 #endif
3430
@@ -42,13 +38,13 @@ static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) · 7 unmodified lines
4238 return xa_store(xa, index, xa_mk_index(index), gfp);
4339 }
4440
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)
4642 {
4743 XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index),
4844 GFP_KERNEL) != 0);
4945 }
5046
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)
5248 {
5349 u32 id;
5450
@@ -57,7 +53,7 @@ static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) · 2 unmodified lines
5753 XA_BUG_ON(xa, id != index);
5854 }
5955
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)
6157 {
6258 XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index));
6359 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
8379 return curr;
8480 }
8581
86−static noinline void check_xa_err(struct xarray *xa)
82+static inline struct xarray *xa_param(struct kunit *test)
8783 {
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+
8891 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0);
8992 XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0);
9093 #ifndef __KERNEL__
@@ -99,8 +102,10 @@ static noinline void check_xa_err(struct xarray *xa) · 8 unmodified lines
99102 // XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL);
100103 }
101104
102−static noinline void check_xas_retry(struct xarray *xa)
105+static noinline void check_xas_retry(struct kunit *test)
103106 {
107+ struct xarray *xa = xa_param(test);
108+
104109 XA_STATE(xas, xa, 0);
105110 void *entry;
106111
@@ -109,7 +114,7 @@ static noinline void check_xas_retry(struct xarray *xa) · 2 unmodified lines
109114
110115 rcu_read_lock();
111116 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);
113118 XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas)));
114119 XA_BUG_ON(xa, xas_retry(&xas, NULL));
115120 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
140145 }
141146 xas_unlock(&xas);
142147
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);
145150 }
146151
147−static noinline void check_xa_load(struct xarray *xa)
152+static noinline void check_xa_load(struct kunit *test)
148153 {
154+ struct xarray *xa = xa_param(test);
155+
149156 unsigned long i, j;
150157
151158 for (i = 0; i < 1024; i++) {
@@ -167,13 +174,15 @@ static noinline void check_xa_load(struct xarray *xa) · 15 unmodified lines
167174 else
168175 XA_BUG_ON(xa, entry);
169176 }
170− xa_erase_index(xa, i);
177+ xa_erase_index(test, xa, i);
171178 }
172179 XA_BUG_ON(xa, !xa_empty(xa));
173180 }
174181
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)
176183 {
184+ struct xarray *xa = xa_param(test);
185+
177186 unsigned int order;
178187 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 8 : 1;
179188
@@ -193,7 +202,7 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) · 13 unmodified lines
193202 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1));
194203
195204 /* Storing NULL clears marks, and they can't be set again */
196− xa_erase_index(xa, index);
205+ xa_erase_index(test, xa, index);
197206 XA_BUG_ON(xa, !xa_empty(xa));
198207 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
199208 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
244253 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0));
245254 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1));
246255 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);
249258 XA_BUG_ON(xa, !xa_empty(xa));
250259 }
251260 XA_BUG_ON(xa, !xa_empty(xa));
252261 }
253262
254−static noinline void check_xa_mark_2(struct xarray *xa)
263+static noinline void check_xa_mark_2(struct kunit *test)
255264 {
265+ struct xarray *xa = xa_param(test);
266+
256267 XA_STATE(xas, xa, 0);
257268 unsigned long index;
258269 unsigned int count = 0;
@@ -289,9 +300,11 @@ static noinline void check_xa_mark_2(struct xarray *xa) · 30 unmodified lines
289300 xa_destroy(xa);
290301 }
291302
292−static noinline void check_xa_mark_3(struct xarray *xa)
303+static noinline void check_xa_mark_3(struct kunit *test)
293304 {
294305 #ifdef CONFIG_XARRAY_MULTI
306+ struct xarray *xa = xa_param(test);
307+
295308 XA_STATE(xas, xa, 0x41);
296309 void *entry;
297310 int count = 0;
@@ -310,19 +323,21 @@ static noinline void check_xa_mark_3(struct xarray *xa) · 12 unmodified lines
310323 #endif
311324 }
312325
313−static noinline void check_xa_mark(struct xarray *xa)
326+static noinline void check_xa_mark(struct kunit *test)
314327 {
315328 unsigned long index;
316329
317330 for (index = 0; index < 16384; index += 4)
318− check_xa_mark_1(xa, index);
331+ check_xa_mark_1(test, index);
319332
320− check_xa_mark_2(xa);
321− check_xa_mark_3(xa);
333+ check_xa_mark_2(test);
334+ check_xa_mark_3(test);
322335 }
323336
324−static noinline void check_xa_shrink(struct xarray *xa)
337+static noinline void check_xa_shrink(struct kunit *test)
325338 {
339+ struct xarray *xa = xa_param(test);
340+
326341 XA_STATE(xas, xa, 1);
327342 struct xa_node *node;
328343 unsigned int order;
@@ -347,7 +362,7 @@ static noinline void check_xa_shrink(struct xarray *xa) · 18 unmodified lines
347362 XA_BUG_ON(xa, xas_load(&xas) != NULL);
348363 xas_unlock(&xas);
349364 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);
351366 XA_BUG_ON(xa, !xa_empty(xa));
352367
353368 for (order = 0; order < max_order; order++) {
@@ -364,45 +379,49 @@ static noinline void check_xa_shrink(struct xarray *xa) · 10 unmodified lines
364379 XA_BUG_ON(xa, xa_head(xa) == node);
365380 rcu_read_unlock();
366381 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);
368383 XA_BUG_ON(xa, xa->xa_head != node);
369− xa_erase_index(xa, 0);
384+ xa_erase_index(test, xa, 0);
370385 }
371386 }
372387
373−static noinline void check_insert(struct xarray *xa)
388+static noinline void check_insert(struct kunit *test)
374389 {
390+ struct xarray *xa = xa_param(test);
391+
375392 unsigned long i;
376393
377394 for (i = 0; i < 1024; i++) {
378− xa_insert_index(xa, i);
395+ xa_insert_index(test, xa, i);
379396 XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL);
380397 XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL);
381− xa_erase_index(xa, i);
398+ xa_erase_index(test, xa, i);
382399 }
383400
384401 for (i = 10; i < BITS_PER_LONG; i++) {
385− xa_insert_index(xa, 1UL << i);
402+ xa_insert_index(test, xa, 1UL << i);
386403 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL);
387404 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);
389406
390− xa_insert_index(xa, (1UL << i) - 1);
407+ xa_insert_index(test, xa, (1UL << i) - 1);
391408 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL);
392409 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);
394411 }
395412
396− xa_insert_index(xa, ~0UL);
413+ xa_insert_index(test, xa, ~0UL);
397414 XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL);
398415 XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL);
399− xa_erase_index(xa, ~0UL);
416+ xa_erase_index(test, xa, ~0UL);
400417
401418 XA_BUG_ON(xa, !xa_empty(xa));
402419 }
403420
404−static noinline void check_cmpxchg(struct xarray *xa)
421+static noinline void check_cmpxchg(struct kunit *test)
405422 {
423+ struct xarray *xa = xa_param(test);
424+
406425 void *FIVE = xa_mk_value(5);
407426 void *SIX = xa_mk_value(6);
408427 void *LOTS = xa_mk_value(12345678);
@@ -418,14 +437,16 @@ static noinline void check_cmpxchg(struct xarray *xa) · 9 unmodified lines
418437 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY);
419438 XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE);
420439 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);
423442 XA_BUG_ON(xa, !xa_empty(xa));
424443 }
425444
426−static noinline void check_cmpxchg_order(struct xarray *xa)
445+static noinline void check_cmpxchg_order(struct kunit *test)
427446 {
428447 #ifdef CONFIG_XARRAY_MULTI
448+ struct xarray *xa = xa_param(test);
449+
429450 void *FIVE = xa_mk_value(5);
430451 unsigned int i, order = 3;
431452
@@ -476,8 +497,10 @@ static noinline void check_cmpxchg_order(struct xarray *xa) · 44 unmodified lines
476497 #endif
477498 }
478499
479−static noinline void check_reserve(struct xarray *xa)
500+static noinline void check_reserve(struct kunit *test)
480501 {
502+ struct xarray *xa = xa_param(test);
503+
481504 void *entry;
482505 unsigned long index;
483506 int count;
@@ -494,7 +517,7 @@ static noinline void check_reserve(struct xarray *xa) · 10 unmodified lines
494517 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
495518 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL);
496519 xa_release(xa, 12345678);
497− xa_erase_index(xa, 12345678);
520+ xa_erase_index(test, xa, 12345678);
498521 XA_BUG_ON(xa, !xa_empty(xa));
499522
500523 /* cmpxchg sees a reserved entry as ZERO */
@@ -502,7 +525,7 @@ static noinline void check_reserve(struct xarray *xa) · 1 unmodified line
502525 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY,
503526 xa_mk_value(12345678), GFP_NOWAIT) != NULL);
504527 xa_release(xa, 12345678);
505− xa_erase_index(xa, 12345678);
528+ xa_erase_index(test, xa, 12345678);
506529 XA_BUG_ON(xa, !xa_empty(xa));
507530
508531 /* xa_insert treats it as busy */
@@ -542,8 +565,10 @@ static noinline void check_reserve(struct xarray *xa) · 33 unmodified lines
542565 xa_destroy(xa);
543566 }
544567
545−static noinline void check_xas_erase(struct xarray *xa)
568+static noinline void check_xas_erase(struct kunit *test)
546569 {
570+ struct xarray *xa = xa_param(test);
571+
547572 XA_STATE(xas, xa, 0);
548573 void *entry;
549574 unsigned long i, j;
@@ -581,9 +606,11 @@ static noinline void check_xas_erase(struct xarray *xa) · 31 unmodified lines
581606 }
582607
583608 #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,
585610 unsigned int order)
586611 {
612+ struct xarray *xa = xa_param(test);
613+
587614 XA_STATE(xas, xa, index);
588615 unsigned long min = index & ~((1UL << order) - 1);
589616 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
602629 XA_BUG_ON(xa, xa_load(xa, max) != NULL);
603630 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
604631
605− xa_erase_index(xa, min);
632+ xa_erase_index(test, xa, min);
606633 XA_BUG_ON(xa, !xa_empty(xa));
607634 }
608635
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,
610637 unsigned int order)
611638 {
639+ struct xarray *xa = xa_param(test);
640+
612641 XA_STATE(xas, xa, index);
613642 xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL);
614643
@@ -620,9 +649,11 @@ static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, · 5 unmodified lines
620649 XA_BUG_ON(xa, !xa_empty(xa));
621650 }
622651
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,
624653 unsigned int order)
625654 {
655+ struct xarray *xa = xa_param(test);
656+
626657 XA_STATE(xas, xa, 0);
627658 void *entry;
628659 int n = 0;
@@ -647,9 +678,11 @@ static noinline void check_multi_store_3(struct xarray *xa, unsigned long index, · 18 unmodified lines
647678 }
648679 #endif
649680
650−static noinline void check_multi_store(struct xarray *xa)
681+static noinline void check_multi_store(struct kunit *test)
651682 {
652683 #ifdef CONFIG_XARRAY_MULTI
684+ struct xarray *xa = xa_param(test);
685+
653686 unsigned long i, j, k;
654687 unsigned int max_order = (sizeof(long) == 4) ? 30 : 60;
655688
@@ -714,26 +747,28 @@ static noinline void check_multi_store(struct xarray *xa) · 58 unmodified lines
714747 }
715748
716749 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);
720753 }
721− check_multi_store_2(xa, 4095, 9);
754+ check_multi_store_2(test, 4095, 9);
722755
723756 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);
726759 }
727760 #endif
728761 }
729762
730763 #ifdef CONFIG_XARRAY_MULTI
731764 /* 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,
733766 unsigned long index,
734767 unsigned int order,
735768 void *p)
736769 {
770+ struct xarray *xa = xa_param(test);
771+
737772 XA_STATE(xas, xa, index);
738773 unsigned int nrpages = 1UL << order;
739774
@@ -761,10 +796,12 @@ static noinline void check_xa_multi_store_adv_add(struct xarray *xa, · 21 unmodified lines
761796 }
762797
763798 /* 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,
765800 unsigned long index,
766801 unsigned int order)
767802 {
803+ struct xarray *xa = xa_param(test);
804+
768805 XA_STATE(xas, xa, index);
769806
770807 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
772809 xas_init_marks(&xas);
773810 }
774811
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,
776813 unsigned long index,
777814 unsigned int order)
778815 {
816+ struct xarray *xa = xa_param(test);
817+
779818 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);
781820 xa_unlock_irq(xa);
782821 }
783822
@@ -814,10 +853,12 @@ static unsigned long some_val = 0xdeadbeef; · 30 unmodified lines
814853 static unsigned long some_val_2 = 0xdeaddead;
815854
816855 /* 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,
818857 unsigned long pos,
819858 unsigned int order)
820859 {
860+ struct xarray *xa = xa_param(test);
861+
821862 unsigned int nrpages = 1UL << order;
822863 unsigned long index, base, next_index, next_next_index;
823864 unsigned int i;
@@ -827,7 +868,7 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 3 unmodified lines
827868 next_index = round_down(base + nrpages, nrpages);
828869 next_next_index = round_down(next_index + nrpages, nrpages);
829870
830− check_xa_multi_store_adv_add(xa, base, order, &some_val);
871+ check_xa_multi_store_adv_add(test, base, order, &some_val);
831872
832873 for (i = 0; i < nrpages; i++)
833874 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
835876 XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL);
836877
837878 /* 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);
839880 XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2);
840881
841882 /* 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);
843884
844885 /* 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);
846887
847888 for (i = 0; i < nrpages; i++)
848889 XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2);
849890
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);
852893 XA_BUG_ON(xa, !xa_empty(xa));
853894
854895 /* starting fresh again */
@@ -856,7 +897,7 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 1 unmodified line
856897 /* let's test some holes now */
857898
858899 /* 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);
860901
861902 for (i = 0; i < nrpages; i++)
862903 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
867908 for (i = 0; i < nrpages; i++)
868909 XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL);
869910
870− check_xa_multi_store_adv_delete(xa, next_index, order);
911+ check_xa_multi_store_adv_delete(test, next_index, order);
871912 XA_BUG_ON(xa, !xa_empty(xa));
872913
873914 /* hole at base and next */
874915
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);
876917
877918 for (i = 0; i < nrpages; i++)
878919 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
883924 for (i = 0; i < nrpages; i++)
884925 XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2);
885926
886− check_xa_multi_store_adv_delete(xa, next_next_index, order);
927+ check_xa_multi_store_adv_delete(test, next_next_index, order);
887928 XA_BUG_ON(xa, !xa_empty(xa));
888929 }
889930 #endif
890931
891−static noinline void check_multi_store_advanced(struct xarray *xa)
932+static noinline void check_multi_store_advanced(struct kunit *test)
892933 {
893934 #ifdef CONFIG_XARRAY_MULTI
894935 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
900941 */
901942 for (pos = 7; pos < end; pos = (pos * pos) + 564) {
902943 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);
905946 }
906947 }
907948 #endif
908949 }
909950
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)
911952 {
912953 int i;
913954 u32 id;
914955
915956 XA_BUG_ON(xa, !xa_empty(xa));
916957 /* 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);
918959
919960 /* Erasing it should make the array empty again */
920− xa_erase_index(xa, base);
961+ xa_erase_index(test, xa, base);
921962 XA_BUG_ON(xa, !xa_empty(xa));
922963
923964 /* And it should assign %base again */
924− xa_alloc_index(xa, base, GFP_KERNEL);
965+ xa_alloc_index(test, xa, base, GFP_KERNEL);
925966
926967 /* Allocating and then erasing a lot should not lose base */
927968 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);
929970 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);
932973
933974 /* Destroying the array should do the same as erasing */
934975 xa_destroy(xa);
935976
936977 /* And it should assign %base again */
937− xa_alloc_index(xa, base, GFP_KERNEL);
978+ xa_alloc_index(test, xa, base, GFP_KERNEL);
938979
939980 /* 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);
942983
943984 /* Storing a value should mark it used */
944985 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);
946987
947988 /* 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);
950991
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);
953994
954995 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);
956997 }
957998
958999 xa_destroy(xa);
@@ -975,14 +1016,14 @@ static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) · 16 unmodified lines
9751016
9761017 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),
9771018 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);
9791020 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),
9801021 GFP_KERNEL) != -EBUSY);
981− xa_erase_index(xa, 3);
1022+ xa_erase_index(test, xa, 3);
9821023 XA_BUG_ON(xa, !xa_empty(xa));
9831024 }
9841025
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)
9861027 {
9871028 unsigned int i, id;
9881029 unsigned long index;
@@ -1018,7 +1059,7 @@ static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base) · 29 unmodified lines
10181059 XA_BUG_ON(xa, id != 5);
10191060
10201061 xa_for_each(xa, index, entry) {
1021− xa_erase_index(xa, index);
1062+ xa_erase_index(test, xa, index);
10221063 }
10231064
10241065 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
10331074 xa_destroy(xa);
10341075 }
10351076
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)
10371078 {
10381079 struct xa_limit limit = XA_LIMIT(1, 0x3fff);
10391080 u32 next = 0;
@@ -1049,8 +1090,8 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) · 9 unmodified lines
10491090 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit,
10501091 &next, GFP_KERNEL) != 0);
10511092 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);
10541095 XA_BUG_ON(xa, !xa_empty(xa));
10551096
10561097 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
10651106
10661107 /* Check wrap-around is handled correctly */
10671108 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);
10701111 next = UINT_MAX;
10711112 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX),
10721113 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
10791120 XA_BUG_ON(xa, id != base + 1);
10801121
10811122 xa_for_each(xa, index, entry)
1082− xa_erase_index(xa, index);
1123+ xa_erase_index(test, xa, index);
10831124
10841125 XA_BUG_ON(xa, !xa_empty(xa));
10851126 }
@@ -1087,19 +1128,21 @@ static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) · 1 unmodified line
10871128 static DEFINE_XARRAY_ALLOC(xa0);
10881129 static DEFINE_XARRAY_ALLOC1(xa1);
10891130
1090−static noinline void check_xa_alloc(void)
1131+static noinline void check_xa_alloc(struct kunit *test)
10911132 {
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);
10981139 }
10991140
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,
11011142 unsigned int order, unsigned int present)
11021143 {
1144+ struct xarray *xa = xa_param(test);
1145+
11031146 XA_STATE_ORDER(xas, xa, start, order);
11041147 void *entry;
11051148 unsigned int count = 0;
@@ -1123,50 +1166,54 @@ retry: · 17 unmodified lines
11231166 XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start));
11241167 XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) !=
11251168 xa_mk_index(start));
1126− xa_erase_index(xa, start);
1169+ xa_erase_index(test, xa, start);
11271170 }
11281171
1129−static noinline void check_store_iter(struct xarray *xa)
1172+static noinline void check_store_iter(struct kunit *test)
11301173 {
1174+ struct xarray *xa = xa_param(test);
1175+
11311176 unsigned int i, j;
11321177 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;
11331178
11341179 for (i = 0; i < max_order; i++) {
11351180 unsigned int min = 1 << i;
11361181 unsigned int max = (2 << i) - 1;
1137− __check_store_iter(xa, 0, i, 0);
1182+ __check_store_iter(test, 0, i, 0);
11381183 XA_BUG_ON(xa, !xa_empty(xa));
1139− __check_store_iter(xa, min, i, 0);
1184+ __check_store_iter(test, min, i, 0);
11401185 XA_BUG_ON(xa, !xa_empty(xa));
11411186
11421187 xa_store_index(xa, min, GFP_KERNEL);
1143− __check_store_iter(xa, min, i, 1);
1188+ __check_store_iter(test, min, i, 1);
11441189 XA_BUG_ON(xa, !xa_empty(xa));
11451190 xa_store_index(xa, max, GFP_KERNEL);
1146− __check_store_iter(xa, min, i, 1);
1191+ __check_store_iter(test, min, i, 1);
11471192 XA_BUG_ON(xa, !xa_empty(xa));
11481193
11491194 for (j = 0; j < min; j++)
11501195 xa_store_index(xa, j, GFP_KERNEL);
1151− __check_store_iter(xa, 0, i, min);
1196+ __check_store_iter(test, 0, i, min);
11521197 XA_BUG_ON(xa, !xa_empty(xa));
11531198 for (j = 0; j < min; j++)
11541199 xa_store_index(xa, min + j, GFP_KERNEL);
1155− __check_store_iter(xa, min, i, min);
1200+ __check_store_iter(test, min, i, min);
11561201 XA_BUG_ON(xa, !xa_empty(xa));
11571202 }
11581203 #ifdef CONFIG_XARRAY_MULTI
11591204 xa_store_index(xa, 63, GFP_KERNEL);
11601205 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);
11631208 #endif
11641209 XA_BUG_ON(xa, !xa_empty(xa));
11651210 }
11661211
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)
11681213 {
11691214 #ifdef CONFIG_XARRAY_MULTI
1215+ struct xarray *xa = xa_param(test);
1216+
11701217 unsigned long multi = 3 << order;
11711218 unsigned long next = 4 << order;
11721219 unsigned long index;
@@ -1189,15 +1236,17 @@ static noinline void check_multi_find_1(struct xarray *xa, unsigned order) · 16 unmodified lines
11891236 XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL);
11901237 XA_BUG_ON(xa, index != next);
11911238
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);
11951242 XA_BUG_ON(xa, !xa_empty(xa));
11961243 #endif
11971244 }
11981245
1199−static noinline void check_multi_find_2(struct xarray *xa)
1246+static noinline void check_multi_find_2(struct kunit *test)
12001247 {
1248+ struct xarray *xa = xa_param(test);
1249+
12011250 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1;
12021251 unsigned int i, j;
12031252 void *entry;
@@ -1211,17 +1260,19 @@ static noinline void check_multi_find_2(struct xarray *xa) · 7 unmodified lines
12111260 GFP_KERNEL);
12121261 rcu_read_lock();
12131262 xas_for_each(&xas, entry, ULONG_MAX) {
1214− xa_erase_index(xa, index);
1263+ xa_erase_index(test, xa, index);
12151264 }
12161265 rcu_read_unlock();
1217− xa_erase_index(xa, index - 1);
1266+ xa_erase_index(test, xa, index - 1);
12181267 XA_BUG_ON(xa, !xa_empty(xa));
12191268 }
12201269 }
12211270 }
12221271
1223−static noinline void check_multi_find_3(struct xarray *xa)
1272+static noinline void check_multi_find_3(struct kunit *test)
12241273 {
1274+ struct xarray *xa = xa_param(test);
1275+
12251276 unsigned int order;
12261277
12271278 for (order = 5; order < order_limit; order++) {
@@ -1230,12 +1281,14 @@ static noinline void check_multi_find_3(struct xarray *xa) · 2 unmodified lines
12301281 XA_BUG_ON(xa, !xa_empty(xa));
12311282 xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL);
12321283 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);
12341285 }
12351286 }
12361287
1237−static noinline void check_find_1(struct xarray *xa)
1288+static noinline void check_find_1(struct kunit *test)
12381289 {
1290+ struct xarray *xa = xa_param(test);
1291+
12391292 unsigned long i, j, k;
12401293
12411294 XA_BUG_ON(xa, !xa_empty(xa));
@@ -1272,18 +1325,20 @@ static noinline void check_find_1(struct xarray *xa) · 30 unmodified lines
12721325 else
12731326 XA_BUG_ON(xa, entry != NULL);
12741327 }
1275− xa_erase_index(xa, j);
1328+ xa_erase_index(test, xa, j);
12761329 XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0));
12771330 XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0));
12781331 }
1279− xa_erase_index(xa, i);
1332+ xa_erase_index(test, xa, i);
12801333 XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0));
12811334 }
12821335 XA_BUG_ON(xa, !xa_empty(xa));
12831336 }
12841337
1285−static noinline void check_find_2(struct xarray *xa)
1338+static noinline void check_find_2(struct kunit *test)
12861339 {
1340+ struct xarray *xa = xa_param(test);
1341+
12871342 void *entry;
12881343 unsigned long i, j, index;
12891344
@@ -1303,8 +1358,10 @@ static noinline void check_find_2(struct xarray *xa) · 13 unmodified lines
13031358 xa_destroy(xa);
13041359 }
13051360
1306−static noinline void check_find_3(struct xarray *xa)
1361+static noinline void check_find_3(struct kunit *test)
13071362 {
1363+ struct xarray *xa = xa_param(test);
1364+
13081365 XA_STATE(xas, xa, 0);
13091366 unsigned long i, j, k;
13101367 void *entry;
@@ -1328,8 +1385,10 @@ static noinline void check_find_3(struct xarray *xa) · 17 unmodified lines
13281385 xa_destroy(xa);
13291386 }
13301387
1331−static noinline void check_find_4(struct xarray *xa)
1388+static noinline void check_find_4(struct kunit *test)
13321389 {
1390+ struct xarray *xa = xa_param(test);
1391+
13331392 unsigned long index = 0;
13341393 void *entry;
13351394
@@ -1341,22 +1400,22 @@ static noinline void check_find_4(struct xarray *xa) · 5 unmodified lines
13411400 entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT);
13421401 XA_BUG_ON(xa, entry);
13431402
1344− xa_erase_index(xa, ULONG_MAX);
1403+ xa_erase_index(test, xa, ULONG_MAX);
13451404 }
13461405
1347−static noinline void check_find(struct xarray *xa)
1406+static noinline void check_find(struct kunit *test)
13481407 {
13491408 unsigned i;
13501409
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);
13551414
13561415 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);
13601419 }
13611420
13621421 /* 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
13821441 return entry ? xas.xa_index : -1;
13831442 }
13841443
1385−static noinline void check_find_entry(struct xarray *xa)
1444+static noinline void check_find_entry(struct kunit *test)
13861445 {
1446+ struct xarray *xa = xa_param(test);
1447+
13871448 #ifdef CONFIG_XARRAY_MULTI
13881449 unsigned int order;
13891450 unsigned long offset, index;
@@ -1410,12 +1471,14 @@ static noinline void check_find_entry(struct xarray *xa) · 20 unmodified lines
14101471 xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
14111472 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
14121473 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);
14141475 XA_BUG_ON(xa, !xa_empty(xa));
14151476 }
14161477
1417−static noinline void check_pause(struct xarray *xa)
1478+static noinline void check_pause(struct kunit *test)
14181479 {
1480+ struct xarray *xa = xa_param(test);
1481+
14191482 XA_STATE(xas, xa, 0);
14201483 void *entry;
14211484 unsigned int order;
@@ -1450,8 +1513,10 @@ static noinline void check_pause(struct xarray *xa) · 28 unmodified lines
14501513 xa_destroy(xa);
14511514 }
14521515
1453−static noinline void check_move_tiny(struct xarray *xa)
1516+static noinline void check_move_tiny(struct kunit *test)
14541517 {
1518+ struct xarray *xa = xa_param(test);
1519+
14551520 XA_STATE(xas, xa, 0);
14561521
14571522 XA_BUG_ON(xa, !xa_empty(xa));
@@ -1468,12 +1533,14 @@ static noinline void check_move_tiny(struct xarray *xa) · 10 unmodified lines
14681533 XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0));
14691534 XA_BUG_ON(xa, xas_prev(&xas) != NULL);
14701535 rcu_read_unlock();
1471− xa_erase_index(xa, 0);
1536+ xa_erase_index(test, xa, 0);
14721537 XA_BUG_ON(xa, !xa_empty(xa));
14731538 }
14741539
1475−static noinline void check_move_max(struct xarray *xa)
1540+static noinline void check_move_max(struct kunit *test)
14761541 {
1542+ struct xarray *xa = xa_param(test);
1543+
14771544 XA_STATE(xas, xa, 0);
14781545
14791546 xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
@@ -1489,12 +1556,14 @@ static noinline void check_move_max(struct xarray *xa) · 9 unmodified lines
14891556 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL);
14901557 rcu_read_unlock();
14911558
1492− xa_erase_index(xa, ULONG_MAX);
1559+ xa_erase_index(test, xa, ULONG_MAX);
14931560 XA_BUG_ON(xa, !xa_empty(xa));
14941561 }
14951562
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)
14971564 {
1565+ struct xarray *xa = xa_param(test);
1566+
14981567 XA_STATE(xas, xa, 0);
14991568 unsigned long i;
15001569
@@ -1536,13 +1605,15 @@ static noinline void check_move_small(struct xarray *xa, unsigned long idx) · 35 unmodified lines
15361605 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);
15371606 rcu_read_unlock();
15381607
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);
15411610 XA_BUG_ON(xa, !xa_empty(xa));
15421611 }
15431612
1544−static noinline void check_move(struct xarray *xa)
1613+static noinline void check_move(struct kunit *test)
15451614 {
1615+ struct xarray *xa = xa_param(test);
1616+
15461617 XA_STATE(xas, xa, (1 << 16) - 1);
15471618 unsigned long i;
15481619
@@ -1569,7 +1640,7 @@ static noinline void check_move(struct xarray *xa) · 20 unmodified lines
15691640 rcu_read_unlock();
15701641
15711642 for (i = (1 << 8); i < (1 << 15); i++)
1572− xa_erase_index(xa, i);
1643+ xa_erase_index(test, xa, i);
15731644
15741645 i = xas.xa_index;
15751646
@@ -1600,17 +1671,17 @@ static noinline void check_move(struct xarray *xa) · 24 unmodified lines
16001671
16011672 xa_destroy(xa);
16021673
1603− check_move_tiny(xa);
1604− check_move_max(xa);
1674+ check_move_tiny(test);
1675+ check_move_max(test);
16051676
16061677 for (i = 0; i < 16; i++)
1607− check_move_small(xa, 1UL << i);
1678+ check_move_small(test, 1UL << i);
16081679
16091680 for (i = 2; i < 16; i++)
1610− check_move_small(xa, (1UL << i) - 1);
1681+ check_move_small(test, (1UL << i) - 1);
16111682 }
16121683
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,
16141685 unsigned long index, unsigned order)
16151686 {
16161687 XA_STATE_ORDER(xas, xa, index, order);
@@ -1633,30 +1704,34 @@ unlock: · 16 unmodified lines
16331704 XA_BUG_ON(xa, xas_error(&xas));
16341705 }
16351706
1636−static noinline void check_create_range_1(struct xarray *xa,
1707+static noinline void check_create_range_1(struct kunit *test,
16371708 unsigned long index, unsigned order)
16381709 {
1710+ struct xarray *xa = xa_param(test);
1711+
16391712 unsigned long i;
16401713
1641− xa_store_many_order(xa, index, order);
1714+ xa_store_many_order(test, xa, index, order);
16421715 for (i = index; i < index + (1UL << order); i++)
1643− xa_erase_index(xa, i);
1716+ xa_erase_index(test, xa, i);
16441717 XA_BUG_ON(xa, !xa_empty(xa));
16451718 }
16461719
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)
16481721 {
1722+ struct xarray *xa = xa_param(test);
1723+
16491724 unsigned long i;
16501725 unsigned long nr = 1UL << order;
16511726
16521727 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);
16541729 for (i = 0; i < nr * nr; i++)
1655− xa_erase_index(xa, i);
1730+ xa_erase_index(test, xa, i);
16561731 XA_BUG_ON(xa, !xa_empty(xa));
16571732 }
16581733
1659−static noinline void check_create_range_3(void)
1734+static noinline void check_create_range_3(struct kunit *test)
16601735 {
16611736 XA_STATE(xas, NULL, 0);
16621737 xas_set_err(&xas, -EEXIST);
@@ -1664,9 +1739,11 @@ static noinline void check_create_range_3(void) · 1 unmodified line
16641739 XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST);
16651740 }
16661741
1667−static noinline void check_create_range_4(struct xarray *xa,
1742+static noinline void check_create_range_4(struct kunit *test,
16681743 unsigned long index, unsigned order)
16691744 {
1745+ struct xarray *xa = xa_param(test);
1746+
16701747 XA_STATE_ORDER(xas, xa, index, order);
16711748 unsigned long base = xas.xa_index;
16721749 unsigned long i = 0;
@@ -1692,13 +1769,15 @@ unlock: · 19 unmodified lines
16921769 XA_BUG_ON(xa, xas_error(&xas));
16931770
16941771 for (i = base; i < base + (1UL << order); i++)
1695− xa_erase_index(xa, i);
1772+ xa_erase_index(test, xa, i);
16961773 XA_BUG_ON(xa, !xa_empty(xa));
16971774 }
16981775
1699−static noinline void check_create_range_5(struct xarray *xa,
1776+static noinline void check_create_range_5(struct kunit *test,
17001777 unsigned long index, unsigned int order)
17011778 {
1779+ struct xarray *xa = xa_param(test);
1780+
17021781 XA_STATE_ORDER(xas, xa, index, order);
17031782 unsigned int i;
17041783
@@ -1715,44 +1794,46 @@ static noinline void check_create_range_5(struct xarray *xa, · 10 unmodified lines
17151794 xa_destroy(xa);
17161795 }
17171796
1718−static noinline void check_create_range(struct xarray *xa)
1797+static noinline void check_create_range(struct kunit *test)
17191798 {
17201799 unsigned int order;
17211800 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1;
17221801
17231802 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);
17291808 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);
17481827 }
17491828
1750− check_create_range_3();
1829+ check_create_range_3(test);
17511830 }
17521831
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,
17541833 unsigned long last)
17551834 {
1835+ struct xarray *xa = xa_param(test);
1836+
17561837 #ifdef CONFIG_XARRAY_MULTI
17571838 xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL);
17581839
@@ -1767,26 +1848,28 @@ static noinline void __check_store_range(struct xarray *xa, unsigned long first, · 8 unmodified lines
17671848 XA_BUG_ON(xa, !xa_empty(xa));
17681849 }
17691850
1770−static noinline void check_store_range(struct xarray *xa)
1851+static noinline void check_store_range(struct kunit *test)
17711852 {
17721853 unsigned long i, j;
17731854
17741855 for (i = 0; i < 128; i++) {
17751856 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);
17821863 }
17831864 }
17841865 }
17851866
17861867 #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,
17881869 unsigned int order, unsigned int new_order)
17891870 {
1871+ struct xarray *xa = xa_param(test);
1872+
17901873 XA_STATE_ORDER(xas, xa, index, new_order);
17911874 unsigned int i, found;
17921875 void *entry;
@@ -1822,26 +1905,30 @@ static void check_split_1(struct xarray *xa, unsigned long index, · 29 unmodified lines
18221905 xa_destroy(xa);
18231906 }
18241907
1825−static noinline void check_split(struct xarray *xa)
1908+static noinline void check_split(struct kunit *test)
18261909 {
1910+ struct xarray *xa = xa_param(test);
1911+
18271912 unsigned int order, new_order;
18281913
18291914 XA_BUG_ON(xa, !xa_empty(xa));
18301915
18311916 for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) {
18321917 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);
18361921 }
18371922 }
18381923 }
18391924 #else
1840−static void check_split(struct xarray *xa) { }
1925+static void check_split(struct kunit *test) { }
18411926 #endif
18421927
1843−static void check_align_1(struct xarray *xa, char *name)
1928+static void check_align_1(struct kunit *test, char *name)
18441929 {
1930+ struct xarray *xa = xa_param(test);
1931+
18451932 int i;
18461933 unsigned int id;
18471934 unsigned long index;
@@ -1861,8 +1948,10 @@ static void check_align_1(struct xarray *xa, char *name) · 13 unmodified lines
18611948 * We should always be able to store without allocating memory after
18621949 * reserving a slot.
18631950 */
1864−static void check_align_2(struct xarray *xa, char *name)
1951+static void check_align_2(struct kunit *test, char *name)
18651952 {
1953+ struct xarray *xa = xa_param(test);
1954+
18661955 int i;
18671956
18681957 XA_BUG_ON(xa, !xa_empty(xa));
@@ -1881,15 +1970,15 @@ static void check_align_2(struct xarray *xa, char *name) · 12 unmodified lines
18811970 XA_BUG_ON(xa, !xa_empty(xa));
18821971 }
18831972
1884−static noinline void check_align(struct xarray *xa)
1973+static noinline void check_align(struct kunit *test)
18851974 {
18861975 char name[] = "Motorola 68000";
18871976
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);
18931982 }
18941983
18951984 static LIST_HEAD(shadow_nodes);
@@ -1905,7 +1994,7 @@ static void test_update_node(struct xa_node *node) · 9 unmodified lines
19051994 }
19061995 }
19071996
1908−static noinline void shadow_remove(struct xarray *xa)
1997+static noinline void shadow_remove(struct kunit *test, struct xarray *xa)
19091998 {
19101999 struct xa_node *node;
19112000
@@ -1919,8 +2008,17 @@ static noinline void shadow_remove(struct xarray *xa) · 7 unmodified lines
19192008 xa_unlock(xa);
19202009 }
19212010
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)
19232017 {
2018+ struct workingset_testcase tc = *(struct workingset_testcase *)test->param_value;
2019+ struct xarray *xa = tc.xa;
2020+ unsigned long index = tc.index;
2021+
19242022 XA_STATE(xas, xa, index);
19252023 xas_set_update(&xas, test_update_node);
19262024
@@ -1943,7 +2041,7 @@ static noinline void check_workingset(struct xarray *xa, unsigned long index) · 16 unmodified lines
19432041 xas_unlock(&xas);
19442042 XA_BUG_ON(xa, list_empty(&shadow_nodes));
19452043
1946− shadow_remove(xa);
2044+ shadow_remove(test, xa);
19472045 XA_BUG_ON(xa, !list_empty(&shadow_nodes));
19482046 XA_BUG_ON(xa, !xa_empty(xa));
19492047 }
@@ -1952,9 +2050,11 @@ static noinline void check_workingset(struct xarray *xa, unsigned long index) · 2 unmodified lines
19522050 * Check that the pointer / value / sibling entries are accounted the
19532051 * way we expect them to be.
19542052 */
1955−static noinline void check_account(struct xarray *xa)
2053+static noinline void check_account(struct kunit *test)
19562054 {
19572055 #ifdef CONFIG_XARRAY_MULTI
2056+ struct xarray *xa = xa_param(test);
2057+
19582058 unsigned int order;
19592059
19602060 for (order = 1; order < 12; order++) {
@@ -1981,8 +2081,10 @@ static noinline void check_account(struct xarray *xa) · 20 unmodified lines
19812081 #endif
19822082 }
19832083
1984−static noinline void check_get_order(struct xarray *xa)
2084+static noinline void check_get_order(struct kunit *test)
19852085 {
2086+ struct xarray *xa = xa_param(test);
2087+
19862088 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;
19872089 unsigned int order;
19882090 unsigned long i, j;
@@ -2001,8 +2103,10 @@ static noinline void check_get_order(struct xarray *xa) · 12 unmodified lines
20012103 }
20022104 }
20032105
2004−static noinline void check_xas_get_order(struct xarray *xa)
2106+static noinline void check_xas_get_order(struct kunit *test)
20052107 {
2108+ struct xarray *xa = xa_param(test);
2109+
20062110 XA_STATE(xas, xa, 0);
20072111
20082112 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
20342138 }
20352139 }
20362140
2037−static noinline void check_xas_conflict_get_order(struct xarray *xa)
2141+static noinline void check_xas_conflict_get_order(struct kunit *test)
20382142 {
2143+ struct xarray *xa = xa_param(test);
2144+
20392145 XA_STATE(xas, xa, 0);
20402146
20412147 void *entry;
@@ -2092,8 +2198,10 @@ static noinline void check_xas_conflict_get_order(struct xarray *xa) · 50 unmodified lines
20922198 }
20932199
20942200
2095−static noinline void check_destroy(struct xarray *xa)
2201+static noinline void check_destroy(struct kunit *test)
20962202 {
2203+ struct xarray *xa = xa_param(test);
2204+
20972205 unsigned long index;
20982206
20992207 XA_BUG_ON(xa, !xa_empty(xa));
@@ -2126,52 +2234,59 @@ static noinline void check_destroy(struct xarray *xa) · 26 unmodified lines
21262234 }
21272235
21282236 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);
21292289
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);
21752290 MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
21762291 MODULE_DESCRIPTION("XArray API test module");
21772292 MODULE_LICENSE("GPL");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

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

Repository code

Go to file
t