Skip to content

Commit 62fd525

Browse files
Matthew Wilcoxtorvalds
authored andcommitted
radix tree test suite: Test radix_tree_replace_slot() for multiorder 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]>
1 parent 9c0e28a commit 62fd525

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

tools/testing/radix-tree/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
CFLAGS += -I. -g -Wall -D_LGPL_SOURCE
2+
CFLAGS += -I. -g -O2 -Wall -D_LGPL_SOURCE
33
LDFLAGS += -lpthread -lurcu
44
TARGETS = main
55
OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \

tools/testing/radix-tree/multiorder.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static void multiorder_check(unsigned long index, int order)
124124
unsigned long i;
125125
unsigned long min = index & ~((1UL << order) - 1);
126126
unsigned long max = min + (1UL << order);
127+
void **slot;
128+
struct item *item2 = item_create(min);
127129
RADIX_TREE(tree, GFP_KERNEL);
128130

129131
printf("Multiorder index %ld, order %d\n", index, order);
@@ -139,13 +141,19 @@ static void multiorder_check(unsigned long index, int order)
139141
item_check_absent(&tree, i);
140142
for (i = max; i < 2*max; i++)
141143
item_check_absent(&tree, i);
144+
for (i = min; i < max; i++)
145+
assert(radix_tree_insert(&tree, i, item2) == -EEXIST);
146+
147+
slot = radix_tree_lookup_slot(&tree, index);
148+
free(*slot);
149+
radix_tree_replace_slot(slot, item2);
142150
for (i = min; i < max; i++) {
143-
static void *entry = (void *)
144-
(0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY);
145-
assert(radix_tree_insert(&tree, i, entry) == -EEXIST);
151+
struct item *item = item_lookup(&tree, i);
152+
assert(item != 0);
153+
assert(item->index == min);
146154
}
147155

148-
assert(item_delete(&tree, index) != 0);
156+
assert(item_delete(&tree, min) != 0);
149157

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

0 commit comments

Comments
 (0)