aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/radix-tree/idr-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/radix-tree/idr-test.c')
-rw-r--r--tools/testing/radix-tree/idr-test.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index 44ef9eba5a7a..6c645eb77d42 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -178,6 +178,55 @@ void idr_get_next_test(int base)
178 idr_destroy(&idr); 178 idr_destroy(&idr);
179} 179}
180 180
181int idr_u32_cb(int id, void *ptr, void *data)
182{
183 BUG_ON(id < 0);
184 BUG_ON(ptr != DUMMY_PTR);
185 return 0;
186}
187
188void idr_u32_test1(struct idr *idr, u32 handle)
189{
190 static bool warned = false;
191 u32 id = handle;
192 int sid = 0;
193 void *ptr;
194
195 BUG_ON(idr_alloc_u32(idr, DUMMY_PTR, &id, id, GFP_KERNEL));
196 BUG_ON(id != handle);
197 BUG_ON(idr_alloc_u32(idr, DUMMY_PTR, &id, id, GFP_KERNEL) != -ENOSPC);
198 BUG_ON(id != handle);
199 if (!warned && id > INT_MAX)
200 printk("vvv Ignore these warnings\n");
201 ptr = idr_get_next(idr, &sid);
202 if (id > INT_MAX) {
203 BUG_ON(ptr != NULL);
204 BUG_ON(sid != 0);
205 } else {
206 BUG_ON(ptr != DUMMY_PTR);
207 BUG_ON(sid != id);
208 }
209 idr_for_each(idr, idr_u32_cb, NULL);
210 if (!warned && id > INT_MAX) {
211 printk("^^^ Warnings over\n");
212 warned = true;
213 }
214 BUG_ON(idr_remove(idr, id) != DUMMY_PTR);
215 BUG_ON(!idr_is_empty(idr));
216}
217
218void idr_u32_test(int base)
219{
220 DEFINE_IDR(idr);
221 idr_init_base(&idr, base);
222 idr_u32_test1(&idr, 10);
223 idr_u32_test1(&idr, 0x7fffffff);
224 idr_u32_test1(&idr, 0x80000000);
225 idr_u32_test1(&idr, 0x80000001);
226 idr_u32_test1(&idr, 0xffe00000);
227 idr_u32_test1(&idr, 0xffffffff);
228}
229
181void idr_checks(void) 230void idr_checks(void)
182{ 231{
183 unsigned long i; 232 unsigned long i;
@@ -248,6 +297,9 @@ void idr_checks(void)
248 idr_get_next_test(0); 297 idr_get_next_test(0);
249 idr_get_next_test(1); 298 idr_get_next_test(1);
250 idr_get_next_test(4); 299 idr_get_next_test(4);
300 idr_u32_test(4);
301 idr_u32_test(1);
302 idr_u32_test(0);
251} 303}
252 304
253/* 305/*