diff options
author | Ross Zwisler <ross.zwisler@linux.intel.com> | 2016-05-20 20:02:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-20 20:58:30 -0400 |
commit | 643b57d0a9bd4c93625a2f5da4cebc3ceb402b9b (patch) | |
tree | 2ccd9b48e111a82f361538d41ad15387c40cd296 /tools/testing/radix-tree/multiorder.c | |
parent | 21ef533931f73a8e963a6107aa5ec51b192f28be (diff) |
radix tree test suite: multi-order iteration test
Add a unit test to verify that we can iterate over multi-order entries
properly via a radix_tree_for_each_slot() loop.
This was done with a single, somewhat complicated configuration that was
meant to test many of the various corner cases having to do with
multi-order entries:
- An iteration could begin at a sibling entry, and we need to return the
canonical entry.
- We could have entries of various orders in the same slots[] array.
- We could have multi-order entries at a nonzero height, followed by
indirect pointers to more radix tree nodes later in that same slots[]
array.
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/testing/radix-tree/multiorder.c')
-rw-r--r-- | tools/testing/radix-tree/multiorder.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c index 0a311a5f39de..ba27fe0a579c 100644 --- a/tools/testing/radix-tree/multiorder.c +++ b/tools/testing/radix-tree/multiorder.c | |||
@@ -92,6 +92,96 @@ static void multiorder_insert_bug(void) | |||
92 | item_kill_tree(&tree); | 92 | item_kill_tree(&tree); |
93 | } | 93 | } |
94 | 94 | ||
95 | void multiorder_iteration(void) | ||
96 | { | ||
97 | RADIX_TREE(tree, GFP_KERNEL); | ||
98 | struct radix_tree_iter iter; | ||
99 | void **slot; | ||
100 | int i, err; | ||
101 | |||
102 | printf("Multiorder iteration test\n"); | ||
103 | |||
104 | #define NUM_ENTRIES 11 | ||
105 | int index[NUM_ENTRIES] = {0, 2, 4, 8, 16, 32, 34, 36, 64, 72, 128}; | ||
106 | int order[NUM_ENTRIES] = {1, 1, 2, 3, 4, 1, 0, 1, 3, 0, 7}; | ||
107 | |||
108 | for (i = 0; i < NUM_ENTRIES; i++) { | ||
109 | err = item_insert_order(&tree, index[i], order[i]); | ||
110 | assert(!err); | ||
111 | } | ||
112 | |||
113 | i = 0; | ||
114 | /* start from index 1 to verify we find the multi-order entry at 0 */ | ||
115 | radix_tree_for_each_slot(slot, &tree, &iter, 1) { | ||
116 | int height = order[i] / RADIX_TREE_MAP_SHIFT; | ||
117 | int shift = height * RADIX_TREE_MAP_SHIFT; | ||
118 | |||
119 | assert(iter.index == index[i]); | ||
120 | assert(iter.shift == shift); | ||
121 | i++; | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * Now iterate through the tree starting at an elevated multi-order | ||
126 | * entry, beginning at an index in the middle of the range. | ||
127 | */ | ||
128 | i = 8; | ||
129 | radix_tree_for_each_slot(slot, &tree, &iter, 70) { | ||
130 | int height = order[i] / RADIX_TREE_MAP_SHIFT; | ||
131 | int shift = height * RADIX_TREE_MAP_SHIFT; | ||
132 | |||
133 | assert(iter.index == index[i]); | ||
134 | assert(iter.shift == shift); | ||
135 | i++; | ||
136 | } | ||
137 | |||
138 | item_kill_tree(&tree); | ||
139 | } | ||
140 | |||
141 | void multiorder_tagged_iteration(void) | ||
142 | { | ||
143 | RADIX_TREE(tree, GFP_KERNEL); | ||
144 | struct radix_tree_iter iter; | ||
145 | void **slot; | ||
146 | int i; | ||
147 | |||
148 | printf("Multiorder tagged iteration test\n"); | ||
149 | |||
150 | #define MT_NUM_ENTRIES 9 | ||
151 | int index[MT_NUM_ENTRIES] = {0, 2, 4, 16, 32, 40, 64, 72, 128}; | ||
152 | int order[MT_NUM_ENTRIES] = {1, 0, 2, 4, 3, 1, 3, 0, 7}; | ||
153 | |||
154 | #define TAG_ENTRIES 7 | ||
155 | int tag_index[TAG_ENTRIES] = {0, 4, 16, 40, 64, 72, 128}; | ||
156 | |||
157 | for (i = 0; i < MT_NUM_ENTRIES; i++) | ||
158 | assert(!item_insert_order(&tree, index[i], order[i])); | ||
159 | |||
160 | assert(!radix_tree_tagged(&tree, 1)); | ||
161 | |||
162 | for (i = 0; i < TAG_ENTRIES; i++) | ||
163 | assert(radix_tree_tag_set(&tree, tag_index[i], 1)); | ||
164 | |||
165 | i = 0; | ||
166 | /* start from index 1 to verify we find the multi-order entry at 0 */ | ||
167 | radix_tree_for_each_tagged(slot, &tree, &iter, 1, 1) { | ||
168 | assert(iter.index == tag_index[i]); | ||
169 | i++; | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * Now iterate through the tree starting at an elevated multi-order | ||
174 | * entry, beginning at an index in the middle of the range. | ||
175 | */ | ||
176 | i = 4; | ||
177 | radix_tree_for_each_slot(slot, &tree, &iter, 70) { | ||
178 | assert(iter.index == tag_index[i]); | ||
179 | i++; | ||
180 | } | ||
181 | |||
182 | item_kill_tree(&tree); | ||
183 | } | ||
184 | |||
95 | void multiorder_checks(void) | 185 | void multiorder_checks(void) |
96 | { | 186 | { |
97 | int i; | 187 | int i; |
@@ -106,4 +196,6 @@ void multiorder_checks(void) | |||
106 | multiorder_shrink((1UL << (i + RADIX_TREE_MAP_SHIFT)), i); | 196 | multiorder_shrink((1UL << (i + RADIX_TREE_MAP_SHIFT)), i); |
107 | 197 | ||
108 | multiorder_insert_bug(); | 198 | multiorder_insert_bug(); |
199 | multiorder_iteration(); | ||
200 | multiorder_tagged_iteration(); | ||
109 | } | 201 | } |