Skip to content

Commit

Permalink
radix tree test suite: Test radix_tree_replace_slot() for multiorder …
Browse files Browse the repository at this point in the history
…entries

When we replace a multiorder entry, check that all indices reflect the
new value.

Also, compile the test suite with -O2, which shows other problems with
the code due to some dodgy pointer operations in the radix tree code.

Signed-off-by: Matthew Wilcox <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox authored and torvalds committed Sep 25, 2016
1 parent 9c0e28a commit 62fd525
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tools/testing/radix-tree/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

CFLAGS += -I. -g -Wall -D_LGPL_SOURCE
CFLAGS += -I. -g -O2 -Wall -D_LGPL_SOURCE
LDFLAGS += -lpthread -lurcu
TARGETS = main
OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \
Expand Down
16 changes: 12 additions & 4 deletions tools/testing/radix-tree/multiorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ static void multiorder_check(unsigned long index, int order)
unsigned long i;
unsigned long min = index & ~((1UL << order) - 1);
unsigned long max = min + (1UL << order);
void **slot;
struct item *item2 = item_create(min);
RADIX_TREE(tree, GFP_KERNEL);

printf("Multiorder index %ld, order %d\n", index, order);
Expand All @@ -139,13 +141,19 @@ static void multiorder_check(unsigned long index, int order)
item_check_absent(&tree, i);
for (i = max; i < 2*max; i++)
item_check_absent(&tree, i);
for (i = min; i < max; i++)
assert(radix_tree_insert(&tree, i, item2) == -EEXIST);

slot = radix_tree_lookup_slot(&tree, index);
free(*slot);
radix_tree_replace_slot(slot, item2);
for (i = min; i < max; i++) {
static void *entry = (void *)
(0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY);
assert(radix_tree_insert(&tree, i, entry) == -EEXIST);
struct item *item = item_lookup(&tree, i);
assert(item != 0);
assert(item->index == min);
}

assert(item_delete(&tree, index) != 0);
assert(item_delete(&tree, min) != 0);

for (i = 0; i < 2*max; i++)
item_check_absent(&tree, i);
Expand Down

0 comments on commit 62fd525

Please sign in to comment.