diff options
-rw-r--r-- | tools/testing/radix-tree/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/radix-tree/main.c | 2 | ||||
-rw-r--r-- | tools/testing/radix-tree/multiorder.c | 58 | ||||
-rw-r--r-- | tools/testing/radix-tree/test.c | 13 | ||||
-rw-r--r-- | tools/testing/radix-tree/test.h | 6 |
5 files changed, 76 insertions, 5 deletions
diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/Makefile index 43febba864bd..3b530467148e 100644 --- a/tools/testing/radix-tree/Makefile +++ b/tools/testing/radix-tree/Makefile | |||
@@ -3,7 +3,7 @@ CFLAGS += -I. -g -Wall -D_LGPL_SOURCE | |||
3 | LDFLAGS += -lpthread -lurcu | 3 | LDFLAGS += -lpthread -lurcu |
4 | TARGETS = main | 4 | TARGETS = main |
5 | OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \ | 5 | OFILES = main.o radix-tree.o linux.o test.o tag_check.o find_next_bit.o \ |
6 | regression1.o regression2.o regression3.o | 6 | regression1.o regression2.o regression3.o multiorder.o |
7 | 7 | ||
8 | targets: $(TARGETS) | 8 | targets: $(TARGETS) |
9 | 9 | ||
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c index 122c8b9be17e..b6a700b00cce 100644 --- a/tools/testing/radix-tree/main.c +++ b/tools/testing/radix-tree/main.c | |||
@@ -275,6 +275,8 @@ static void single_thread_tests(bool long_run) | |||
275 | int i; | 275 | int i; |
276 | 276 | ||
277 | printf("starting single_thread_tests: %d allocated\n", nr_allocated); | 277 | printf("starting single_thread_tests: %d allocated\n", nr_allocated); |
278 | multiorder_checks(); | ||
279 | printf("after multiorder_check: %d allocated\n", nr_allocated); | ||
278 | locate_check(); | 280 | locate_check(); |
279 | printf("after locate_check: %d allocated\n", nr_allocated); | 281 | printf("after locate_check: %d allocated\n", nr_allocated); |
280 | tag_check(); | 282 | tag_check(); |
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c new file mode 100644 index 000000000000..cfe718c78eb6 --- /dev/null +++ b/tools/testing/radix-tree/multiorder.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * multiorder.c: Multi-order radix tree entry testing | ||
3 | * Copyright (c) 2016 Intel Corporation | ||
4 | * Author: Ross Zwisler <ross.zwisler@linux.intel.com> | ||
5 | * Author: Matthew Wilcox <matthew.r.wilcox@intel.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | ||
8 | * under the terms and conditions of the GNU General Public License, | ||
9 | * version 2, as published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
14 | * more details. | ||
15 | */ | ||
16 | #include <linux/radix-tree.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/errno.h> | ||
19 | |||
20 | #include "test.h" | ||
21 | |||
22 | static void multiorder_check(unsigned long index, int order) | ||
23 | { | ||
24 | unsigned long i; | ||
25 | unsigned long min = index & ~((1UL << order) - 1); | ||
26 | unsigned long max = min + (1UL << order); | ||
27 | RADIX_TREE(tree, GFP_KERNEL); | ||
28 | |||
29 | printf("Multiorder index %ld, order %d\n", index, order); | ||
30 | |||
31 | assert(item_insert_order(&tree, index, order) == 0); | ||
32 | |||
33 | for (i = min; i < max; i++) { | ||
34 | struct item *item = item_lookup(&tree, i); | ||
35 | assert(item != 0); | ||
36 | assert(item->index == index); | ||
37 | } | ||
38 | for (i = 0; i < min; i++) | ||
39 | item_check_absent(&tree, i); | ||
40 | for (i = max; i < 2*max; i++) | ||
41 | item_check_absent(&tree, i); | ||
42 | |||
43 | assert(item_delete(&tree, index) != 0); | ||
44 | |||
45 | for (i = 0; i < 2*max; i++) | ||
46 | item_check_absent(&tree, i); | ||
47 | } | ||
48 | |||
49 | void multiorder_checks(void) | ||
50 | { | ||
51 | int i; | ||
52 | |||
53 | for (i = 0; i < 20; i++) { | ||
54 | multiorder_check(200, i); | ||
55 | multiorder_check(0, i); | ||
56 | multiorder_check((1UL << i) + 1, i); | ||
57 | } | ||
58 | } | ||
diff --git a/tools/testing/radix-tree/test.c b/tools/testing/radix-tree/test.c index 2bebf34cdc27..da54f11e8ba7 100644 --- a/tools/testing/radix-tree/test.c +++ b/tools/testing/radix-tree/test.c | |||
@@ -24,14 +24,21 @@ int item_tag_get(struct radix_tree_root *root, unsigned long index, int tag) | |||
24 | return radix_tree_tag_get(root, index, tag); | 24 | return radix_tree_tag_get(root, index, tag); |
25 | } | 25 | } |
26 | 26 | ||
27 | int __item_insert(struct radix_tree_root *root, struct item *item) | 27 | int __item_insert(struct radix_tree_root *root, struct item *item, |
28 | unsigned order) | ||
28 | { | 29 | { |
29 | return radix_tree_insert(root, item->index, item); | 30 | return __radix_tree_insert(root, item->index, order, item); |
30 | } | 31 | } |
31 | 32 | ||
32 | int item_insert(struct radix_tree_root *root, unsigned long index) | 33 | int item_insert(struct radix_tree_root *root, unsigned long index) |
33 | { | 34 | { |
34 | return __item_insert(root, item_create(index)); | 35 | return __item_insert(root, item_create(index), 0); |
36 | } | ||
37 | |||
38 | int item_insert_order(struct radix_tree_root *root, unsigned long index, | ||
39 | unsigned order) | ||
40 | { | ||
41 | return __item_insert(root, item_create(index), order); | ||
35 | } | 42 | } |
36 | 43 | ||
37 | int item_delete(struct radix_tree_root *root, unsigned long index) | 44 | int item_delete(struct radix_tree_root *root, unsigned long index) |
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h index 4e1d95faaa94..53cb595db44a 100644 --- a/tools/testing/radix-tree/test.h +++ b/tools/testing/radix-tree/test.h | |||
@@ -8,8 +8,11 @@ struct item { | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | struct item *item_create(unsigned long index); | 10 | struct item *item_create(unsigned long index); |
11 | int __item_insert(struct radix_tree_root *root, struct item *item); | 11 | int __item_insert(struct radix_tree_root *root, struct item *item, |
12 | unsigned order); | ||
12 | int item_insert(struct radix_tree_root *root, unsigned long index); | 13 | int item_insert(struct radix_tree_root *root, unsigned long index); |
14 | int item_insert_order(struct radix_tree_root *root, unsigned long index, | ||
15 | unsigned order); | ||
13 | int item_delete(struct radix_tree_root *root, unsigned long index); | 16 | int item_delete(struct radix_tree_root *root, unsigned long index); |
14 | struct item *item_lookup(struct radix_tree_root *root, unsigned long index); | 17 | struct item *item_lookup(struct radix_tree_root *root, unsigned long index); |
15 | 18 | ||
@@ -23,6 +26,7 @@ void item_full_scan(struct radix_tree_root *root, unsigned long start, | |||
23 | void item_kill_tree(struct radix_tree_root *root); | 26 | void item_kill_tree(struct radix_tree_root *root); |
24 | 27 | ||
25 | void tag_check(void); | 28 | void tag_check(void); |
29 | void multiorder_checks(void); | ||
26 | 30 | ||
27 | struct item * | 31 | struct item * |
28 | item_tag_set(struct radix_tree_root *root, unsigned long index, int tag); | 32 | item_tag_set(struct radix_tree_root *root, unsigned long index, int tag); |