diff options
author | Matthew Wilcox <willy@infradead.org> | 2018-06-18 18:10:32 -0400 |
---|---|---|
committer | Matthew Wilcox <willy@infradead.org> | 2018-08-21 23:54:20 -0400 |
commit | 5c78b0b1ebe16fbae39a1cada79ab067965828f5 (patch) | |
tree | a46125bb6d45627bbb8026ba337f1d0518ffcf57 | |
parent | 161b47e31f9912947a3a72dcb161c79978a1fe04 (diff) |
test_ida: Convert check_ida_conv to new API
Move as much as possible to kernel space; leave the parts in user space
that rely on checking memory allocation failures to detect the
transition between an exceptional entry and a bitmap.
Signed-off-by: Matthew Wilcox <willy@infradead.org>
-rw-r--r-- | lib/test_ida.c | 30 | ||||
-rw-r--r-- | tools/testing/radix-tree/idr-test.c | 56 |
2 files changed, 40 insertions, 46 deletions
diff --git a/lib/test_ida.c b/lib/test_ida.c index 44174ec9f5bf..eaee9a28f325 100644 --- a/lib/test_ida.c +++ b/lib/test_ida.c | |||
@@ -69,6 +69,35 @@ static void ida_check_max(struct ida *ida) | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | /* | ||
73 | * Check handling of conversions between exceptional entries and full bitmaps. | ||
74 | */ | ||
75 | static void ida_check_conv(struct ida *ida) | ||
76 | { | ||
77 | unsigned long i; | ||
78 | |||
79 | for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) { | ||
80 | IDA_BUG_ON(ida, ida_alloc_min(ida, i + 1, GFP_KERNEL) != i + 1); | ||
81 | IDA_BUG_ON(ida, ida_alloc_min(ida, i + BITS_PER_LONG, | ||
82 | GFP_KERNEL) != i + BITS_PER_LONG); | ||
83 | ida_free(ida, i + 1); | ||
84 | ida_free(ida, i + BITS_PER_LONG); | ||
85 | IDA_BUG_ON(ida, !ida_is_empty(ida)); | ||
86 | } | ||
87 | |||
88 | for (i = 0; i < IDA_BITMAP_BITS * 2; i++) | ||
89 | IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); | ||
90 | for (i = IDA_BITMAP_BITS * 2; i > 0; i--) | ||
91 | ida_free(ida, i - 1); | ||
92 | IDA_BUG_ON(ida, !ida_is_empty(ida)); | ||
93 | |||
94 | for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) | ||
95 | IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); | ||
96 | for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) | ||
97 | ida_free(ida, i - 1); | ||
98 | IDA_BUG_ON(ida, !ida_is_empty(ida)); | ||
99 | } | ||
100 | |||
72 | static int ida_checks(void) | 101 | static int ida_checks(void) |
73 | { | 102 | { |
74 | DEFINE_IDA(ida); | 103 | DEFINE_IDA(ida); |
@@ -78,6 +107,7 @@ static int ida_checks(void) | |||
78 | ida_check_leaf(&ida, 1024); | 107 | ida_check_leaf(&ida, 1024); |
79 | ida_check_leaf(&ida, 1024 * 64); | 108 | ida_check_leaf(&ida, 1024 * 64); |
80 | ida_check_max(&ida); | 109 | ida_check_max(&ida); |
110 | ida_check_conv(&ida); | ||
81 | 111 | ||
82 | printk("IDA: %u of %u tests passed\n", tests_passed, tests_run); | 112 | printk("IDA: %u of %u tests passed\n", tests_passed, tests_run); |
83 | return (tests_run != tests_passed) ? 0 : -EINVAL; | 113 | return (tests_run != tests_passed) ? 0 : -EINVAL; |
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c index bd9699327f95..c6026cfe3145 100644 --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c | |||
@@ -339,59 +339,23 @@ void ida_check_nomem(void) | |||
339 | /* | 339 | /* |
340 | * Check handling of conversions between exceptional entries and full bitmaps. | 340 | * Check handling of conversions between exceptional entries and full bitmaps. |
341 | */ | 341 | */ |
342 | void ida_check_conv(void) | 342 | void ida_check_conv_user(void) |
343 | { | 343 | { |
344 | DEFINE_IDA(ida); | 344 | DEFINE_IDA(ida); |
345 | int id; | ||
346 | unsigned long i; | 345 | unsigned long i; |
347 | 346 | ||
348 | for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) { | ||
349 | assert(ida_pre_get(&ida, GFP_KERNEL)); | ||
350 | assert(!ida_get_new_above(&ida, i + 1, &id)); | ||
351 | assert(id == i + 1); | ||
352 | assert(!ida_get_new_above(&ida, i + BITS_PER_LONG, &id)); | ||
353 | assert(id == i + BITS_PER_LONG); | ||
354 | ida_remove(&ida, i + 1); | ||
355 | ida_remove(&ida, i + BITS_PER_LONG); | ||
356 | assert(ida_is_empty(&ida)); | ||
357 | } | ||
358 | |||
359 | assert(ida_pre_get(&ida, GFP_KERNEL)); | ||
360 | |||
361 | for (i = 0; i < IDA_BITMAP_BITS * 2; i++) { | ||
362 | assert(ida_pre_get(&ida, GFP_KERNEL)); | ||
363 | assert(!ida_get_new(&ida, &id)); | ||
364 | assert(id == i); | ||
365 | } | ||
366 | |||
367 | for (i = IDA_BITMAP_BITS * 2; i > 0; i--) { | ||
368 | ida_remove(&ida, i - 1); | ||
369 | } | ||
370 | assert(ida_is_empty(&ida)); | ||
371 | |||
372 | for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) { | ||
373 | assert(ida_pre_get(&ida, GFP_KERNEL)); | ||
374 | assert(!ida_get_new(&ida, &id)); | ||
375 | assert(id == i); | ||
376 | } | ||
377 | |||
378 | for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) { | ||
379 | ida_remove(&ida, i - 1); | ||
380 | } | ||
381 | assert(ida_is_empty(&ida)); | ||
382 | |||
383 | radix_tree_cpu_dead(1); | 347 | radix_tree_cpu_dead(1); |
384 | for (i = 0; i < 1000000; i++) { | 348 | for (i = 0; i < 1000000; i++) { |
385 | int err = ida_get_new(&ida, &id); | 349 | int id = ida_alloc(&ida, GFP_NOWAIT); |
386 | if (err == -EAGAIN) { | 350 | if (id == -ENOMEM) { |
387 | assert((i % IDA_BITMAP_BITS) == (BITS_PER_LONG - 2)); | 351 | IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) != |
388 | assert(ida_pre_get(&ida, GFP_KERNEL)); | 352 | BITS_PER_LONG - 2); |
389 | err = ida_get_new(&ida, &id); | 353 | id = ida_alloc(&ida, GFP_KERNEL); |
390 | } else { | 354 | } else { |
391 | assert((i % IDA_BITMAP_BITS) != (BITS_PER_LONG - 2)); | 355 | IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) == |
356 | BITS_PER_LONG - 2); | ||
392 | } | 357 | } |
393 | assert(!err); | 358 | IDA_BUG_ON(&ida, id != i); |
394 | assert(id == i); | ||
395 | } | 359 | } |
396 | ida_destroy(&ida); | 360 | ida_destroy(&ida); |
397 | } | 361 | } |
@@ -507,7 +471,7 @@ void user_ida_checks(void) | |||
507 | ida_destroy(&ida); | 471 | ida_destroy(&ida); |
508 | assert(ida_is_empty(&ida)); | 472 | assert(ida_is_empty(&ida)); |
509 | 473 | ||
510 | ida_check_conv(); | 474 | ida_check_conv_user(); |
511 | ida_check_random(); | 475 | ida_check_random(); |
512 | ida_simple_get_remove_test(); | 476 | ida_simple_get_remove_test(); |
513 | 477 | ||