Lines Matching defs:idr

3  * idr-test.c: Test the IDR API
7 #include <linux/idr.h>
25 void item_idr_remove(struct idr *idr, int id)
27 struct item *item = idr_find(idr, id);
29 idr_remove(idr, id);
36 DEFINE_IDR(idr);
38 assert(idr_alloc_cyclic(&idr, DUMMY_PTR, 0, 0x4000, GFP_KERNEL) == 0);
39 assert(idr_alloc_cyclic(&idr, DUMMY_PTR, 0x3ffd, 0x4000, GFP_KERNEL) == 0x3ffd);
40 idr_remove(&idr, 0x3ffd);
41 idr_remove(&idr, 0);
52 id = idr_alloc_cyclic(&idr, item, 1, 0x4000, GFP_KERNEL);
56 idr_for_each(&idr, item_idr_free, &idr);
57 idr_destroy(&idr);
62 DEFINE_IDR(idr);
64 idr_alloc(&idr, (void *)-1, 10, 11, GFP_KERNEL);
65 idr_replace(&idr, &idr, 10);
67 idr_destroy(&idr);
79 DEFINE_IDR(idr);
81 assert(idr_is_empty(&idr));
83 assert(idr_alloc(&idr, NULL, 0, 0, GFP_KERNEL) == 0);
84 assert(!idr_is_empty(&idr));
85 idr_remove(&idr, 0);
86 assert(idr_is_empty(&idr));
88 assert(idr_alloc(&idr, NULL, 0, 0, GFP_KERNEL) == 0);
89 assert(!idr_is_empty(&idr));
90 idr_destroy(&idr);
91 assert(idr_is_empty(&idr));
94 assert(idr_alloc(&idr, NULL, 0, 0, GFP_KERNEL) == i);
97 assert(idr_replace(&idr, DUMMY_PTR, 3) == NULL);
98 assert(idr_replace(&idr, DUMMY_PTR, 4) == NULL);
99 assert(idr_replace(&idr, NULL, 4) == DUMMY_PTR);
100 assert(idr_replace(&idr, DUMMY_PTR, 11) == ERR_PTR(-ENOENT));
101 idr_remove(&idr, 5);
102 assert(idr_alloc(&idr, NULL, 0, 0, GFP_KERNEL) == 5);
103 idr_remove(&idr, 5);
106 idr_remove(&idr, i);
107 assert(!idr_is_empty(&idr));
109 idr_remove(&idr, 8);
110 assert(!idr_is_empty(&idr));
111 idr_remove(&idr, 9);
112 assert(idr_is_empty(&idr));
114 assert(idr_alloc(&idr, NULL, 0, 0, GFP_KERNEL) == 0);
115 assert(idr_replace(&idr, DUMMY_PTR, 3) == ERR_PTR(-ENOENT));
116 assert(idr_replace(&idr, DUMMY_PTR, 0) == NULL);
117 assert(idr_replace(&idr, NULL, 0) == DUMMY_PTR);
119 idr_destroy(&idr);
120 assert(idr_is_empty(&idr));
123 assert(idr_alloc(&idr, NULL, 1, 0, GFP_KERNEL) == i);
126 idr_destroy(&idr);
127 assert(idr_is_empty(&idr));
133 DEFINE_IDR(idr);
139 assert(idr_alloc(&idr, item, i, i + 1, GFP_NOWAIT) == i);
144 idr_for_each(&idr, item_idr_free, &idr);
145 idr_destroy(&idr);
152 DEFINE_IDR(idr);
153 idr_init_base(&idr, base);
159 assert(idr_alloc(&idr, item, indices[i], indices[i+1],
164 idr_get_next(&idr, &nextid);
169 idr_for_each(&idr, item_idr_free, &idr);
170 idr_destroy(&idr);
180 void idr_u32_test1(struct idr *idr, u32 handle)
187 BUG_ON(idr_alloc_u32(idr, DUMMY_PTR, &id, id, GFP_KERNEL));
189 BUG_ON(idr_alloc_u32(idr, DUMMY_PTR, &id, id, GFP_KERNEL) != -ENOSPC);
193 ptr = idr_get_next(idr, &sid);
201 idr_for_each(idr, idr_u32_cb, NULL);
206 BUG_ON(idr_remove(idr, id) != DUMMY_PTR);
207 BUG_ON(!idr_is_empty(idr));
212 DEFINE_IDR(idr);
213 idr_init_base(&idr, base);
214 idr_u32_test1(&idr, 10);
215 idr_u32_test1(&idr, 0x7fffffff);
216 idr_u32_test1(&idr, 0x80000000);
217 idr_u32_test1(&idr, 0x80000001);
218 idr_u32_test1(&idr, 0xffe00000);
219 idr_u32_test1(&idr, 0xffffffff);
222 static void idr_align_test(struct idr *idr)
229 BUG_ON(idr_alloc(idr, &name[i], 0, 0, GFP_KERNEL) != i);
230 idr_for_each_entry(idr, entry, id);
232 idr_destroy(idr);
235 BUG_ON(idr_alloc(idr, &name[i], 0, 0, GFP_KERNEL) != i - 1);
236 idr_for_each_entry(idr, entry, id);
238 idr_destroy(idr);
241 BUG_ON(idr_alloc(idr, &name[i], 0, 0, GFP_KERNEL) != i - 2);
242 idr_for_each_entry(idr, entry, id);
244 idr_destroy(idr);
247 BUG_ON(idr_alloc(idr, &name[i], 0, 0, GFP_KERNEL) != i - 3);
248 idr_for_each_entry(idr, entry, id);
250 idr_destroy(idr);
253 BUG_ON(idr_alloc(idr, &name[i], 0, 0, GFP_KERNEL) != 0);
254 BUG_ON(idr_alloc(idr, &name[i + 1], 0, 0, GFP_KERNEL) != 1);
255 idr_for_each_entry(idr, entry, id);
256 idr_remove(idr, 1);
257 idr_for_each_entry(idr, entry, id);
258 idr_remove(idr, 0);
259 BUG_ON(!idr_is_empty(idr));
263 BUG_ON(idr_alloc(idr, NULL, 0, 0, GFP_KERNEL) != 0);
264 idr_for_each_entry(idr, entry, id);
265 idr_replace(idr, &name[i], 0);
266 idr_for_each_entry(idr, entry, id);
267 BUG_ON(idr_find(idr, 0) != &name[i]);
268 idr_remove(idr, 0);
272 BUG_ON(idr_alloc(idr, &name[i], 0, 0, GFP_KERNEL) != 0);
273 BUG_ON(idr_alloc(idr, NULL, 0, 0, GFP_KERNEL) != 1);
274 idr_remove(idr, 1);
275 idr_for_each_entry(idr, entry, id);
276 idr_replace(idr, &name[i + 1], 0);
277 idr_for_each_entry(idr, entry, id);
278 idr_remove(idr, 0);
334 DEFINE_IDR(idr);
338 assert(idr_alloc(&idr, item, 0, 20000, GFP_KERNEL) == i);
341 assert(idr_alloc(&idr, DUMMY_PTR, 5, 30, GFP_KERNEL) < 0);
344 item_idr_remove(&idr, i);
346 idr_remove(&idr, 3);
348 idr_for_each(&idr, item_idr_free, &idr);
349 idr_destroy(&idr);
351 assert(idr_is_empty(&idr));
353 idr_remove(&idr, 3);
354 idr_remove(&idr, 0);
356 assert(idr_alloc(&idr, DUMMY_PTR, 0, 0, GFP_KERNEL) == 0);
357 idr_remove(&idr, 1);
359 assert(idr_alloc(&idr, DUMMY_PTR, 0, 0, GFP_KERNEL) == i);
360 idr_remove(&idr, 1 << 30);
361 idr_destroy(&idr);
365 assert(idr_alloc(&idr, item, i, i + 10, GFP_KERNEL) == i);
367 assert(idr_alloc(&idr, DUMMY_PTR, i - 2, i, GFP_KERNEL) == -ENOSPC);
368 assert(idr_alloc(&idr, DUMMY_PTR, i - 2, i + 10, GFP_KERNEL) == -ENOSPC);
370 idr_for_each(&idr, item_idr_free, &idr);
371 idr_destroy(&idr);
372 idr_destroy(&idr);
374 assert(idr_is_empty(&idr));
376 idr_set_cursor(&idr, INT_MAX - 3UL);
385 id = idr_alloc_cyclic(&idr, item, 0, 0, GFP_KERNEL);
389 idr_for_each(&idr, item_idr_free, &idr);
390 idr_destroy(&idr);
391 assert(idr_is_empty(&idr));
395 assert(idr_alloc(&idr, item, 1, 20000, GFP_KERNEL) == i);
398 idr_for_each(&idr, item_idr_free, &idr);
399 idr_destroy(&idr);
411 idr_align_test(&idr);