aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <willy@infradead.org>2018-09-09 01:52:17 -0400
committerMatthew Wilcox <willy@infradead.org>2018-10-21 10:46:46 -0400
commit4f06d6302da682157890f72c0573e12a73536814 (patch)
treead61fcd160cb757cf34f173f596c927885742af3
parent93eb07f72c8d86f8fe5e90907df1cc037f6ffbb7 (diff)
xarray: Move multiorder_check to in-kernel tests
This version is a little less thorough in order to be a little quicker, but tests the important edge cases. Also test adding a multiorder entry at a non-canonical index, and erasing it. Signed-off-by: Matthew Wilcox <willy@infradead.org>
-rw-r--r--lib/test_xarray.c44
-rw-r--r--tools/testing/radix-tree/multiorder.c48
2 files changed, 44 insertions, 48 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c
index ff94b54a926d..0f06a93b4d0e 100644
--- a/lib/test_xarray.c
+++ b/lib/test_xarray.c
@@ -422,6 +422,43 @@ static noinline void check_xas_erase(struct xarray *xa)
422 } 422 }
423} 423}
424 424
425#ifdef CONFIG_XARRAY_MULTI
426static noinline void check_multi_store_1(struct xarray *xa, unsigned long index,
427 unsigned int order)
428{
429 XA_STATE(xas, xa, index);
430 unsigned long min = index & ~((1UL << order) - 1);
431 unsigned long max = min + (1UL << order);
432
433 xa_store_order(xa, index, order, xa_mk_value(index), GFP_KERNEL);
434 XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(index));
435 XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(index));
436 XA_BUG_ON(xa, xa_load(xa, max) != NULL);
437 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
438
439 XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(min)) != xa_mk_value(index));
440 XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(min));
441 XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(min));
442 XA_BUG_ON(xa, xa_load(xa, max) != NULL);
443 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
444
445 xa_erase_index(xa, min);
446 XA_BUG_ON(xa, !xa_empty(xa));
447}
448
449static noinline void check_multi_store_2(struct xarray *xa, unsigned long index,
450 unsigned int order)
451{
452 XA_STATE(xas, xa, index);
453 xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL);
454
455 XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(1)) != xa_mk_value(0));
456 XA_BUG_ON(xa, xas.xa_index != index);
457 XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1));
458 XA_BUG_ON(xa, !xa_empty(xa));
459}
460#endif
461
425static noinline void check_multi_store(struct xarray *xa) 462static noinline void check_multi_store(struct xarray *xa)
426{ 463{
427#ifdef CONFIG_XARRAY_MULTI 464#ifdef CONFIG_XARRAY_MULTI
@@ -487,6 +524,13 @@ static noinline void check_multi_store(struct xarray *xa)
487 XA_BUG_ON(xa, !xa_empty(xa)); 524 XA_BUG_ON(xa, !xa_empty(xa));
488 } 525 }
489 } 526 }
527
528 for (i = 0; i < 20; i++) {
529 check_multi_store_1(xa, 200, i);
530 check_multi_store_1(xa, 0, i);
531 check_multi_store_1(xa, (1UL << i) + 1, i);
532 }
533 check_multi_store_2(xa, 4095, 9);
490#endif 534#endif
491} 535}
492 536
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c
index a60c03287e9c..6e8d66c2aa89 100644
--- a/tools/testing/radix-tree/multiorder.c
+++ b/tools/testing/radix-tree/multiorder.c
@@ -20,46 +20,6 @@
20 20
21#include "test.h" 21#include "test.h"
22 22
23static void multiorder_check(unsigned long index, int order)
24{
25 unsigned long i;
26 unsigned long min = index & ~((1UL << order) - 1);
27 unsigned long max = min + (1UL << order);
28 void **slot;
29 struct item *item2 = item_create(min, order);
30 RADIX_TREE(tree, GFP_KERNEL);
31
32 printv(2, "Multiorder index %ld, order %d\n", index, order);
33
34 assert(item_insert_order(&tree, index, order) == 0);
35
36 for (i = min; i < max; i++) {
37 struct item *item = item_lookup(&tree, i);
38 assert(item != 0);
39 assert(item->index == index);
40 }
41 for (i = 0; i < min; i++)
42 item_check_absent(&tree, i);
43 for (i = max; i < 2*max; i++)
44 item_check_absent(&tree, i);
45 for (i = min; i < max; i++)
46 assert(radix_tree_insert(&tree, i, item2) == -EEXIST);
47
48 slot = radix_tree_lookup_slot(&tree, index);
49 free(*slot);
50 radix_tree_replace_slot(&tree, slot, item2);
51 for (i = min; i < max; i++) {
52 struct item *item = item_lookup(&tree, i);
53 assert(item != 0);
54 assert(item->index == min);
55 }
56
57 assert(item_delete(&tree, min) != 0);
58
59 for (i = 0; i < 2*max; i++)
60 item_check_absent(&tree, i);
61}
62
63void multiorder_iteration(void) 23void multiorder_iteration(void)
64{ 24{
65 RADIX_TREE(tree, GFP_KERNEL); 25 RADIX_TREE(tree, GFP_KERNEL);
@@ -251,14 +211,6 @@ static void multiorder_iteration_race(void)
251 211
252void multiorder_checks(void) 212void multiorder_checks(void)
253{ 213{
254 int i;
255
256 for (i = 0; i < 20; i++) {
257 multiorder_check(200, i);
258 multiorder_check(0, i);
259 multiorder_check((1UL << i) + 1, i);
260 }
261
262 multiorder_iteration(); 214 multiorder_iteration();
263 multiorder_tagged_iteration(); 215 multiorder_tagged_iteration();
264 multiorder_iteration_race(); 216 multiorder_iteration_race();