Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

radix-tree test suite: add multi-order tag test

Add a generic test for multi-order tag verification, and call it using
several different configurations.

This test creates a multi-order radix tree using the given index and
order, and then sets, checks and clears tags using the indices covered
by the single multi-order radix tree entry.

With the various calls done by this test we verify root multi-order
entries without siblings, multi-order entries without siblings in a
radix tree node, as well as multi-order entries with siblings of various
sizes.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ross Zwisler and committed by
Linus Torvalds
0fc9b8ca 4589ba6d

+97
+97
tools/testing/radix-tree/multiorder.c
··· 19 19 20 20 #include "test.h" 21 21 22 + #define for_each_index(i, base, order) \ 23 + for (i = base; i < base + (1 << order); i++) 24 + 25 + static void __multiorder_tag_test(int index, int order) 26 + { 27 + RADIX_TREE(tree, GFP_KERNEL); 28 + int base, err, i; 29 + 30 + /* our canonical entry */ 31 + base = index & ~((1 << order) - 1); 32 + 33 + printf("Multiorder tag test with index %d, canonical entry %d\n", 34 + index, base); 35 + 36 + err = item_insert_order(&tree, index, order); 37 + assert(!err); 38 + 39 + /* 40 + * Verify we get collisions for covered indices. We try and fail to 41 + * insert an exceptional entry so we don't leak memory via 42 + * item_insert_order(). 43 + */ 44 + for_each_index(i, base, order) { 45 + err = __radix_tree_insert(&tree, i, order, 46 + (void *)(0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY)); 47 + assert(err == -EEXIST); 48 + } 49 + 50 + for_each_index(i, base, order) { 51 + assert(!radix_tree_tag_get(&tree, i, 0)); 52 + assert(!radix_tree_tag_get(&tree, i, 1)); 53 + } 54 + 55 + assert(radix_tree_tag_set(&tree, index, 0)); 56 + 57 + for_each_index(i, base, order) { 58 + assert(radix_tree_tag_get(&tree, i, 0)); 59 + assert(!radix_tree_tag_get(&tree, i, 1)); 60 + } 61 + 62 + assert(radix_tree_tag_clear(&tree, index, 0)); 63 + 64 + for_each_index(i, base, order) { 65 + assert(!radix_tree_tag_get(&tree, i, 0)); 66 + assert(!radix_tree_tag_get(&tree, i, 1)); 67 + } 68 + 69 + assert(!radix_tree_tagged(&tree, 0)); 70 + assert(!radix_tree_tagged(&tree, 1)); 71 + 72 + item_kill_tree(&tree); 73 + } 74 + 75 + static void multiorder_tag_tests(void) 76 + { 77 + /* test multi-order entry for indices 0-7 with no sibling pointers */ 78 + __multiorder_tag_test(0, 3); 79 + __multiorder_tag_test(5, 3); 80 + 81 + /* test multi-order entry for indices 8-15 with no sibling pointers */ 82 + __multiorder_tag_test(8, 3); 83 + __multiorder_tag_test(15, 3); 84 + 85 + /* 86 + * Our order 5 entry covers indices 0-31 in a tree with height=2. 87 + * This is broken up as follows: 88 + * 0-7: canonical entry 89 + * 8-15: sibling 1 90 + * 16-23: sibling 2 91 + * 24-31: sibling 3 92 + */ 93 + __multiorder_tag_test(0, 5); 94 + __multiorder_tag_test(29, 5); 95 + 96 + /* same test, but with indices 32-63 */ 97 + __multiorder_tag_test(32, 5); 98 + __multiorder_tag_test(44, 5); 99 + 100 + /* 101 + * Our order 8 entry covers indices 0-255 in a tree with height=3. 102 + * This is broken up as follows: 103 + * 0-63: canonical entry 104 + * 64-127: sibling 1 105 + * 128-191: sibling 2 106 + * 192-255: sibling 3 107 + */ 108 + __multiorder_tag_test(0, 8); 109 + __multiorder_tag_test(190, 8); 110 + 111 + /* same test, but with indices 256-511 */ 112 + __multiorder_tag_test(256, 8); 113 + __multiorder_tag_test(300, 8); 114 + 115 + __multiorder_tag_test(0x12345678UL, 8); 116 + } 117 + 22 118 static void multiorder_check(unsigned long index, int order) 23 119 { 24 120 unsigned long i; ··· 292 196 multiorder_shrink((1UL << (i + RADIX_TREE_MAP_SHIFT)), i); 293 197 294 198 multiorder_insert_bug(); 199 + multiorder_tag_tests(); 295 200 multiorder_iteration(); 296 201 multiorder_tagged_iteration(); 297 202 }