diff options
Diffstat (limited to 'tools/testing/radix-tree/multiorder.c')
-rw-r--r-- | tools/testing/radix-tree/multiorder.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c index ba27fe0a579c..1b6fc9b19930 100644 --- a/tools/testing/radix-tree/multiorder.c +++ b/tools/testing/radix-tree/multiorder.c | |||
@@ -19,6 +19,102 @@ | |||
19 | 19 | ||
20 | #include "test.h" | 20 | #include "test.h" |
21 | 21 | ||
22 | #define for_each_index(i, base, order) \ | ||
23 | for (i = base; i < base + (1 << order); i++) | ||
24 | |||
25 | static void __multiorder_tag_test(int index, int order) | ||
26 | { | ||
27 | RADIX_TREE(tree, GFP_KERNEL); | ||
28 | int base, err, i; | ||
29 | |||
30 | /* our canonical entry */ | ||
31 | base = index & ~((1 << order) - 1); | ||
32 | |||
33 | printf("Multiorder tag test with index %d, canonical entry %d\n", | ||
34 | index, base); | ||
35 | |||
36 | err = item_insert_order(&tree, index, order); | ||
37 | assert(!err); | ||
38 | |||
39 | /* | ||
40 | * Verify we get collisions for covered indices. We try and fail to | ||
41 | * insert an exceptional entry so we don't leak memory via | ||
42 | * item_insert_order(). | ||
43 | */ | ||
44 | for_each_index(i, base, order) { | ||
45 | err = __radix_tree_insert(&tree, i, order, | ||
46 | (void *)(0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY)); | ||
47 | assert(err == -EEXIST); | ||
48 | } | ||
49 | |||
50 | for_each_index(i, base, order) { | ||
51 | assert(!radix_tree_tag_get(&tree, i, 0)); | ||
52 | assert(!radix_tree_tag_get(&tree, i, 1)); | ||
53 | } | ||
54 | |||
55 | assert(radix_tree_tag_set(&tree, index, 0)); | ||
56 | |||
57 | for_each_index(i, base, order) { | ||
58 | assert(radix_tree_tag_get(&tree, i, 0)); | ||
59 | assert(!radix_tree_tag_get(&tree, i, 1)); | ||
60 | } | ||
61 | |||
62 | assert(radix_tree_tag_clear(&tree, index, 0)); | ||
63 | |||
64 | for_each_index(i, base, order) { | ||
65 | assert(!radix_tree_tag_get(&tree, i, 0)); | ||
66 | assert(!radix_tree_tag_get(&tree, i, 1)); | ||
67 | } | ||
68 | |||
69 | assert(!radix_tree_tagged(&tree, 0)); | ||
70 | assert(!radix_tree_tagged(&tree, 1)); | ||
71 | |||
72 | item_kill_tree(&tree); | ||
73 | } | ||
74 | |||
75 | static void multiorder_tag_tests(void) | ||
76 | { | ||
77 | /* test multi-order entry for indices 0-7 with no sibling pointers */ | ||
78 | __multiorder_tag_test(0, 3); | ||
79 | __multiorder_tag_test(5, 3); | ||
80 | |||
81 | /* test multi-order entry for indices 8-15 with no sibling pointers */ | ||
82 | __multiorder_tag_test(8, 3); | ||
83 | __multiorder_tag_test(15, 3); | ||
84 | |||
85 | /* | ||
86 | * Our order 5 entry covers indices 0-31 in a tree with height=2. | ||
87 | * This is broken up as follows: | ||
88 | * 0-7: canonical entry | ||
89 | * 8-15: sibling 1 | ||
90 | * 16-23: sibling 2 | ||
91 | * 24-31: sibling 3 | ||
92 | */ | ||
93 | __multiorder_tag_test(0, 5); | ||
94 | __multiorder_tag_test(29, 5); | ||
95 | |||
96 | /* same test, but with indices 32-63 */ | ||
97 | __multiorder_tag_test(32, 5); | ||
98 | __multiorder_tag_test(44, 5); | ||
99 | |||
100 | /* | ||
101 | * Our order 8 entry covers indices 0-255 in a tree with height=3. | ||
102 | * This is broken up as follows: | ||
103 | * 0-63: canonical entry | ||
104 | * 64-127: sibling 1 | ||
105 | * 128-191: sibling 2 | ||
106 | * 192-255: sibling 3 | ||
107 | */ | ||
108 | __multiorder_tag_test(0, 8); | ||
109 | __multiorder_tag_test(190, 8); | ||
110 | |||
111 | /* same test, but with indices 256-511 */ | ||
112 | __multiorder_tag_test(256, 8); | ||
113 | __multiorder_tag_test(300, 8); | ||
114 | |||
115 | __multiorder_tag_test(0x12345678UL, 8); | ||
116 | } | ||
117 | |||
22 | static void multiorder_check(unsigned long index, int order) | 118 | static void multiorder_check(unsigned long index, int order) |
23 | { | 119 | { |
24 | unsigned long i; | 120 | unsigned long i; |
@@ -196,6 +292,7 @@ void multiorder_checks(void) | |||
196 | multiorder_shrink((1UL << (i + RADIX_TREE_MAP_SHIFT)), i); | 292 | multiorder_shrink((1UL << (i + RADIX_TREE_MAP_SHIFT)), i); |
197 | 293 | ||
198 | multiorder_insert_bug(); | 294 | multiorder_insert_bug(); |
295 | multiorder_tag_tests(); | ||
199 | multiorder_iteration(); | 296 | multiorder_iteration(); |
200 | multiorder_tagged_iteration(); | 297 | multiorder_tagged_iteration(); |
201 | } | 298 | } |