Skip to content

Commit

Permalink
radix-tree: add test for radix_tree_locate_item()
Browse files Browse the repository at this point in the history
Add a unit test that provides coverage for the bug fixed in the commit
entitled "radix-tree: rewrite radix_tree_locate_item fix" from Hugh
Dickins.  I've verified that this test fails before his patch due to
miscalculated 'index' values in __locate() in lib/radix-tree.c, and
passes with his fix.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ross Zwisler <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ross Zwisler authored and torvalds committed May 21, 2016
1 parent 0a2efc6 commit eb73f7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions tools/testing/radix-tree/linux/init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* An empty file stub that allows radix-tree.c to compile. */
15 changes: 14 additions & 1 deletion tools/testing/radix-tree/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void copy_tag_check(void)
item_kill_tree(&tree);
}

void __locate_check(struct radix_tree_root *tree, unsigned long index,
static void __locate_check(struct radix_tree_root *tree, unsigned long index,
unsigned order)
{
struct item *item;
Expand All @@ -248,12 +248,25 @@ void __locate_check(struct radix_tree_root *tree, unsigned long index,
}
}

static void __order_0_locate_check(void)
{
RADIX_TREE(tree, GFP_KERNEL);
int i;

for (i = 0; i < 50; i++)
__locate_check(&tree, rand() % INT_MAX, 0);

item_kill_tree(&tree);
}

static void locate_check(void)
{
RADIX_TREE(tree, GFP_KERNEL);
unsigned order;
unsigned long offset, index;

__order_0_locate_check();

for (order = 0; order < 20; order++) {
for (offset = 0; offset < (1 << (order + 3));
offset += (1UL << order)) {
Expand Down

0 comments on commit eb73f7f

Please sign in to comment.