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

Unified · Split

16 files
  1. arch/m68k/configs/amiga_defconfig +0 −1
  2. arch/m68k/configs/apollo_defconfig +0 −1
  3. arch/m68k/configs/atari_defconfig +0 −1
  4. arch/m68k/configs/bvme6000_defconfig +0 −1
  5. arch/m68k/configs/hp300_defconfig +0 −1
  6. arch/m68k/configs/mac_defconfig +0 −1
  7. arch/m68k/configs/multi_defconfig +0 −1
  8. arch/m68k/configs/mvme147_defconfig +0 −1
  9. arch/m68k/configs/mvme16x_defconfig +0 −1
  10. arch/m68k/configs/q40_defconfig +0 −1
  11. arch/m68k/configs/sun3_defconfig +0 −1
  12. arch/m68k/configs/sun3x_defconfig +0 −1
  13. arch/powerpc/configs/ppc64_defconfig +0 −1
  14. lib/Kconfig.debug +16 −2
  15. lib/Makefile +1 −1
  16. lib/test_xarray.c +393 −278
arch/m68k/configs/amiga_defconfig+0−1
@@ -629,7 +629,6 @@ CONFIG_TEST_PRINTF=m · 628 unmodified lines
629CONFIG_TEST_SCANF=m629CONFIG_TEST_SCANF=m
630CONFIG_TEST_BITMAP=m630CONFIG_TEST_BITMAP=m
631CONFIG_TEST_UUID=m631CONFIG_TEST_UUID=m
632CONFIG_TEST_XARRAY=m
633CONFIG_TEST_MAPLE_TREE=m632CONFIG_TEST_MAPLE_TREE=m
634CONFIG_TEST_RHASHTABLE=m633CONFIG_TEST_RHASHTABLE=m
635CONFIG_TEST_IDA=m634CONFIG_TEST_IDA=m
arch/m68k/configs/apollo_defconfig+0−1
@@ -586,7 +586,6 @@ CONFIG_TEST_PRINTF=m · 585 unmodified lines
586CONFIG_TEST_SCANF=m586CONFIG_TEST_SCANF=m
587CONFIG_TEST_BITMAP=m587CONFIG_TEST_BITMAP=m
588CONFIG_TEST_UUID=m588CONFIG_TEST_UUID=m
589CONFIG_TEST_XARRAY=m
590CONFIG_TEST_MAPLE_TREE=m589CONFIG_TEST_MAPLE_TREE=m
591CONFIG_TEST_RHASHTABLE=m590CONFIG_TEST_RHASHTABLE=m
592CONFIG_TEST_IDA=m591CONFIG_TEST_IDA=m
arch/m68k/configs/atari_defconfig+0−1
@@ -606,7 +606,6 @@ CONFIG_TEST_PRINTF=m · 605 unmodified lines
606CONFIG_TEST_SCANF=m606CONFIG_TEST_SCANF=m
607CONFIG_TEST_BITMAP=m607CONFIG_TEST_BITMAP=m
608CONFIG_TEST_UUID=m608CONFIG_TEST_UUID=m
609CONFIG_TEST_XARRAY=m
610CONFIG_TEST_MAPLE_TREE=m609CONFIG_TEST_MAPLE_TREE=m
611CONFIG_TEST_RHASHTABLE=m610CONFIG_TEST_RHASHTABLE=m
612CONFIG_TEST_IDA=m611CONFIG_TEST_IDA=m
arch/m68k/configs/bvme6000_defconfig+0−1
@@ -578,7 +578,6 @@ CONFIG_TEST_PRINTF=m · 577 unmodified lines
578CONFIG_TEST_SCANF=m578CONFIG_TEST_SCANF=m
579CONFIG_TEST_BITMAP=m579CONFIG_TEST_BITMAP=m
580CONFIG_TEST_UUID=m580CONFIG_TEST_UUID=m
581CONFIG_TEST_XARRAY=m
582CONFIG_TEST_MAPLE_TREE=m581CONFIG_TEST_MAPLE_TREE=m
583CONFIG_TEST_RHASHTABLE=m582CONFIG_TEST_RHASHTABLE=m
584CONFIG_TEST_IDA=m583CONFIG_TEST_IDA=m
arch/m68k/configs/hp300_defconfig+0−1
@@ -588,7 +588,6 @@ CONFIG_TEST_PRINTF=m · 587 unmodified lines
588CONFIG_TEST_SCANF=m588CONFIG_TEST_SCANF=m
589CONFIG_TEST_BITMAP=m589CONFIG_TEST_BITMAP=m
590CONFIG_TEST_UUID=m590CONFIG_TEST_UUID=m
591CONFIG_TEST_XARRAY=m
592CONFIG_TEST_MAPLE_TREE=m591CONFIG_TEST_MAPLE_TREE=m
593CONFIG_TEST_RHASHTABLE=m592CONFIG_TEST_RHASHTABLE=m
594CONFIG_TEST_IDA=m593CONFIG_TEST_IDA=m
arch/m68k/configs/mac_defconfig+0−1
@@ -605,7 +605,6 @@ CONFIG_TEST_PRINTF=m · 604 unmodified lines
605CONFIG_TEST_SCANF=m605CONFIG_TEST_SCANF=m
606CONFIG_TEST_BITMAP=m606CONFIG_TEST_BITMAP=m
607CONFIG_TEST_UUID=m607CONFIG_TEST_UUID=m
608CONFIG_TEST_XARRAY=m
609CONFIG_TEST_MAPLE_TREE=m608CONFIG_TEST_MAPLE_TREE=m
610CONFIG_TEST_RHASHTABLE=m609CONFIG_TEST_RHASHTABLE=m
611CONFIG_TEST_IDA=m610CONFIG_TEST_IDA=m
arch/m68k/configs/multi_defconfig+0−1
@@ -692,7 +692,6 @@ CONFIG_TEST_PRINTF=m · 691 unmodified lines
692CONFIG_TEST_SCANF=m692CONFIG_TEST_SCANF=m
693CONFIG_TEST_BITMAP=m693CONFIG_TEST_BITMAP=m
694CONFIG_TEST_UUID=m694CONFIG_TEST_UUID=m
695CONFIG_TEST_XARRAY=m
696CONFIG_TEST_MAPLE_TREE=m695CONFIG_TEST_MAPLE_TREE=m
697CONFIG_TEST_RHASHTABLE=m696CONFIG_TEST_RHASHTABLE=m
698CONFIG_TEST_IDA=m697CONFIG_TEST_IDA=m
arch/m68k/configs/mvme147_defconfig+0−1
@@ -578,7 +578,6 @@ CONFIG_TEST_PRINTF=m · 577 unmodified lines
578CONFIG_TEST_SCANF=m578CONFIG_TEST_SCANF=m
579CONFIG_TEST_BITMAP=m579CONFIG_TEST_BITMAP=m
580CONFIG_TEST_UUID=m580CONFIG_TEST_UUID=m
581CONFIG_TEST_XARRAY=m
582CONFIG_TEST_MAPLE_TREE=m581CONFIG_TEST_MAPLE_TREE=m
583CONFIG_TEST_RHASHTABLE=m582CONFIG_TEST_RHASHTABLE=m
584CONFIG_TEST_IDA=m583CONFIG_TEST_IDA=m
arch/m68k/configs/mvme16x_defconfig+0−1
@@ -579,7 +579,6 @@ CONFIG_TEST_PRINTF=m · 578 unmodified lines
579CONFIG_TEST_SCANF=m579CONFIG_TEST_SCANF=m
580CONFIG_TEST_BITMAP=m580CONFIG_TEST_BITMAP=m
581CONFIG_TEST_UUID=m581CONFIG_TEST_UUID=m
582CONFIG_TEST_XARRAY=m
583CONFIG_TEST_MAPLE_TREE=m582CONFIG_TEST_MAPLE_TREE=m
584CONFIG_TEST_RHASHTABLE=m583CONFIG_TEST_RHASHTABLE=m
585CONFIG_TEST_IDA=m584CONFIG_TEST_IDA=m
arch/m68k/configs/q40_defconfig+0−1
@@ -595,7 +595,6 @@ CONFIG_TEST_PRINTF=m · 594 unmodified lines
595CONFIG_TEST_SCANF=m595CONFIG_TEST_SCANF=m
596CONFIG_TEST_BITMAP=m596CONFIG_TEST_BITMAP=m
597CONFIG_TEST_UUID=m597CONFIG_TEST_UUID=m
598CONFIG_TEST_XARRAY=m
599CONFIG_TEST_MAPLE_TREE=m598CONFIG_TEST_MAPLE_TREE=m
600CONFIG_TEST_RHASHTABLE=m599CONFIG_TEST_RHASHTABLE=m
601CONFIG_TEST_IDA=m600CONFIG_TEST_IDA=m
arch/m68k/configs/sun3_defconfig+0−1
@@ -575,7 +575,6 @@ CONFIG_TEST_PRINTF=m · 574 unmodified lines
575CONFIG_TEST_SCANF=m575CONFIG_TEST_SCANF=m
576CONFIG_TEST_BITMAP=m576CONFIG_TEST_BITMAP=m
577CONFIG_TEST_UUID=m577CONFIG_TEST_UUID=m
578CONFIG_TEST_XARRAY=m
579CONFIG_TEST_MAPLE_TREE=m578CONFIG_TEST_MAPLE_TREE=m
580CONFIG_TEST_RHASHTABLE=m579CONFIG_TEST_RHASHTABLE=m
581CONFIG_TEST_IDA=m580CONFIG_TEST_IDA=m
arch/m68k/configs/sun3x_defconfig+0−1
@@ -576,7 +576,6 @@ CONFIG_TEST_PRINTF=m · 575 unmodified lines
576CONFIG_TEST_SCANF=m576CONFIG_TEST_SCANF=m
577CONFIG_TEST_BITMAP=m577CONFIG_TEST_BITMAP=m
578CONFIG_TEST_UUID=m578CONFIG_TEST_UUID=m
579CONFIG_TEST_XARRAY=m
580CONFIG_TEST_MAPLE_TREE=m579CONFIG_TEST_MAPLE_TREE=m
581CONFIG_TEST_RHASHTABLE=m580CONFIG_TEST_RHASHTABLE=m
582CONFIG_TEST_IDA=m581CONFIG_TEST_IDA=m
arch/powerpc/configs/ppc64_defconfig+0−1
@@ -451,7 +451,6 @@ CONFIG_TEST_PRINTF=m · 450 unmodified lines
451CONFIG_TEST_SCANF=m451CONFIG_TEST_SCANF=m
452CONFIG_TEST_BITMAP=m452CONFIG_TEST_BITMAP=m
453CONFIG_TEST_UUID=m453CONFIG_TEST_UUID=m
454CONFIG_TEST_XARRAY=m
455CONFIG_TEST_MAPLE_TREE=m454CONFIG_TEST_MAPLE_TREE=m
456CONFIG_TEST_RHASHTABLE=m455CONFIG_TEST_RHASHTABLE=m
457CONFIG_TEST_IDA=m456CONFIG_TEST_IDA=m
lib/Kconfig.debug+16−2
@@ -2456,8 +2456,22 @@ config TEST_BITMAP · 2455 unmodified lines
2456config TEST_UUID2456config TEST_UUID
2457 tristate "Test functions located in the uuid module at runtime"2457 tristate "Test functions located in the uuid module at runtime"
2458 2458
2459config TEST_XARRAY2459config XARRAY_KUNIT
2460 tristate "Test the XArray code at runtime"2460 tristate "KUnit test XArray code at runtime" if !KUNIT_ALL_TESTS
2461 depends on KUNIT
2462 default KUNIT_ALL_TESTS
2463 help
2464 Enable this option to test the Xarray code at boot.
2465
2466 KUnit tests run during boot and output the results to the debug log
2467 in TAP format (http://testanything.org/). Only useful for kernel devs
2468 running the KUnit test harness, and not intended for inclusion into a
2469 production build.
2470
2471 For more information on KUnit and unit tests in general please refer
2472 to the KUnit documentation in Documentation/dev-tools/kunit/.
2473
2474 If unsure, say N.
2461 2475
2462config TEST_MAPLE_TREE2476config TEST_MAPLE_TREE
2463 tristate "Test the Maple Tree code at runtime or module load"2477 tristate "Test the Maple Tree code at runtime or module load"
lib/Makefile+1−1
@@ -94,7 +94,6 @@ GCOV_PROFILE_test_bitmap.o := n · 93 unmodified lines
94endif94endif
95 95
96obj-$(CONFIG_TEST_UUID) += test_uuid.o96obj-$(CONFIG_TEST_UUID) += test_uuid.o
97obj-$(CONFIG_TEST_XARRAY) += test_xarray.o
98obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o97obj-$(CONFIG_TEST_MAPLE_TREE) += test_maple_tree.o
99obj-$(CONFIG_TEST_PARMAN) += test_parman.o98obj-$(CONFIG_TEST_PARMAN) += test_parman.o
100obj-$(CONFIG_TEST_KMOD) += test_kmod.o99obj-$(CONFIG_TEST_KMOD) += test_kmod.o
@@ -375,6 +374,7 @@ CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN) · 274 unmodified lines
375obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o374obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
376obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o375obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
377obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o376obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o
377obj-$(CONFIG_XARRAY_KUNIT) += test_xarray.o
378obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o378obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
379obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o379obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
380obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o380obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
lib/test_xarray.c+393−278
@@ -6,11 +6,10 @@ · 5 unmodified lines
6 * Author: Matthew Wilcox <willy@infradead.org>6 * Author: Matthew Wilcox <willy@infradead.org>
7 */7 */
8 8
9#include <linux/xarray.h>9#include <kunit/test.h>
10#include <linux/module.h>
11 10
12static unsigned int tests_run;11#include <linux/module.h>
13static unsigned int tests_passed;12#include <linux/xarray.h>
14 13
15static const unsigned int order_limit =14static const unsigned int order_limit =
16 IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1;15 IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1;
@@ -20,15 +19,12 @@ static const unsigned int order_limit = · 3 unmodified lines
20void xa_dump(const struct xarray *xa) { }19void xa_dump(const struct xarray *xa) { }
21# endif20# endif
22#undef XA_BUG_ON21#undef XA_BUG_ON
23#define XA_BUG_ON(xa, x) do { \22#define XA_BUG_ON(xa, x) do { \
24 tests_run++; \23 if (x) { \
25 if (x) { \24 KUNIT_FAIL(test, #x); \
26 printk("BUG at %s:%d\n", __func__, __LINE__); \25 xa_dump(xa); \
27 xa_dump(xa); \26 dump_stack(); \
28 dump_stack(); \27 } \
29 } else { \
30 tests_passed++; \
31 } \
32} while (0)28} while (0)
33#endif29#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 return xa_store(xa, index, xa_mk_index(index), gfp);38 return xa_store(xa, index, xa_mk_index(index), gfp);
43}39}
44 40
45static void xa_insert_index(struct xarray *xa, unsigned long index)41static void xa_insert_index(struct kunit *test, struct xarray *xa, unsigned long index)
46{42{
47 XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index),43 XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index),
48 GFP_KERNEL) != 0);44 GFP_KERNEL) != 0);
49}45}
50 46
51static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp)47static void xa_alloc_index(struct kunit *test, struct xarray *xa, unsigned long index, gfp_t gfp)
52{48{
53 u32 id;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 XA_BUG_ON(xa, id != index);53 XA_BUG_ON(xa, id != index);
58}54}
59 55
60static void xa_erase_index(struct xarray *xa, unsigned long index)56static void xa_erase_index(struct kunit *test, struct xarray *xa, unsigned long index)
61{57{
62 XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index));58 XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index));
63 XA_BUG_ON(xa, xa_load(xa, index) != NULL);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 return curr;79 return curr;
84}80}
85 81
86static noinline void check_xa_err(struct xarray *xa)82static inline struct xarray *xa_param(struct kunit *test)
87{83{
84 return *(struct xarray **)test->param_value;
85}
86
87static noinline void check_xa_err(struct kunit *test)
88{
89 struct xarray *xa = xa_param(test);
90
88 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0);91 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0);
89 XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0);92 XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0);
90#ifndef __KERNEL__93#ifndef __KERNEL__
@@ -99,8 +102,10 @@ static noinline void check_xa_err(struct xarray *xa) · 8 unmodified lines
99// XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL);102// XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL);
100}103}
101 104
102static noinline void check_xas_retry(struct xarray *xa)105static noinline void check_xas_retry(struct kunit *test)
103{106{
107 struct xarray *xa = xa_param(test);
108
104 XA_STATE(xas, xa, 0);109 XA_STATE(xas, xa, 0);
105 void *entry;110 void *entry;
106 111
@@ -109,7 +114,7 @@ static noinline void check_xas_retry(struct xarray *xa) · 2 unmodified lines
109 114
110 rcu_read_lock();115 rcu_read_lock();
111 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_value(0));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 XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas)));118 XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas)));
114 XA_BUG_ON(xa, xas_retry(&xas, NULL));119 XA_BUG_ON(xa, xas_retry(&xas, NULL));
115 XA_BUG_ON(xa, xas_retry(&xas, xa_mk_value(0)));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 xas_unlock(&xas);146 xas_unlock(&xas);
142 147
143 xa_erase_index(xa, 0);148 xa_erase_index(test, xa, 0);
144 xa_erase_index(xa, 1);149 xa_erase_index(test, xa, 1);
145}150}
146 151
147static noinline void check_xa_load(struct xarray *xa)152static noinline void check_xa_load(struct kunit *test)
148{153{
154 struct xarray *xa = xa_param(test);
155
149 unsigned long i, j;156 unsigned long i, j;
150 157
151 for (i = 0; i < 1024; i++) {158 for (i = 0; i < 1024; i++) {
@@ -167,13 +174,15 @@ static noinline void check_xa_load(struct xarray *xa) · 15 unmodified lines
167 else174 else
168 XA_BUG_ON(xa, entry);175 XA_BUG_ON(xa, entry);
169 }176 }
170 xa_erase_index(xa, i);177 xa_erase_index(test, xa, i);
171 }178 }
172 XA_BUG_ON(xa, !xa_empty(xa));179 XA_BUG_ON(xa, !xa_empty(xa));
173}180}
174 181
175static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index)182static noinline void check_xa_mark_1(struct kunit *test, unsigned long index)
176{183{
184 struct xarray *xa = xa_param(test);
185
177 unsigned int order;186 unsigned int order;
178 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 8 : 1;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 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1));202 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1));
194 203
195 /* Storing NULL clears marks, and they can't be set again */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 XA_BUG_ON(xa, !xa_empty(xa));206 XA_BUG_ON(xa, !xa_empty(xa));
198 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));207 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
199 xa_set_mark(xa, index, XA_MARK_0);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 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0));253 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0));
245 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1));254 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1));
246 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2));255 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2));
247 xa_erase_index(xa, index);256 xa_erase_index(test, xa, index);
248 xa_erase_index(xa, next);257 xa_erase_index(test, xa, next);
249 XA_BUG_ON(xa, !xa_empty(xa));258 XA_BUG_ON(xa, !xa_empty(xa));
250 }259 }
251 XA_BUG_ON(xa, !xa_empty(xa));260 XA_BUG_ON(xa, !xa_empty(xa));
252}261}
253 262
254static noinline void check_xa_mark_2(struct xarray *xa)263static noinline void check_xa_mark_2(struct kunit *test)
255{264{
265 struct xarray *xa = xa_param(test);
266
256 XA_STATE(xas, xa, 0);267 XA_STATE(xas, xa, 0);
257 unsigned long index;268 unsigned long index;
258 unsigned int count = 0;269 unsigned int count = 0;
@@ -289,9 +300,11 @@ static noinline void check_xa_mark_2(struct xarray *xa) · 30 unmodified lines
289 xa_destroy(xa);300 xa_destroy(xa);
290}301}
291 302
292static noinline void check_xa_mark_3(struct xarray *xa)303static noinline void check_xa_mark_3(struct kunit *test)
293{304{
294#ifdef CONFIG_XARRAY_MULTI305#ifdef CONFIG_XARRAY_MULTI
306 struct xarray *xa = xa_param(test);
307
295 XA_STATE(xas, xa, 0x41);308 XA_STATE(xas, xa, 0x41);
296 void *entry;309 void *entry;
297 int count = 0;310 int count = 0;
@@ -310,19 +323,21 @@ static noinline void check_xa_mark_3(struct xarray *xa) · 12 unmodified lines
310#endif323#endif
311}324}
312 325
313static noinline void check_xa_mark(struct xarray *xa)326static noinline void check_xa_mark(struct kunit *test)
314{327{
315 unsigned long index;328 unsigned long index;
316 329
317 for (index = 0; index < 16384; index += 4)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);333 check_xa_mark_2(test);
321 check_xa_mark_3(xa);334 check_xa_mark_3(test);
322}335}
323 336
324static noinline void check_xa_shrink(struct xarray *xa)337static noinline void check_xa_shrink(struct kunit *test)
325{338{
339 struct xarray *xa = xa_param(test);
340
326 XA_STATE(xas, xa, 1);341 XA_STATE(xas, xa, 1);
327 struct xa_node *node;342 struct xa_node *node;
328 unsigned int order;343 unsigned int order;
@@ -347,7 +362,7 @@ static noinline void check_xa_shrink(struct xarray *xa) · 18 unmodified lines
347 XA_BUG_ON(xa, xas_load(&xas) != NULL);362 XA_BUG_ON(xa, xas_load(&xas) != NULL);
348 xas_unlock(&xas);363 xas_unlock(&xas);
349 XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0));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 XA_BUG_ON(xa, !xa_empty(xa));366 XA_BUG_ON(xa, !xa_empty(xa));
352 367
353 for (order = 0; order < max_order; order++) {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 XA_BUG_ON(xa, xa_head(xa) == node);379 XA_BUG_ON(xa, xa_head(xa) == node);
365 rcu_read_unlock();380 rcu_read_unlock();
366 XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL);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 XA_BUG_ON(xa, xa->xa_head != node);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
373static noinline void check_insert(struct xarray *xa)388static noinline void check_insert(struct kunit *test)
374{389{
390 struct xarray *xa = xa_param(test);
391
375 unsigned long i;392 unsigned long i;
376 393
377 for (i = 0; i < 1024; i++) {394 for (i = 0; i < 1024; i++) {
378 xa_insert_index(xa, i);395 xa_insert_index(test, xa, i);
379 XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL);396 XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL);
380 XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL);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 for (i = 10; i < BITS_PER_LONG; i++) {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 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL);403 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL);
387 XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL);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 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL);408 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL);
392 XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL);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 XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL);414 XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL);
398 XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL);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 XA_BUG_ON(xa, !xa_empty(xa));418 XA_BUG_ON(xa, !xa_empty(xa));
402}419}
403 420
404static noinline void check_cmpxchg(struct xarray *xa)421static noinline void check_cmpxchg(struct kunit *test)
405{422{
423 struct xarray *xa = xa_param(test);
424
406 void *FIVE = xa_mk_value(5);425 void *FIVE = xa_mk_value(5);
407 void *SIX = xa_mk_value(6);426 void *SIX = xa_mk_value(6);
408 void *LOTS = xa_mk_value(12345678);427 void *LOTS = xa_mk_value(12345678);
@@ -418,14 +437,16 @@ static noinline void check_cmpxchg(struct xarray *xa) · 9 unmodified lines
418 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY);437 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY);
419 XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE);438 XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE);
420 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY);439 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY);
421 xa_erase_index(xa, 12345678);440 xa_erase_index(test, xa, 12345678);
422 xa_erase_index(xa, 5);441 xa_erase_index(test, xa, 5);
423 XA_BUG_ON(xa, !xa_empty(xa));442 XA_BUG_ON(xa, !xa_empty(xa));
424}443}
425 444
426static noinline void check_cmpxchg_order(struct xarray *xa)445static noinline void check_cmpxchg_order(struct kunit *test)
427{446{
428#ifdef CONFIG_XARRAY_MULTI447#ifdef CONFIG_XARRAY_MULTI
448 struct xarray *xa = xa_param(test);
449
429 void *FIVE = xa_mk_value(5);450 void *FIVE = xa_mk_value(5);
430 unsigned int i, order = 3;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#endif497#endif
477}498}
478 499
479static noinline void check_reserve(struct xarray *xa)500static noinline void check_reserve(struct kunit *test)
480{501{
502 struct xarray *xa = xa_param(test);
503
481 void *entry;504 void *entry;
482 unsigned long index;505 unsigned long index;
483 int count;506 int count;
@@ -494,7 +517,7 @@ static noinline void check_reserve(struct xarray *xa) · 10 unmodified lines
494 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);517 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
495 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL);518 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL);
496 xa_release(xa, 12345678);519 xa_release(xa, 12345678);
497 xa_erase_index(xa, 12345678);520 xa_erase_index(test, xa, 12345678);
498 XA_BUG_ON(xa, !xa_empty(xa));521 XA_BUG_ON(xa, !xa_empty(xa));
499 522
500 /* cmpxchg sees a reserved entry as ZERO */523 /* cmpxchg sees a reserved entry as ZERO */
@@ -502,7 +525,7 @@ static noinline void check_reserve(struct xarray *xa) · 1 unmodified line
502 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY,525 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY,
503 xa_mk_value(12345678), GFP_NOWAIT) != NULL);526 xa_mk_value(12345678), GFP_NOWAIT) != NULL);
504 xa_release(xa, 12345678);527 xa_release(xa, 12345678);
505 xa_erase_index(xa, 12345678);528 xa_erase_index(test, xa, 12345678);
506 XA_BUG_ON(xa, !xa_empty(xa));529 XA_BUG_ON(xa, !xa_empty(xa));
507 530
508 /* xa_insert treats it as busy */531 /* xa_insert treats it as busy */
@@ -542,8 +565,10 @@ static noinline void check_reserve(struct xarray *xa) · 33 unmodified lines
542 xa_destroy(xa);565 xa_destroy(xa);
543}566}
544 567
545static noinline void check_xas_erase(struct xarray *xa)568static noinline void check_xas_erase(struct kunit *test)
546{569{
570 struct xarray *xa = xa_param(test);
571
547 XA_STATE(xas, xa, 0);572 XA_STATE(xas, xa, 0);
548 void *entry;573 void *entry;
549 unsigned long i, j;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#ifdef CONFIG_XARRAY_MULTI608#ifdef CONFIG_XARRAY_MULTI
584static noinline void check_multi_store_1(struct xarray *xa, unsigned long index,609static noinline void check_multi_store_1(struct kunit *test, unsigned long index,
585 unsigned int order)610 unsigned int order)
586{611{
612 struct xarray *xa = xa_param(test);
613
587 XA_STATE(xas, xa, index);614 XA_STATE(xas, xa, index);
588 unsigned long min = index & ~((1UL << order) - 1);615 unsigned long min = index & ~((1UL << order) - 1);
589 unsigned long max = min + (1UL << order);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 XA_BUG_ON(xa, xa_load(xa, max) != NULL);629 XA_BUG_ON(xa, xa_load(xa, max) != NULL);
603 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);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 XA_BUG_ON(xa, !xa_empty(xa));633 XA_BUG_ON(xa, !xa_empty(xa));
607}634}
608 635
609static noinline void check_multi_store_2(struct xarray *xa, unsigned long index,636static noinline void check_multi_store_2(struct kunit *test, unsigned long index,
610 unsigned int order)637 unsigned int order)
611{638{
639 struct xarray *xa = xa_param(test);
640
612 XA_STATE(xas, xa, index);641 XA_STATE(xas, xa, index);
613 xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL);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 XA_BUG_ON(xa, !xa_empty(xa));649 XA_BUG_ON(xa, !xa_empty(xa));
621}650}
622 651
623static noinline void check_multi_store_3(struct xarray *xa, unsigned long index,652static noinline void check_multi_store_3(struct kunit *test, unsigned long index,
624 unsigned int order)653 unsigned int order)
625{654{
655 struct xarray *xa = xa_param(test);
656
626 XA_STATE(xas, xa, 0);657 XA_STATE(xas, xa, 0);
627 void *entry;658 void *entry;
628 int n = 0;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#endif679#endif
649 680
650static noinline void check_multi_store(struct xarray *xa)681static noinline void check_multi_store(struct kunit *test)
651{682{
652#ifdef CONFIG_XARRAY_MULTI683#ifdef CONFIG_XARRAY_MULTI
684 struct xarray *xa = xa_param(test);
685
653 unsigned long i, j, k;686 unsigned long i, j, k;
654 unsigned int max_order = (sizeof(long) == 4) ? 30 : 60;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 for (i = 0; i < 20; i++) {749 for (i = 0; i < 20; i++) {
717 check_multi_store_1(xa, 200, i);750 check_multi_store_1(test, 200, i);
718 check_multi_store_1(xa, 0, i);751 check_multi_store_1(test, 0, i);
719 check_multi_store_1(xa, (1UL << i) + 1, 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 for (i = 1; i < 20; i++) {756 for (i = 1; i < 20; i++) {
724 check_multi_store_3(xa, 0, i);757 check_multi_store_3(test, 0, i);
725 check_multi_store_3(xa, 1UL << i, i);758 check_multi_store_3(test, 1UL << i, i);
726 }759 }
727#endif760#endif
728}761}
729 762
730#ifdef CONFIG_XARRAY_MULTI763#ifdef CONFIG_XARRAY_MULTI
731/* mimics page cache __filemap_add_folio() */764/* mimics page cache __filemap_add_folio() */
732static noinline void check_xa_multi_store_adv_add(struct xarray *xa,765static noinline void check_xa_multi_store_adv_add(struct kunit *test,
733 unsigned long index,766 unsigned long index,
734 unsigned int order,767 unsigned int order,
735 void *p)768 void *p)
736{769{
770 struct xarray *xa = xa_param(test);
771
737 XA_STATE(xas, xa, index);772 XA_STATE(xas, xa, index);
738 unsigned int nrpages = 1UL << order;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/* mimics page_cache_delete() */798/* mimics page_cache_delete() */
764static noinline void check_xa_multi_store_adv_del_entry(struct xarray *xa,799static noinline void check_xa_multi_store_adv_del_entry(struct kunit *test,
765 unsigned long index,800 unsigned long index,
766 unsigned int order)801 unsigned int order)
767{802{
803 struct xarray *xa = xa_param(test);
804
768 XA_STATE(xas, xa, index);805 XA_STATE(xas, xa, index);
769 806
770 xas_set_order(&xas, index, order);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 xas_init_marks(&xas);809 xas_init_marks(&xas);
773}810}
774 811
775static noinline void check_xa_multi_store_adv_delete(struct xarray *xa,812static noinline void check_xa_multi_store_adv_delete(struct kunit *test,
776 unsigned long index,813 unsigned long index,
777 unsigned int order)814 unsigned int order)
778{815{
816 struct xarray *xa = xa_param(test);
817
779 xa_lock_irq(xa);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 xa_unlock_irq(xa);820 xa_unlock_irq(xa);
782}821}
783 822
@@ -814,10 +853,12 @@ static unsigned long some_val = 0xdeadbeef; · 30 unmodified lines
814static unsigned long some_val_2 = 0xdeaddead;853static unsigned long some_val_2 = 0xdeaddead;
815 854
816/* mimics the page cache usage */855/* mimics the page cache usage */
817static noinline void check_xa_multi_store_adv(struct xarray *xa,856static noinline void check_xa_multi_store_adv(struct kunit *test,
818 unsigned long pos,857 unsigned long pos,
819 unsigned int order)858 unsigned int order)
820{859{
860 struct xarray *xa = xa_param(test);
861
821 unsigned int nrpages = 1UL << order;862 unsigned int nrpages = 1UL << order;
822 unsigned long index, base, next_index, next_next_index;863 unsigned long index, base, next_index, next_next_index;
823 unsigned int i;864 unsigned int i;
@@ -827,7 +868,7 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 3 unmodified lines
827 next_index = round_down(base + nrpages, nrpages);868 next_index = round_down(base + nrpages, nrpages);
828 next_next_index = round_down(next_index + nrpages, nrpages);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 for (i = 0; i < nrpages; i++)873 for (i = 0; i < nrpages; i++)
833 XA_BUG_ON(xa, test_get_entry(xa, base + i) != &some_val);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 XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL);876 XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL);
836 877
837 /* Use order 0 for the next item */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 XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2);880 XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2);
840 881
841 /* Remove the next item */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 /* Now use order for a new pointer */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 for (i = 0; i < nrpages; i++)888 for (i = 0; i < nrpages; i++)
848 XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2);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);891 check_xa_multi_store_adv_delete(test, next_index, order);
851 check_xa_multi_store_adv_delete(xa, base, order);892 check_xa_multi_store_adv_delete(test, base, order);
852 XA_BUG_ON(xa, !xa_empty(xa));893 XA_BUG_ON(xa, !xa_empty(xa));
853 894
854 /* starting fresh again */895 /* starting fresh again */
@@ -856,7 +897,7 @@ static noinline void check_xa_multi_store_adv(struct xarray *xa, · 1 unmodified line
856 /* let's test some holes now */897 /* let's test some holes now */
857 898
858 /* hole at base and next_next */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 for (i = 0; i < nrpages; i++)902 for (i = 0; i < nrpages; i++)
862 XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL);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 for (i = 0; i < nrpages; i++)908 for (i = 0; i < nrpages; i++)
868 XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL);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 XA_BUG_ON(xa, !xa_empty(xa));912 XA_BUG_ON(xa, !xa_empty(xa));
872 913
873 /* hole at base and next */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 for (i = 0; i < nrpages; i++)918 for (i = 0; i < nrpages; i++)
878 XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL);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 for (i = 0; i < nrpages; i++)924 for (i = 0; i < nrpages; i++)
884 XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2);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 XA_BUG_ON(xa, !xa_empty(xa));928 XA_BUG_ON(xa, !xa_empty(xa));
888}929}
889#endif930#endif
890 931
891static noinline void check_multi_store_advanced(struct xarray *xa)932static noinline void check_multi_store_advanced(struct kunit *test)
892{933{
893#ifdef CONFIG_XARRAY_MULTI934#ifdef CONFIG_XARRAY_MULTI
894 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;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 for (pos = 7; pos < end; pos = (pos * pos) + 564) {942 for (pos = 7; pos < end; pos = (pos * pos) + 564) {
902 for (i = 0; i < max_order; i++) {943 for (i = 0; i < max_order; i++) {
903 check_xa_multi_store_adv(xa, pos, i);944 check_xa_multi_store_adv(test, pos, i);
904 check_xa_multi_store_adv(xa, pos + 157, i);945 check_xa_multi_store_adv(test, pos + 157, i);
905 }946 }
906 }947 }
907#endif948#endif
908}949}
909 950
910static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base)951static noinline void check_xa_alloc_1(struct kunit *test, struct xarray *xa, unsigned int base)
911{952{
912 int i;953 int i;
913 u32 id;954 u32 id;
914 955
915 XA_BUG_ON(xa, !xa_empty(xa));956 XA_BUG_ON(xa, !xa_empty(xa));
916 /* An empty array should assign %base to the first alloc */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 /* Erasing it should make the array empty again */960 /* Erasing it should make the array empty again */
920 xa_erase_index(xa, base);961 xa_erase_index(test, xa, base);
921 XA_BUG_ON(xa, !xa_empty(xa));962 XA_BUG_ON(xa, !xa_empty(xa));
922 963
923 /* And it should assign %base again */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 /* Allocating and then erasing a lot should not lose base */967 /* Allocating and then erasing a lot should not lose base */
927 for (i = base + 1; i < 2 * XA_CHUNK_SIZE; i++)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 for (i = base; i < 2 * XA_CHUNK_SIZE; i++)970 for (i = base; i < 2 * XA_CHUNK_SIZE; i++)
930 xa_erase_index(xa, i);971 xa_erase_index(test, xa, i);
931 xa_alloc_index(xa, base, GFP_KERNEL);972 xa_alloc_index(test, xa, base, GFP_KERNEL);
932 973
933 /* Destroying the array should do the same as erasing */974 /* Destroying the array should do the same as erasing */
934 xa_destroy(xa);975 xa_destroy(xa);
935 976
936 /* And it should assign %base again */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 /* The next assigned ID should be base+1 */980 /* The next assigned ID should be base+1 */
940 xa_alloc_index(xa, base + 1, GFP_KERNEL);981 xa_alloc_index(test, xa, base + 1, GFP_KERNEL);
941 xa_erase_index(xa, base + 1);982 xa_erase_index(test, xa, base + 1);
942 983
943 /* Storing a value should mark it used */984 /* Storing a value should mark it used */
944 xa_store_index(xa, base + 1, GFP_KERNEL);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 /* If we then erase base, it should be free */988 /* If we then erase base, it should be free */
948 xa_erase_index(xa, base);989 xa_erase_index(test, xa, base);
949 xa_alloc_index(xa, base, GFP_KERNEL);990 xa_alloc_index(test, xa, base, GFP_KERNEL);
950 991
951 xa_erase_index(xa, base + 1);992 xa_erase_index(test, xa, base + 1);
952 xa_erase_index(xa, base + 2);993 xa_erase_index(test, xa, base + 2);
953 994
954 for (i = 1; i < 5000; i++) {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 xa_destroy(xa);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 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),1017 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),
977 GFP_KERNEL) != -EBUSY);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 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),1020 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),
980 GFP_KERNEL) != -EBUSY);1021 GFP_KERNEL) != -EBUSY);
981 xa_erase_index(xa, 3);1022 xa_erase_index(test, xa, 3);
982 XA_BUG_ON(xa, !xa_empty(xa));1023 XA_BUG_ON(xa, !xa_empty(xa));
983}1024}
984 1025
985static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base)1026static noinline void check_xa_alloc_2(struct kunit *test, struct xarray *xa, unsigned int base)
986{1027{
987 unsigned int i, id;1028 unsigned int i, id;
988 unsigned long index;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 XA_BUG_ON(xa, id != 5);1059 XA_BUG_ON(xa, id != 5);
1019 1060
1020 xa_for_each(xa, index, entry) {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 for (i = base; i < base + 9; i++) {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 xa_destroy(xa);1074 xa_destroy(xa);
1034}1075}
1035 1076
1036static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base)1077static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, unsigned int base)
1037{1078{
1038 struct xa_limit limit = XA_LIMIT(1, 0x3fff);1079 struct xa_limit limit = XA_LIMIT(1, 0x3fff);
1039 u32 next = 0;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 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit,1090 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit,
1050 &next, GFP_KERNEL) != 0);1091 &next, GFP_KERNEL) != 0);
1051 XA_BUG_ON(xa, id != 0x3ffd);1092 XA_BUG_ON(xa, id != 0x3ffd);
1052 xa_erase_index(xa, 0x3ffd);1093 xa_erase_index(test, xa, 0x3ffd);
1053 xa_erase_index(xa, 1);1094 xa_erase_index(test, xa, 1);
1054 XA_BUG_ON(xa, !xa_empty(xa));1095 XA_BUG_ON(xa, !xa_empty(xa));
1055 1096
1056 for (i = 0x3ffe; i < 0x4003; i++) {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 /* Check wrap-around is handled correctly */1107 /* Check wrap-around is handled correctly */
1067 if (base != 0)1108 if (base != 0)
1068 xa_erase_index(xa, base);1109 xa_erase_index(test, xa, base);
1069 xa_erase_index(xa, base + 1);1110 xa_erase_index(test, xa, base + 1);
1070 next = UINT_MAX;1111 next = UINT_MAX;
1071 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX),1112 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX),
1072 xa_limit_32b, &next, GFP_KERNEL) != 0);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 XA_BUG_ON(xa, id != base + 1);1120 XA_BUG_ON(xa, id != base + 1);
1080 1121
1081 xa_for_each(xa, index, entry)1122 xa_for_each(xa, index, entry)
1082 xa_erase_index(xa, index);1123 xa_erase_index(test, xa, index);
1083 1124
1084 XA_BUG_ON(xa, !xa_empty(xa));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
1087static DEFINE_XARRAY_ALLOC(xa0);1128static DEFINE_XARRAY_ALLOC(xa0);
1088static DEFINE_XARRAY_ALLOC1(xa1);1129static DEFINE_XARRAY_ALLOC1(xa1);
1089 1130
1090static noinline void check_xa_alloc(void)1131static noinline void check_xa_alloc(struct kunit *test)
1091{1132{
1092 check_xa_alloc_1(&xa0, 0);1133 check_xa_alloc_1(test, &xa0, 0);
1093 check_xa_alloc_1(&xa1, 1);1134 check_xa_alloc_1(test, &xa1, 1);
1094 check_xa_alloc_2(&xa0, 0);1135 check_xa_alloc_2(test, &xa0, 0);
1095 check_xa_alloc_2(&xa1, 1);1136 check_xa_alloc_2(test, &xa1, 1);
1096 check_xa_alloc_3(&xa0, 0);1137 check_xa_alloc_3(test, &xa0, 0);
1097 check_xa_alloc_3(&xa1, 1);1138 check_xa_alloc_3(test, &xa1, 1);
1098}1139}
1099 1140
1100static noinline void __check_store_iter(struct xarray *xa, unsigned long start,1141static noinline void __check_store_iter(struct kunit *test, unsigned long start,
1101 unsigned int order, unsigned int present)1142 unsigned int order, unsigned int present)
1102{1143{
1144 struct xarray *xa = xa_param(test);
1145
1103 XA_STATE_ORDER(xas, xa, start, order);1146 XA_STATE_ORDER(xas, xa, start, order);
1104 void *entry;1147 void *entry;
1105 unsigned int count = 0;1148 unsigned int count = 0;
@@ -1123,50 +1166,54 @@ retry: · 17 unmodified lines
1123 XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start));1166 XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start));
1124 XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) !=1167 XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) !=
1125 xa_mk_index(start));1168 xa_mk_index(start));
1126 xa_erase_index(xa, start);1169 xa_erase_index(test, xa, start);
1127}1170}
1128 1171
1129static noinline void check_store_iter(struct xarray *xa)1172static noinline void check_store_iter(struct kunit *test)
1130{1173{
1174 struct xarray *xa = xa_param(test);
1175
1131 unsigned int i, j;1176 unsigned int i, j;
1132 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;1177 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;
1133 1178
1134 for (i = 0; i < max_order; i++) {1179 for (i = 0; i < max_order; i++) {
1135 unsigned int min = 1 << i;1180 unsigned int min = 1 << i;
1136 unsigned int max = (2 << i) - 1;1181 unsigned int max = (2 << i) - 1;
1137 __check_store_iter(xa, 0, i, 0);1182 __check_store_iter(test, 0, i, 0);
1138 XA_BUG_ON(xa, !xa_empty(xa));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 XA_BUG_ON(xa, !xa_empty(xa));1185 XA_BUG_ON(xa, !xa_empty(xa));
1141 1186
1142 xa_store_index(xa, min, GFP_KERNEL);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 XA_BUG_ON(xa, !xa_empty(xa));1189 XA_BUG_ON(xa, !xa_empty(xa));
1145 xa_store_index(xa, max, GFP_KERNEL);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 XA_BUG_ON(xa, !xa_empty(xa));1192 XA_BUG_ON(xa, !xa_empty(xa));
1148 1193
1149 for (j = 0; j < min; j++)1194 for (j = 0; j < min; j++)
1150 xa_store_index(xa, j, GFP_KERNEL);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 XA_BUG_ON(xa, !xa_empty(xa));1197 XA_BUG_ON(xa, !xa_empty(xa));
1153 for (j = 0; j < min; j++)1198 for (j = 0; j < min; j++)
1154 xa_store_index(xa, min + j, GFP_KERNEL);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 XA_BUG_ON(xa, !xa_empty(xa));1201 XA_BUG_ON(xa, !xa_empty(xa));
1157 }1202 }
1158#ifdef CONFIG_XARRAY_MULTI1203#ifdef CONFIG_XARRAY_MULTI
1159 xa_store_index(xa, 63, GFP_KERNEL);1204 xa_store_index(xa, 63, GFP_KERNEL);
1160 xa_store_index(xa, 65, GFP_KERNEL);1205 xa_store_index(xa, 65, GFP_KERNEL);
1161 __check_store_iter(xa, 64, 2, 1);1206 __check_store_iter(test, 64, 2, 1);
1162 xa_erase_index(xa, 63);1207 xa_erase_index(test, xa, 63);
1163#endif1208#endif
1164 XA_BUG_ON(xa, !xa_empty(xa));1209 XA_BUG_ON(xa, !xa_empty(xa));
1165}1210}
1166 1211
1167static noinline void check_multi_find_1(struct xarray *xa, unsigned order)1212static noinline void check_multi_find_1(struct kunit *test, unsigned int order)
1168{1213{
1169#ifdef CONFIG_XARRAY_MULTI1214#ifdef CONFIG_XARRAY_MULTI
1215 struct xarray *xa = xa_param(test);
1216
1170 unsigned long multi = 3 << order;1217 unsigned long multi = 3 << order;
1171 unsigned long next = 4 << order;1218 unsigned long next = 4 << order;
1172 unsigned long index;1219 unsigned long index;
@@ -1189,15 +1236,17 @@ static noinline void check_multi_find_1(struct xarray *xa, unsigned order) · 16 unmodified lines
1189 XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL);1236 XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL);
1190 XA_BUG_ON(xa, index != next);1237 XA_BUG_ON(xa, index != next);
1191 1238
1192 xa_erase_index(xa, multi);1239 xa_erase_index(test, xa, multi);
1193 xa_erase_index(xa, next);1240 xa_erase_index(test, xa, next);
1194 xa_erase_index(xa, next + 1);1241 xa_erase_index(test, xa, next + 1);
1195 XA_BUG_ON(xa, !xa_empty(xa));1242 XA_BUG_ON(xa, !xa_empty(xa));
1196#endif1243#endif
1197}1244}
1198 1245
1199static noinline void check_multi_find_2(struct xarray *xa)1246static noinline void check_multi_find_2(struct kunit *test)
1200{1247{
1248 struct xarray *xa = xa_param(test);
1249
1201 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1;1250 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1;
1202 unsigned int i, j;1251 unsigned int i, j;
1203 void *entry;1252 void *entry;
@@ -1211,17 +1260,19 @@ static noinline void check_multi_find_2(struct xarray *xa) · 7 unmodified lines
1211 GFP_KERNEL);1260 GFP_KERNEL);
1212 rcu_read_lock();1261 rcu_read_lock();
1213 xas_for_each(&xas, entry, ULONG_MAX) {1262 xas_for_each(&xas, entry, ULONG_MAX) {
1214 xa_erase_index(xa, index);1263 xa_erase_index(test, xa, index);
1215 }1264 }
1216 rcu_read_unlock();1265 rcu_read_unlock();
1217 xa_erase_index(xa, index - 1);1266 xa_erase_index(test, xa, index - 1);
1218 XA_BUG_ON(xa, !xa_empty(xa));1267 XA_BUG_ON(xa, !xa_empty(xa));
1219 }1268 }
1220 }1269 }
1221}1270}
1222 1271
1223static noinline void check_multi_find_3(struct xarray *xa)1272static noinline void check_multi_find_3(struct kunit *test)
1224{1273{
1274 struct xarray *xa = xa_param(test);
1275
1225 unsigned int order;1276 unsigned int order;
1226 1277
1227 for (order = 5; order < order_limit; order++) {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 XA_BUG_ON(xa, !xa_empty(xa));1281 XA_BUG_ON(xa, !xa_empty(xa));
1231 xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL);1282 xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL);
1232 XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT));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
1237static noinline void check_find_1(struct xarray *xa)1288static noinline void check_find_1(struct kunit *test)
1238{1289{
1290 struct xarray *xa = xa_param(test);
1291
1239 unsigned long i, j, k;1292 unsigned long i, j, k;
1240 1293
1241 XA_BUG_ON(xa, !xa_empty(xa));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 else1325 else
1273 XA_BUG_ON(xa, entry != NULL);1326 XA_BUG_ON(xa, entry != NULL);
1274 }1327 }
1275 xa_erase_index(xa, j);1328 xa_erase_index(test, xa, j);
1276 XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0));1329 XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0));
1277 XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0));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 XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0));1333 XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0));
1281 }1334 }
1282 XA_BUG_ON(xa, !xa_empty(xa));1335 XA_BUG_ON(xa, !xa_empty(xa));
1283}1336}
1284 1337
1285static noinline void check_find_2(struct xarray *xa)1338static noinline void check_find_2(struct kunit *test)
1286{1339{
1340 struct xarray *xa = xa_param(test);
1341
1287 void *entry;1342 void *entry;
1288 unsigned long i, j, index;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 xa_destroy(xa);1358 xa_destroy(xa);
1304}1359}
1305 1360
1306static noinline void check_find_3(struct xarray *xa)1361static noinline void check_find_3(struct kunit *test)
1307{1362{
1363 struct xarray *xa = xa_param(test);
1364
1308 XA_STATE(xas, xa, 0);1365 XA_STATE(xas, xa, 0);
1309 unsigned long i, j, k;1366 unsigned long i, j, k;
1310 void *entry;1367 void *entry;
@@ -1328,8 +1385,10 @@ static noinline void check_find_3(struct xarray *xa) · 17 unmodified lines
1328 xa_destroy(xa);1385 xa_destroy(xa);
1329}1386}
1330 1387
1331static noinline void check_find_4(struct xarray *xa)1388static noinline void check_find_4(struct kunit *test)
1332{1389{
1390 struct xarray *xa = xa_param(test);
1391
1333 unsigned long index = 0;1392 unsigned long index = 0;
1334 void *entry;1393 void *entry;
1335 1394
@@ -1341,22 +1400,22 @@ static noinline void check_find_4(struct xarray *xa) · 5 unmodified lines
1341 entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT);1400 entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT);
1342 XA_BUG_ON(xa, entry);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
1347static noinline void check_find(struct xarray *xa)1406static noinline void check_find(struct kunit *test)
1348{1407{
1349 unsigned i;1408 unsigned i;
1350 1409
1351 check_find_1(xa);1410 check_find_1(test);
1352 check_find_2(xa);1411 check_find_2(test);
1353 check_find_3(xa);1412 check_find_3(test);
1354 check_find_4(xa);1413 check_find_4(test);
1355 1414
1356 for (i = 2; i < 10; i++)1415 for (i = 2; i < 10; i++)
1357 check_multi_find_1(xa, i);1416 check_multi_find_1(test, i);
1358 check_multi_find_2(xa);1417 check_multi_find_2(test);
1359 check_multi_find_3(xa);1418 check_multi_find_3(test);
1360}1419}
1361 1420
1362/* See find_swap_entry() in mm/shmem.c */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 return entry ? xas.xa_index : -1;1441 return entry ? xas.xa_index : -1;
1383}1442}
1384 1443
1385static noinline void check_find_entry(struct xarray *xa)1444static noinline void check_find_entry(struct kunit *test)
1386{1445{
1446 struct xarray *xa = xa_param(test);
1447
1387#ifdef CONFIG_XARRAY_MULTI1448#ifdef CONFIG_XARRAY_MULTI
1388 unsigned int order;1449 unsigned int order;
1389 unsigned long offset, index;1450 unsigned long offset, index;
@@ -1410,12 +1471,14 @@ static noinline void check_find_entry(struct xarray *xa) · 20 unmodified lines
1410 xa_store_index(xa, ULONG_MAX, GFP_KERNEL);1471 xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
1411 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);1472 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
1412 XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1);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 XA_BUG_ON(xa, !xa_empty(xa));1475 XA_BUG_ON(xa, !xa_empty(xa));
1415}1476}
1416 1477
1417static noinline void check_pause(struct xarray *xa)1478static noinline void check_pause(struct kunit *test)
1418{1479{
1480 struct xarray *xa = xa_param(test);
1481
1419 XA_STATE(xas, xa, 0);1482 XA_STATE(xas, xa, 0);
1420 void *entry;1483 void *entry;
1421 unsigned int order;1484 unsigned int order;
@@ -1450,8 +1513,10 @@ static noinline void check_pause(struct xarray *xa) · 28 unmodified lines
1450 xa_destroy(xa);1513 xa_destroy(xa);
1451}1514}
1452 1515
1453static noinline void check_move_tiny(struct xarray *xa)1516static noinline void check_move_tiny(struct kunit *test)
1454{1517{
1518 struct xarray *xa = xa_param(test);
1519
1455 XA_STATE(xas, xa, 0);1520 XA_STATE(xas, xa, 0);
1456 1521
1457 XA_BUG_ON(xa, !xa_empty(xa));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 XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0));1533 XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0));
1469 XA_BUG_ON(xa, xas_prev(&xas) != NULL);1534 XA_BUG_ON(xa, xas_prev(&xas) != NULL);
1470 rcu_read_unlock();1535 rcu_read_unlock();
1471 xa_erase_index(xa, 0);1536 xa_erase_index(test, xa, 0);
1472 XA_BUG_ON(xa, !xa_empty(xa));1537 XA_BUG_ON(xa, !xa_empty(xa));
1473}1538}
1474 1539
1475static noinline void check_move_max(struct xarray *xa)1540static noinline void check_move_max(struct kunit *test)
1476{1541{
1542 struct xarray *xa = xa_param(test);
1543
1477 XA_STATE(xas, xa, 0);1544 XA_STATE(xas, xa, 0);
1478 1545
1479 xa_store_index(xa, ULONG_MAX, GFP_KERNEL);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 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL);1556 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL);
1490 rcu_read_unlock();1557 rcu_read_unlock();
1491 1558
1492 xa_erase_index(xa, ULONG_MAX);1559 xa_erase_index(test, xa, ULONG_MAX);
1493 XA_BUG_ON(xa, !xa_empty(xa));1560 XA_BUG_ON(xa, !xa_empty(xa));
1494}1561}
1495 1562
1496static noinline void check_move_small(struct xarray *xa, unsigned long idx)1563static noinline void check_move_small(struct kunit *test, unsigned long idx)
1497{1564{
1565 struct xarray *xa = xa_param(test);
1566
1498 XA_STATE(xas, xa, 0);1567 XA_STATE(xas, xa, 0);
1499 unsigned long i;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 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);1605 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);
1537 rcu_read_unlock();1606 rcu_read_unlock();
1538 1607
1539 xa_erase_index(xa, 0);1608 xa_erase_index(test, xa, 0);
1540 xa_erase_index(xa, idx);1609 xa_erase_index(test, xa, idx);
1541 XA_BUG_ON(xa, !xa_empty(xa));1610 XA_BUG_ON(xa, !xa_empty(xa));
1542}1611}
1543 1612
1544static noinline void check_move(struct xarray *xa)1613static noinline void check_move(struct kunit *test)
1545{1614{
1615 struct xarray *xa = xa_param(test);
1616
1546 XA_STATE(xas, xa, (1 << 16) - 1);1617 XA_STATE(xas, xa, (1 << 16) - 1);
1547 unsigned long i;1618 unsigned long i;
1548 1619
@@ -1569,7 +1640,7 @@ static noinline void check_move(struct xarray *xa) · 20 unmodified lines
1569 rcu_read_unlock();1640 rcu_read_unlock();
1570 1641
1571 for (i = (1 << 8); i < (1 << 15); i++)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 i = xas.xa_index;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 xa_destroy(xa);1672 xa_destroy(xa);
1602 1673
1603 check_move_tiny(xa);1674 check_move_tiny(test);
1604 check_move_max(xa);1675 check_move_max(test);
1605 1676
1606 for (i = 0; i < 16; i++)1677 for (i = 0; i < 16; i++)
1607 check_move_small(xa, 1UL << i);1678 check_move_small(test, 1UL << i);
1608 1679
1609 for (i = 2; i < 16; i++)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
1613static noinline void xa_store_many_order(struct xarray *xa,1684static noinline void xa_store_many_order(struct kunit *test, struct xarray *xa,
1614 unsigned long index, unsigned order)1685 unsigned long index, unsigned order)
1615{1686{
1616 XA_STATE_ORDER(xas, xa, index, order);1687 XA_STATE_ORDER(xas, xa, index, order);
@@ -1633,30 +1704,34 @@ unlock: · 16 unmodified lines
1633 XA_BUG_ON(xa, xas_error(&xas));1704 XA_BUG_ON(xa, xas_error(&xas));
1634}1705}
1635 1706
1636static noinline void check_create_range_1(struct xarray *xa,1707static noinline void check_create_range_1(struct kunit *test,
1637 unsigned long index, unsigned order)1708 unsigned long index, unsigned order)
1638{1709{
1710 struct xarray *xa = xa_param(test);
1711
1639 unsigned long i;1712 unsigned long i;
1640 1713
1641 xa_store_many_order(xa, index, order);1714 xa_store_many_order(test, xa, index, order);
1642 for (i = index; i < index + (1UL << order); i++)1715 for (i = index; i < index + (1UL << order); i++)
1643 xa_erase_index(xa, i);1716 xa_erase_index(test, xa, i);
1644 XA_BUG_ON(xa, !xa_empty(xa));1717 XA_BUG_ON(xa, !xa_empty(xa));
1645}1718}
1646 1719
1647static noinline void check_create_range_2(struct xarray *xa, unsigned order)1720static noinline void check_create_range_2(struct kunit *test, unsigned int order)
1648{1721{
1722 struct xarray *xa = xa_param(test);
1723
1649 unsigned long i;1724 unsigned long i;
1650 unsigned long nr = 1UL << order;1725 unsigned long nr = 1UL << order;
1651 1726
1652 for (i = 0; i < nr * nr; i += nr)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 for (i = 0; i < nr * nr; i++)1729 for (i = 0; i < nr * nr; i++)
1655 xa_erase_index(xa, i);1730 xa_erase_index(test, xa, i);
1656 XA_BUG_ON(xa, !xa_empty(xa));1731 XA_BUG_ON(xa, !xa_empty(xa));
1657}1732}
1658 1733
1659static noinline void check_create_range_3(void)1734static noinline void check_create_range_3(struct kunit *test)
1660{1735{
1661 XA_STATE(xas, NULL, 0);1736 XA_STATE(xas, NULL, 0);
1662 xas_set_err(&xas, -EEXIST);1737 xas_set_err(&xas, -EEXIST);
@@ -1664,9 +1739,11 @@ static noinline void check_create_range_3(void) · 1 unmodified line
1664 XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST);1739 XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST);
1665}1740}
1666 1741
1667static noinline void check_create_range_4(struct xarray *xa,1742static noinline void check_create_range_4(struct kunit *test,
1668 unsigned long index, unsigned order)1743 unsigned long index, unsigned order)
1669{1744{
1745 struct xarray *xa = xa_param(test);
1746
1670 XA_STATE_ORDER(xas, xa, index, order);1747 XA_STATE_ORDER(xas, xa, index, order);
1671 unsigned long base = xas.xa_index;1748 unsigned long base = xas.xa_index;
1672 unsigned long i = 0;1749 unsigned long i = 0;
@@ -1692,13 +1769,15 @@ unlock: · 19 unmodified lines
1692 XA_BUG_ON(xa, xas_error(&xas));1769 XA_BUG_ON(xa, xas_error(&xas));
1693 1770
1694 for (i = base; i < base + (1UL << order); i++)1771 for (i = base; i < base + (1UL << order); i++)
1695 xa_erase_index(xa, i);1772 xa_erase_index(test, xa, i);
1696 XA_BUG_ON(xa, !xa_empty(xa));1773 XA_BUG_ON(xa, !xa_empty(xa));
1697}1774}
1698 1775
1699static noinline void check_create_range_5(struct xarray *xa,1776static noinline void check_create_range_5(struct kunit *test,
1700 unsigned long index, unsigned int order)1777 unsigned long index, unsigned int order)
1701{1778{
1779 struct xarray *xa = xa_param(test);
1780
1702 XA_STATE_ORDER(xas, xa, index, order);1781 XA_STATE_ORDER(xas, xa, index, order);
1703 unsigned int i;1782 unsigned int i;
1704 1783
@@ -1715,44 +1794,46 @@ static noinline void check_create_range_5(struct xarray *xa, · 10 unmodified lines
1715 xa_destroy(xa);1794 xa_destroy(xa);
1716}1795}
1717 1796
1718static noinline void check_create_range(struct xarray *xa)1797static noinline void check_create_range(struct kunit *test)
1719{1798{
1720 unsigned int order;1799 unsigned int order;
1721 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1;1800 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1;
1722 1801
1723 for (order = 0; order < max_order; order++) {1802 for (order = 0; order < max_order; order++) {
1724 check_create_range_1(xa, 0, order);1803 check_create_range_1(test, 0, order);
1725 check_create_range_1(xa, 1U << order, order);1804 check_create_range_1(test, 1U << order, order);
1726 check_create_range_1(xa, 2U << order, order);1805 check_create_range_1(test, 2U << order, order);
1727 check_create_range_1(xa, 3U << order, order);1806 check_create_range_1(test, 3U << order, order);
1728 check_create_range_1(xa, 1U << 24, order);1807 check_create_range_1(test, 1U << 24, order);
1729 if (order < 10)1808 if (order < 10)
1730 check_create_range_2(xa, order);1809 check_create_range_2(test, order);
1731 1810
1732 check_create_range_4(xa, 0, order);1811 check_create_range_4(test, 0, order);
1733 check_create_range_4(xa, 1U << order, order);1812 check_create_range_4(test, 1U << order, order);
1734 check_create_range_4(xa, 2U << order, order);1813 check_create_range_4(test, 2U << order, order);
1735 check_create_range_4(xa, 3U << order, order);1814 check_create_range_4(test, 3U << order, order);
1736 check_create_range_4(xa, 1U << 24, order);1815 check_create_range_4(test, 1U << 24, order);
1737 1816
1738 check_create_range_4(xa, 1, order);1817 check_create_range_4(test, 1, order);
1739 check_create_range_4(xa, (1U << order) + 1, order);1818 check_create_range_4(test, (1U << order) + 1, order);
1740 check_create_range_4(xa, (2U << order) + 1, order);1819 check_create_range_4(test, (2U << order) + 1, order);
1741 check_create_range_4(xa, (2U << order) - 1, order);1820 check_create_range_4(test, (2U << order) - 1, order);
1742 check_create_range_4(xa, (3U << order) + 1, order);1821 check_create_range_4(test, (3U << order) + 1, order);
1743 check_create_range_4(xa, (3U << order) - 1, order);1822 check_create_range_4(test, (3U << order) - 1, order);
1744 check_create_range_4(xa, (1U << 24) + 1, order);1823 check_create_range_4(test, (1U << 24) + 1, order);
1745 1824
1746 check_create_range_5(xa, 0, order);1825 check_create_range_5(test, 0, order);
1747 check_create_range_5(xa, (1U << order), 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
1753static noinline void __check_store_range(struct xarray *xa, unsigned long first,1832static noinline void __check_store_range(struct kunit *test, unsigned long first,
1754 unsigned long last)1833 unsigned long last)
1755{1834{
1835 struct xarray *xa = xa_param(test);
1836
1756#ifdef CONFIG_XARRAY_MULTI1837#ifdef CONFIG_XARRAY_MULTI
1757 xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL);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 XA_BUG_ON(xa, !xa_empty(xa));1848 XA_BUG_ON(xa, !xa_empty(xa));
1768}1849}
1769 1850
1770static noinline void check_store_range(struct xarray *xa)1851static noinline void check_store_range(struct kunit *test)
1771{1852{
1772 unsigned long i, j;1853 unsigned long i, j;
1773 1854
1774 for (i = 0; i < 128; i++) {1855 for (i = 0; i < 128; i++) {
1775 for (j = i; j < 128; j++) {1856 for (j = i; j < 128; j++) {
1776 __check_store_range(xa, i, j);1857 __check_store_range(test, i, j);
1777 __check_store_range(xa, 128 + i, 128 + j);1858 __check_store_range(test, 128 + i, 128 + j);
1778 __check_store_range(xa, 4095 + i, 4095 + j);1859 __check_store_range(test, 4095 + i, 4095 + j);
1779 __check_store_range(xa, 4096 + i, 4096 + j);1860 __check_store_range(test, 4096 + i, 4096 + j);
1780 __check_store_range(xa, 123456 + i, 123456 + j);1861 __check_store_range(test, 123456 + i, 123456 + j);
1781 __check_store_range(xa, (1 << 24) + i, (1 << 24) + j);1862 __check_store_range(test, (1 << 24) + i, (1 << 24) + j);
1782 }1863 }
1783 }1864 }
1784}1865}
1785 1866
1786#ifdef CONFIG_XARRAY_MULTI1867#ifdef CONFIG_XARRAY_MULTI
1787static void check_split_1(struct xarray *xa, unsigned long index,1868static void check_split_1(struct kunit *test, unsigned long index,
1788 unsigned int order, unsigned int new_order)1869 unsigned int order, unsigned int new_order)
1789{1870{
1871 struct xarray *xa = xa_param(test);
1872
1790 XA_STATE_ORDER(xas, xa, index, new_order);1873 XA_STATE_ORDER(xas, xa, index, new_order);
1791 unsigned int i, found;1874 unsigned int i, found;
1792 void *entry;1875 void *entry;
@@ -1822,26 +1905,30 @@ static void check_split_1(struct xarray *xa, unsigned long index, · 29 unmodified lines
1822 xa_destroy(xa);1905 xa_destroy(xa);
1823}1906}
1824 1907
1825static noinline void check_split(struct xarray *xa)1908static noinline void check_split(struct kunit *test)
1826{1909{
1910 struct xarray *xa = xa_param(test);
1911
1827 unsigned int order, new_order;1912 unsigned int order, new_order;
1828 1913
1829 XA_BUG_ON(xa, !xa_empty(xa));1914 XA_BUG_ON(xa, !xa_empty(xa));
1830 1915
1831 for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) {1916 for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) {
1832 for (new_order = 0; new_order < order; new_order++) {1917 for (new_order = 0; new_order < order; new_order++) {
1833 check_split_1(xa, 0, order, new_order);1918 check_split_1(test, 0, order, new_order);
1834 check_split_1(xa, 1UL << order, order, new_order);1919 check_split_1(test, 1UL << order, order, new_order);
1835 check_split_1(xa, 3UL << order, order, new_order);1920 check_split_1(test, 3UL << order, order, new_order);
1836 }1921 }
1837 }1922 }
1838}1923}
1839#else1924#else
1840static void check_split(struct xarray *xa) { }1925static void check_split(struct kunit *test) { }
1841#endif1926#endif
1842 1927
1843static void check_align_1(struct xarray *xa, char *name)1928static void check_align_1(struct kunit *test, char *name)
1844{1929{
1930 struct xarray *xa = xa_param(test);
1931
1845 int i;1932 int i;
1846 unsigned int id;1933 unsigned int id;
1847 unsigned long index;1934 unsigned long index;
@@ -1861,8 +1948,10 @@ static void check_align_1(struct xarray *xa, char *name) · 13 unmodified lines
1861 * We should always be able to store without allocating memory after1948 * We should always be able to store without allocating memory after
1862 * reserving a slot.1949 * reserving a slot.
1863 */1950 */
1864static void check_align_2(struct xarray *xa, char *name)1951static void check_align_2(struct kunit *test, char *name)
1865{1952{
1953 struct xarray *xa = xa_param(test);
1954
1866 int i;1955 int i;
1867 1956
1868 XA_BUG_ON(xa, !xa_empty(xa));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 XA_BUG_ON(xa, !xa_empty(xa));1970 XA_BUG_ON(xa, !xa_empty(xa));
1882}1971}
1883 1972
1884static noinline void check_align(struct xarray *xa)1973static noinline void check_align(struct kunit *test)
1885{1974{
1886 char name[] = "Motorola 68000";1975 char name[] = "Motorola 68000";
1887 1976
1888 check_align_1(xa, name);1977 check_align_1(test, name);
1889 check_align_1(xa, name + 1);1978 check_align_1(test, name + 1);
1890 check_align_1(xa, name + 2);1979 check_align_1(test, name + 2);
1891 check_align_1(xa, name + 3);1980 check_align_1(test, name + 3);
1892 check_align_2(xa, name);1981 check_align_2(test, name);
1893}1982}
1894 1983
1895static LIST_HEAD(shadow_nodes);1984static 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
1908static noinline void shadow_remove(struct xarray *xa)1997static noinline void shadow_remove(struct kunit *test, struct xarray *xa)
1909{1998{
1910 struct xa_node *node;1999 struct xa_node *node;
1911 2000
@@ -1919,8 +2008,17 @@ static noinline void shadow_remove(struct xarray *xa) · 7 unmodified lines
1919 xa_unlock(xa);2008 xa_unlock(xa);
1920}2009}
1921 2010
1922static noinline void check_workingset(struct xarray *xa, unsigned long index)2011struct workingset_testcase {
2012 struct xarray *xa;
2013 unsigned long index;
2014};
2015
2016static 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 XA_STATE(xas, xa, index);2022 XA_STATE(xas, xa, index);
1925 xas_set_update(&xas, test_update_node);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 xas_unlock(&xas);2041 xas_unlock(&xas);
1944 XA_BUG_ON(xa, list_empty(&shadow_nodes));2042 XA_BUG_ON(xa, list_empty(&shadow_nodes));
1945 2043
1946 shadow_remove(xa);2044 shadow_remove(test, xa);
1947 XA_BUG_ON(xa, !list_empty(&shadow_nodes));2045 XA_BUG_ON(xa, !list_empty(&shadow_nodes));
1948 XA_BUG_ON(xa, !xa_empty(xa));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 * Check that the pointer / value / sibling entries are accounted the2050 * Check that the pointer / value / sibling entries are accounted the
1953 * way we expect them to be.2051 * way we expect them to be.
1954 */2052 */
1955static noinline void check_account(struct xarray *xa)2053static noinline void check_account(struct kunit *test)
1956{2054{
1957#ifdef CONFIG_XARRAY_MULTI2055#ifdef CONFIG_XARRAY_MULTI
2056 struct xarray *xa = xa_param(test);
2057
1958 unsigned int order;2058 unsigned int order;
1959 2059
1960 for (order = 1; order < 12; order++) {2060 for (order = 1; order < 12; order++) {
@@ -1981,8 +2081,10 @@ static noinline void check_account(struct xarray *xa) · 20 unmodified lines
1981#endif2081#endif
1982}2082}
1983 2083
1984static noinline void check_get_order(struct xarray *xa)2084static noinline void check_get_order(struct kunit *test)
1985{2085{
2086 struct xarray *xa = xa_param(test);
2087
1986 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;2088 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;
1987 unsigned int order;2089 unsigned int order;
1988 unsigned long i, j;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
2004static noinline void check_xas_get_order(struct xarray *xa)2106static noinline void check_xas_get_order(struct kunit *test)
2005{2107{
2108 struct xarray *xa = xa_param(test);
2109
2006 XA_STATE(xas, xa, 0);2110 XA_STATE(xas, xa, 0);
2007 2111
2008 unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;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
2037static noinline void check_xas_conflict_get_order(struct xarray *xa)2141static noinline void check_xas_conflict_get_order(struct kunit *test)
2038{2142{
2143 struct xarray *xa = xa_param(test);
2144
2039 XA_STATE(xas, xa, 0);2145 XA_STATE(xas, xa, 0);
2040 2146
2041 void *entry;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
2095static noinline void check_destroy(struct xarray *xa)2201static noinline void check_destroy(struct kunit *test)
2096{2202{
2203 struct xarray *xa = xa_param(test);
2204
2097 unsigned long index;2205 unsigned long index;
2098 2206
2099 XA_BUG_ON(xa, !xa_empty(xa));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
2128static DEFINE_XARRAY(array);2236static DEFINE_XARRAY(array);
2237static struct xarray *arrays[] = { &array };
2238KUNIT_ARRAY_PARAM(array, arrays, NULL);
2239
2240static struct xarray *xa0s[] = { &xa0 };
2241KUNIT_ARRAY_PARAM(xa0, xa0s, NULL);
2242
2243static struct workingset_testcase workingset_testcases[] = {
2244 { &array, 0 },
2245 { &array, 64 },
2246 { &array, 4096 },
2247};
2248KUNIT_ARRAY_PARAM(workingset, workingset_testcases, NULL);
2249
2250static 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
2283static struct kunit_suite xarray_suite = {
2284 .name = "xarray",
2285 .test_cases = xarray_cases,
2286};
2287
2288kunit_test_suite(xarray_suite);
2129 2289
2130static 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
2169static void xarray_exit(void)
2170{
2171}
2172
2173module_init(xarray_checks);
2174module_exit(xarray_exit);
2175MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");2290MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
2176MODULE_DESCRIPTION("XArray API test module");2291MODULE_DESCRIPTION("XArray API test module");
2177MODULE_LICENSE("GPL");2292MODULE_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