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.c78
1 files changed, 75 insertions, 3 deletions
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index a26098c6123d..30cd0b296f1a 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -153,6 +153,30 @@ void idr_nowait_test(void)
153 idr_destroy(&idr); 153 idr_destroy(&idr);
154} 154}
155 155
156void idr_get_next_test(void)
157{
158 unsigned long i;
159 int nextid;
160 DEFINE_IDR(idr);
161
162 int indices[] = {4, 7, 9, 15, 65, 128, 1000, 99999, 0};
163
164 for(i = 0; indices[i]; i++) {
165 struct item *item = item_create(indices[i], 0);
166 assert(idr_alloc(&idr, item, indices[i], indices[i+1],
167 GFP_KERNEL) == indices[i]);
168 }
169
170 for(i = 0, nextid = 0; indices[i]; i++) {
171 idr_get_next(&idr, &nextid);
172 assert(nextid == indices[i]);
173 nextid++;
174 }
175
176 idr_for_each(&idr, item_idr_free, &idr);
177 idr_destroy(&idr);
178}
179
156void idr_checks(void) 180void idr_checks(void)
157{ 181{
158 unsigned long i; 182 unsigned long i;
@@ -202,6 +226,7 @@ void idr_checks(void)
202 idr_alloc_test(); 226 idr_alloc_test();
203 idr_null_test(); 227 idr_null_test();
204 idr_nowait_test(); 228 idr_nowait_test();
229 idr_get_next_test();
205} 230}
206 231
207/* 232/*
@@ -338,7 +363,7 @@ void ida_check_random(void)
338{ 363{
339 DEFINE_IDA(ida); 364 DEFINE_IDA(ida);
340 DECLARE_BITMAP(bitmap, 2048); 365 DECLARE_BITMAP(bitmap, 2048);
341 int id; 366 int id, err;
342 unsigned int i; 367 unsigned int i;
343 time_t s = time(NULL); 368 time_t s = time(NULL);
344 369
@@ -352,8 +377,11 @@ void ida_check_random(void)
352 ida_remove(&ida, bit); 377 ida_remove(&ida, bit);
353 } else { 378 } else {
354 __set_bit(bit, bitmap); 379 __set_bit(bit, bitmap);
355 ida_pre_get(&ida, GFP_KERNEL); 380 do {
356 assert(!ida_get_new_above(&ida, bit, &id)); 381 ida_pre_get(&ida, GFP_KERNEL);
382 err = ida_get_new_above(&ida, bit, &id);
383 } while (err == -ENOMEM);
384 assert(!err);
357 assert(id == bit); 385 assert(id == bit);
358 } 386 }
359 } 387 }
@@ -362,6 +390,24 @@ void ida_check_random(void)
362 goto repeat; 390 goto repeat;
363} 391}
364 392
393void ida_simple_get_remove_test(void)
394{
395 DEFINE_IDA(ida);
396 unsigned long i;
397
398 for (i = 0; i < 10000; i++) {
399 assert(ida_simple_get(&ida, 0, 20000, GFP_KERNEL) == i);
400 }
401 assert(ida_simple_get(&ida, 5, 30, GFP_KERNEL) < 0);
402
403 for (i = 0; i < 10000; i++) {
404 ida_simple_remove(&ida, i);
405 }
406 assert(ida_is_empty(&ida));
407
408 ida_destroy(&ida);
409}
410
365void ida_checks(void) 411void ida_checks(void)
366{ 412{
367 DEFINE_IDA(ida); 413 DEFINE_IDA(ida);
@@ -428,15 +474,41 @@ void ida_checks(void)
428 ida_check_max(); 474 ida_check_max();
429 ida_check_conv(); 475 ida_check_conv();
430 ida_check_random(); 476 ida_check_random();
477 ida_simple_get_remove_test();
431 478
432 radix_tree_cpu_dead(1); 479 radix_tree_cpu_dead(1);
433} 480}
434 481
482static void *ida_random_fn(void *arg)
483{
484 rcu_register_thread();
485 ida_check_random();
486 rcu_unregister_thread();
487 return NULL;
488}
489
490void ida_thread_tests(void)
491{
492 pthread_t threads[10];
493 int i;
494
495 for (i = 0; i < ARRAY_SIZE(threads); i++)
496 if (pthread_create(&threads[i], NULL, ida_random_fn, NULL)) {
497 perror("creating ida thread");
498 exit(1);
499 }
500
501 while (i--)
502 pthread_join(threads[i], NULL);
503}
504
435int __weak main(void) 505int __weak main(void)
436{ 506{
437 radix_tree_init(); 507 radix_tree_init();
438 idr_checks(); 508 idr_checks();
439 ida_checks(); 509 ida_checks();
510 ida_thread_tests();
511 radix_tree_cpu_dead(1);
440 rcu_barrier(); 512 rcu_barrier();
441 if (nr_allocated) 513 if (nr_allocated)
442 printf("nr_allocated = %d\n", nr_allocated); 514 printf("nr_allocated = %d\n", nr_allocated);