diff options
author | Matthew Wilcox <mawilcox@microsoft.com> | 2016-12-14 18:08:23 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-14 19:04:10 -0500 |
commit | 101d9607fffefdfc9e3922f0ac9061a61edda1b0 (patch) | |
tree | e4abfb429a84337a524b753cfb50f665c1331750 | |
parent | 3ad75f8a1d9b047989059c67afc38d57161270e9 (diff) |
radix tree test suite: record order in each item
This probably doubles the size of each item allocated by the test suite
but it lets us check a few more things, and may be needed for upcoming
API changes that require the caller pass in the order of the entry.
Link: http://lkml.kernel.org/r/1480369871-5271-46-git-send-email-mawilcox@linuxonhyperv.com
Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | tools/testing/radix-tree/multiorder.c | 2 | ||||
-rw-r--r-- | tools/testing/radix-tree/test.c | 29 | ||||
-rw-r--r-- | tools/testing/radix-tree/test.h | 6 |
3 files changed, 23 insertions, 14 deletions
diff --git a/tools/testing/radix-tree/multiorder.c b/tools/testing/radix-tree/multiorder.c index d1be94667a30..8d5865c95664 100644 --- a/tools/testing/radix-tree/multiorder.c +++ b/tools/testing/radix-tree/multiorder.c | |||
@@ -125,7 +125,7 @@ static void multiorder_check(unsigned long index, int order) | |||
125 | unsigned long min = index & ~((1UL << order) - 1); | 125 | unsigned long min = index & ~((1UL << order) - 1); |
126 | unsigned long max = min + (1UL << order); | 126 | unsigned long max = min + (1UL << order); |
127 | void **slot; | 127 | void **slot; |
128 | struct item *item2 = item_create(min); | 128 | struct item *item2 = item_create(min, order); |
129 | RADIX_TREE(tree, GFP_KERNEL); | 129 | RADIX_TREE(tree, GFP_KERNEL); |
130 | 130 | ||
131 | printf("Multiorder index %ld, order %d\n", index, order); | 131 | printf("Multiorder index %ld, order %d\n", index, order); |
diff --git a/tools/testing/radix-tree/test.c b/tools/testing/radix-tree/test.c index 6f8dafc797ce..0de548939a2e 100644 --- a/tools/testing/radix-tree/test.c +++ b/tools/testing/radix-tree/test.c | |||
@@ -24,21 +24,29 @@ 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) | ||
29 | { | 28 | { |
30 | return __radix_tree_insert(root, item->index, order, item); | 29 | return __radix_tree_insert(root, item->index, item->order, item); |
31 | } | 30 | } |
32 | 31 | ||
33 | int item_insert(struct radix_tree_root *root, unsigned long index) | 32 | int item_insert(struct radix_tree_root *root, unsigned long index) |
34 | { | 33 | { |
35 | return __item_insert(root, item_create(index), 0); | 34 | return __item_insert(root, item_create(index, 0)); |
36 | } | 35 | } |
37 | 36 | ||
38 | int item_insert_order(struct radix_tree_root *root, unsigned long index, | 37 | int item_insert_order(struct radix_tree_root *root, unsigned long index, |
39 | unsigned order) | 38 | unsigned order) |
40 | { | 39 | { |
41 | return __item_insert(root, item_create(index), order); | 40 | return __item_insert(root, item_create(index, order)); |
41 | } | ||
42 | |||
43 | void item_sanity(struct item *item, unsigned long index) | ||
44 | { | ||
45 | unsigned long mask; | ||
46 | assert(!radix_tree_is_internal_node(item)); | ||
47 | assert(item->order < BITS_PER_LONG); | ||
48 | mask = (1UL << item->order) - 1; | ||
49 | assert((item->index | mask) == (index | mask)); | ||
42 | } | 50 | } |
43 | 51 | ||
44 | int item_delete(struct radix_tree_root *root, unsigned long index) | 52 | int item_delete(struct radix_tree_root *root, unsigned long index) |
@@ -46,18 +54,19 @@ int item_delete(struct radix_tree_root *root, unsigned long index) | |||
46 | struct item *item = radix_tree_delete(root, index); | 54 | struct item *item = radix_tree_delete(root, index); |
47 | 55 | ||
48 | if (item) { | 56 | if (item) { |
49 | assert(item->index == index); | 57 | item_sanity(item, index); |
50 | free(item); | 58 | free(item); |
51 | return 1; | 59 | return 1; |
52 | } | 60 | } |
53 | return 0; | 61 | return 0; |
54 | } | 62 | } |
55 | 63 | ||
56 | struct item *item_create(unsigned long index) | 64 | struct item *item_create(unsigned long index, unsigned int order) |
57 | { | 65 | { |
58 | struct item *ret = malloc(sizeof(*ret)); | 66 | struct item *ret = malloc(sizeof(*ret)); |
59 | 67 | ||
60 | ret->index = index; | 68 | ret->index = index; |
69 | ret->order = order; | ||
61 | return ret; | 70 | return ret; |
62 | } | 71 | } |
63 | 72 | ||
@@ -66,8 +75,8 @@ void item_check_present(struct radix_tree_root *root, unsigned long index) | |||
66 | struct item *item; | 75 | struct item *item; |
67 | 76 | ||
68 | item = radix_tree_lookup(root, index); | 77 | item = radix_tree_lookup(root, index); |
69 | assert(item != 0); | 78 | assert(item != NULL); |
70 | assert(item->index == index); | 79 | item_sanity(item, index); |
71 | } | 80 | } |
72 | 81 | ||
73 | struct item *item_lookup(struct radix_tree_root *root, unsigned long index) | 82 | struct item *item_lookup(struct radix_tree_root *root, unsigned long index) |
@@ -80,7 +89,7 @@ void item_check_absent(struct radix_tree_root *root, unsigned long index) | |||
80 | struct item *item; | 89 | struct item *item; |
81 | 90 | ||
82 | item = radix_tree_lookup(root, index); | 91 | item = radix_tree_lookup(root, index); |
83 | assert(item == 0); | 92 | assert(item == NULL); |
84 | } | 93 | } |
85 | 94 | ||
86 | /* | 95 | /* |
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h index 215ab77a56e3..423c528aaee9 100644 --- a/tools/testing/radix-tree/test.h +++ b/tools/testing/radix-tree/test.h | |||
@@ -5,11 +5,11 @@ | |||
5 | 5 | ||
6 | struct item { | 6 | struct item { |
7 | unsigned long index; | 7 | unsigned long index; |
8 | unsigned int order; | ||
8 | }; | 9 | }; |
9 | 10 | ||
10 | struct item *item_create(unsigned long index); | 11 | struct item *item_create(unsigned long index, unsigned int order); |
11 | int __item_insert(struct radix_tree_root *root, struct item *item, | 12 | int __item_insert(struct radix_tree_root *root, struct item *item); |
12 | unsigned order); | ||
13 | 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, | 14 | int item_insert_order(struct radix_tree_root *root, unsigned long index, |
15 | unsigned order); | 15 | unsigned order); |