Skip to content

Commit 5c78b0b

Browse files
author
Matthew Wilcox
committed
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>
1 parent 161b47e commit 5c78b0b

File tree

2 files changed

+40
-46
lines changed

2 files changed

+40
-46
lines changed

lib/test_ida.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ static void ida_check_max(struct ida *ida)
6969
}
7070
}
7171

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+
72101
static int ida_checks(void)
73102
{
74103
DEFINE_IDA(ida);
@@ -78,6 +107,7 @@ static int ida_checks(void)
78107
ida_check_leaf(&ida, 1024);
79108
ida_check_leaf(&ida, 1024 * 64);
80109
ida_check_max(&ida);
110+
ida_check_conv(&ida);
81111

82112
printk("IDA: %u of %u tests passed\n", tests_passed, tests_run);
83113
return (tests_run != tests_passed) ? 0 : -EINVAL;

tools/testing/radix-tree/idr-test.c

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -339,59 +339,23 @@ void ida_check_nomem(void)
339339
/*
340340
* Check handling of conversions between exceptional entries and full bitmaps.
341341
*/
342-
void ida_check_conv(void)
342+
void ida_check_conv_user(void)
343343
{
344344
DEFINE_IDA(ida);
345-
int id;
346345
unsigned long i;
347346

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-
383347
radix_tree_cpu_dead(1);
384348
for (i = 0; i < 1000000; i++) {
385-
int err = ida_get_new(&ida, &id);
386-
if (err == -EAGAIN) {
387-
assert((i % IDA_BITMAP_BITS) == (BITS_PER_LONG - 2));
388-
assert(ida_pre_get(&ida, GFP_KERNEL));
389-
err = ida_get_new(&ida, &id);
349+
int id = ida_alloc(&ida, GFP_NOWAIT);
350+
if (id == -ENOMEM) {
351+
IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) !=
352+
BITS_PER_LONG - 2);
353+
id = ida_alloc(&ida, GFP_KERNEL);
390354
} 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);
392357
}
393-
assert(!err);
394-
assert(id == i);
358+
IDA_BUG_ON(&ida, id != i);
395359
}
396360
ida_destroy(&ida);
397361
}
@@ -507,7 +471,7 @@ void user_ida_checks(void)
507471
ida_destroy(&ida);
508472
assert(ida_is_empty(&ida));
509473

510-
ida_check_conv();
474+
ida_check_conv_user();
511475
ida_check_random();
512476
ida_simple_get_remove_test();
513477

0 commit comments

Comments
 (0)