Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <time.h> |
| 6 | #include <assert.h> |
Matthew Wilcox | 0a835c4 | 2016-12-20 10:27:56 -0500 | [diff] [blame] | 7 | #include <limits.h> |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 8 | |
| 9 | #include <linux/slab.h> |
| 10 | #include <linux/radix-tree.h> |
| 11 | |
| 12 | #include "test.h" |
| 13 | #include "regression.h" |
| 14 | |
| 15 | void __gang_check(unsigned long middle, long down, long up, int chunk, int hop) |
| 16 | { |
| 17 | long idx; |
| 18 | RADIX_TREE(tree, GFP_KERNEL); |
| 19 | |
| 20 | middle = 1 << 30; |
| 21 | |
| 22 | for (idx = -down; idx < up; idx++) |
| 23 | item_insert(&tree, middle + idx); |
| 24 | |
| 25 | item_check_absent(&tree, middle - down - 1); |
| 26 | for (idx = -down; idx < up; idx++) |
| 27 | item_check_present(&tree, middle + idx); |
| 28 | item_check_absent(&tree, middle + up); |
| 29 | |
Matthew Wilcox | d1c0d5e | 2018-05-19 16:30:54 -0400 | [diff] [blame] | 30 | if (chunk > 0) { |
| 31 | item_gang_check_present(&tree, middle - down, up + down, |
| 32 | chunk, hop); |
| 33 | item_full_scan(&tree, middle - down, down + up, chunk); |
| 34 | } |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 35 | item_kill_tree(&tree); |
| 36 | } |
| 37 | |
| 38 | void gang_check(void) |
| 39 | { |
Matthew Wilcox | d1c0d5e | 2018-05-19 16:30:54 -0400 | [diff] [blame] | 40 | __gang_check(1UL << 30, 128, 128, 35, 2); |
| 41 | __gang_check(1UL << 31, 128, 128, 32, 32); |
| 42 | __gang_check(1UL << 31, 128, 128, 32, 100); |
| 43 | __gang_check(1UL << 31, 128, 128, 17, 7); |
| 44 | __gang_check(0xffff0000UL, 0, 65536, 17, 7); |
| 45 | __gang_check(0xfffffffeUL, 1, 1, 17, 7); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void __big_gang_check(void) |
| 49 | { |
| 50 | unsigned long start; |
| 51 | int wrapped = 0; |
| 52 | |
| 53 | start = 0; |
| 54 | do { |
| 55 | unsigned long old_start; |
| 56 | |
| 57 | // printf("0x%08lx\n", start); |
| 58 | __gang_check(start, rand() % 113 + 1, rand() % 71, |
| 59 | rand() % 157, rand() % 91 + 1); |
| 60 | old_start = start; |
| 61 | start += rand() % 1000000; |
| 62 | start %= 1ULL << 33; |
| 63 | if (start < old_start) |
| 64 | wrapped = 1; |
| 65 | } while (!wrapped); |
| 66 | } |
| 67 | |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 68 | void big_gang_check(bool long_run) |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 69 | { |
| 70 | int i; |
| 71 | |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 72 | for (i = 0; i < (long_run ? 1000 : 3); i++) { |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 73 | __big_gang_check(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 74 | printv(2, "%d ", i); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 75 | fflush(stdout); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | void add_and_check(void) |
| 80 | { |
| 81 | RADIX_TREE(tree, GFP_KERNEL); |
| 82 | |
| 83 | item_insert(&tree, 44); |
| 84 | item_check_present(&tree, 44); |
| 85 | item_check_absent(&tree, 43); |
| 86 | item_kill_tree(&tree); |
| 87 | } |
| 88 | |
| 89 | void dynamic_height_check(void) |
| 90 | { |
| 91 | int i; |
| 92 | RADIX_TREE(tree, GFP_KERNEL); |
| 93 | tree_verify_min_height(&tree, 0); |
| 94 | |
| 95 | item_insert(&tree, 42); |
| 96 | tree_verify_min_height(&tree, 42); |
| 97 | |
| 98 | item_insert(&tree, 1000000); |
| 99 | tree_verify_min_height(&tree, 1000000); |
| 100 | |
| 101 | assert(item_delete(&tree, 1000000)); |
| 102 | tree_verify_min_height(&tree, 42); |
| 103 | |
| 104 | assert(item_delete(&tree, 42)); |
| 105 | tree_verify_min_height(&tree, 0); |
| 106 | |
| 107 | for (i = 0; i < 1000; i++) { |
| 108 | item_insert(&tree, i); |
| 109 | tree_verify_min_height(&tree, i); |
| 110 | } |
| 111 | |
| 112 | i--; |
| 113 | for (;;) { |
| 114 | assert(item_delete(&tree, i)); |
| 115 | if (i == 0) { |
| 116 | tree_verify_min_height(&tree, 0); |
| 117 | break; |
| 118 | } |
| 119 | i--; |
| 120 | tree_verify_min_height(&tree, i); |
| 121 | } |
| 122 | |
| 123 | item_kill_tree(&tree); |
| 124 | } |
| 125 | |
| 126 | void check_copied_tags(struct radix_tree_root *tree, unsigned long start, unsigned long end, unsigned long *idx, int count, int fromtag, int totag) |
| 127 | { |
| 128 | int i; |
| 129 | |
| 130 | for (i = 0; i < count; i++) { |
| 131 | /* if (i % 1000 == 0) |
| 132 | putchar('.'); */ |
| 133 | if (idx[i] < start || idx[i] > end) { |
| 134 | if (item_tag_get(tree, idx[i], totag)) { |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 135 | printv(2, "%lu-%lu: %lu, tags %d-%d\n", start, |
| 136 | end, idx[i], item_tag_get(tree, idx[i], |
| 137 | fromtag), |
| 138 | item_tag_get(tree, idx[i], totag)); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 139 | } |
| 140 | assert(!item_tag_get(tree, idx[i], totag)); |
| 141 | continue; |
| 142 | } |
| 143 | if (item_tag_get(tree, idx[i], fromtag) ^ |
| 144 | item_tag_get(tree, idx[i], totag)) { |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 145 | printv(2, "%lu-%lu: %lu, tags %d-%d\n", start, end, |
| 146 | idx[i], item_tag_get(tree, idx[i], fromtag), |
| 147 | item_tag_get(tree, idx[i], totag)); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 148 | } |
| 149 | assert(!(item_tag_get(tree, idx[i], fromtag) ^ |
| 150 | item_tag_get(tree, idx[i], totag))); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | #define ITEMS 50000 |
| 155 | |
| 156 | void copy_tag_check(void) |
| 157 | { |
| 158 | RADIX_TREE(tree, GFP_KERNEL); |
| 159 | unsigned long idx[ITEMS]; |
| 160 | unsigned long start, end, count = 0, tagged, cur, tmp; |
| 161 | int i; |
| 162 | |
| 163 | // printf("generating radix tree indices...\n"); |
| 164 | start = rand(); |
| 165 | end = rand(); |
| 166 | if (start > end && (rand() % 10)) { |
| 167 | cur = start; |
| 168 | start = end; |
| 169 | end = cur; |
| 170 | } |
| 171 | /* Specifically create items around the start and the end of the range |
| 172 | * with high probability to check for off by one errors */ |
| 173 | cur = rand(); |
| 174 | if (cur & 1) { |
| 175 | item_insert(&tree, start); |
| 176 | if (cur & 2) { |
| 177 | if (start <= end) |
| 178 | count++; |
| 179 | item_tag_set(&tree, start, 0); |
| 180 | } |
| 181 | } |
| 182 | if (cur & 4) { |
| 183 | item_insert(&tree, start-1); |
| 184 | if (cur & 8) |
| 185 | item_tag_set(&tree, start-1, 0); |
| 186 | } |
| 187 | if (cur & 16) { |
| 188 | item_insert(&tree, end); |
| 189 | if (cur & 32) { |
| 190 | if (start <= end) |
| 191 | count++; |
| 192 | item_tag_set(&tree, end, 0); |
| 193 | } |
| 194 | } |
| 195 | if (cur & 64) { |
| 196 | item_insert(&tree, end+1); |
| 197 | if (cur & 128) |
| 198 | item_tag_set(&tree, end+1, 0); |
| 199 | } |
| 200 | |
| 201 | for (i = 0; i < ITEMS; i++) { |
| 202 | do { |
| 203 | idx[i] = rand(); |
| 204 | } while (item_lookup(&tree, idx[i])); |
| 205 | |
| 206 | item_insert(&tree, idx[i]); |
| 207 | if (rand() & 1) { |
| 208 | item_tag_set(&tree, idx[i], 0); |
| 209 | if (idx[i] >= start && idx[i] <= end) |
| 210 | count++; |
| 211 | } |
| 212 | /* if (i % 1000 == 0) |
| 213 | putchar('.'); */ |
| 214 | } |
| 215 | |
| 216 | // printf("\ncopying tags...\n"); |
Matthew Wilcox | 268f42d | 2016-12-14 15:08:55 -0800 | [diff] [blame] | 217 | tagged = tag_tagged_items(&tree, NULL, start, end, ITEMS, 0, 1); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 218 | |
| 219 | // printf("checking copied tags\n"); |
| 220 | assert(tagged == count); |
| 221 | check_copied_tags(&tree, start, end, idx, ITEMS, 0, 1); |
| 222 | |
| 223 | /* Copy tags in several rounds */ |
| 224 | // printf("\ncopying tags...\n"); |
Matthew Wilcox | 268f42d | 2016-12-14 15:08:55 -0800 | [diff] [blame] | 225 | tmp = rand() % (count / 10 + 2); |
| 226 | tagged = tag_tagged_items(&tree, NULL, start, end, tmp, 0, 2); |
| 227 | assert(tagged == count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 228 | |
| 229 | // printf("%lu %lu %lu\n", tagged, tmp, count); |
| 230 | // printf("checking copied tags\n"); |
| 231 | check_copied_tags(&tree, start, end, idx, ITEMS, 0, 2); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 232 | verify_tag_consistency(&tree, 0); |
| 233 | verify_tag_consistency(&tree, 1); |
| 234 | verify_tag_consistency(&tree, 2); |
| 235 | // printf("\n"); |
| 236 | item_kill_tree(&tree); |
| 237 | } |
| 238 | |
Ross Zwisler | eb73f7f | 2016-05-20 17:02:49 -0700 | [diff] [blame] | 239 | static void __locate_check(struct radix_tree_root *tree, unsigned long index, |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 240 | unsigned order) |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 241 | { |
| 242 | struct item *item; |
| 243 | unsigned long index2; |
| 244 | |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 245 | item_insert_order(tree, index, order); |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 246 | item = item_lookup(tree, index); |
Matthew Wilcox | 478922e | 2016-12-14 15:08:52 -0800 | [diff] [blame] | 247 | index2 = find_item(tree, item); |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 248 | if (index != index2) { |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 249 | printv(2, "index %ld order %d inserted; found %ld\n", |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 250 | index, order, index2); |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 251 | abort(); |
| 252 | } |
| 253 | } |
| 254 | |
Ross Zwisler | eb73f7f | 2016-05-20 17:02:49 -0700 | [diff] [blame] | 255 | static void __order_0_locate_check(void) |
| 256 | { |
| 257 | RADIX_TREE(tree, GFP_KERNEL); |
| 258 | int i; |
| 259 | |
| 260 | for (i = 0; i < 50; i++) |
| 261 | __locate_check(&tree, rand() % INT_MAX, 0); |
| 262 | |
| 263 | item_kill_tree(&tree); |
| 264 | } |
| 265 | |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 266 | static void locate_check(void) |
| 267 | { |
| 268 | RADIX_TREE(tree, GFP_KERNEL); |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 269 | unsigned order; |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 270 | unsigned long offset, index; |
| 271 | |
Ross Zwisler | eb73f7f | 2016-05-20 17:02:49 -0700 | [diff] [blame] | 272 | __order_0_locate_check(); |
| 273 | |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 274 | for (order = 0; order < 20; order++) { |
| 275 | for (offset = 0; offset < (1 << (order + 3)); |
| 276 | offset += (1UL << order)) { |
| 277 | for (index = 0; index < (1UL << (order + 5)); |
| 278 | index += (1UL << order)) { |
| 279 | __locate_check(&tree, index + offset, order); |
| 280 | } |
Matthew Wilcox | 478922e | 2016-12-14 15:08:52 -0800 | [diff] [blame] | 281 | if (find_item(&tree, &tree) != -1) |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 282 | abort(); |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 283 | |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 284 | item_kill_tree(&tree); |
| 285 | } |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Matthew Wilcox | 478922e | 2016-12-14 15:08:52 -0800 | [diff] [blame] | 288 | if (find_item(&tree, &tree) != -1) |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 289 | abort(); |
Matthew Wilcox | 0a2efc6 | 2016-05-20 17:02:46 -0700 | [diff] [blame] | 290 | __locate_check(&tree, -1, 0); |
Matthew Wilcox | 478922e | 2016-12-14 15:08:52 -0800 | [diff] [blame] | 291 | if (find_item(&tree, &tree) != -1) |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 292 | abort(); |
| 293 | item_kill_tree(&tree); |
| 294 | } |
| 295 | |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 296 | static void single_thread_tests(bool long_run) |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 297 | { |
| 298 | int i; |
| 299 | |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 300 | printv(1, "starting single_thread_tests: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 301 | nr_allocated, preempt_count); |
Matthew Wilcox | 4f3755d | 2016-05-20 17:02:14 -0700 | [diff] [blame] | 302 | multiorder_checks(); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 303 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 304 | printv(2, "after multiorder_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 305 | nr_allocated, preempt_count); |
Matthew Wilcox | d42cb1a | 2016-05-20 17:01:39 -0700 | [diff] [blame] | 306 | locate_check(); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 307 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 308 | printv(2, "after locate_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 309 | nr_allocated, preempt_count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 310 | tag_check(); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 311 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 312 | printv(2, "after tag_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 313 | nr_allocated, preempt_count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 314 | gang_check(); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 315 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 316 | printv(2, "after gang_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 317 | nr_allocated, preempt_count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 318 | add_and_check(); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 319 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 320 | printv(2, "after add_and_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 321 | nr_allocated, preempt_count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 322 | dynamic_height_check(); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 323 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 324 | printv(2, "after dynamic_height_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 325 | nr_allocated, preempt_count); |
Matthew Wilcox | 0a835c4 | 2016-12-20 10:27:56 -0500 | [diff] [blame] | 326 | idr_checks(); |
Matthew Wilcox | 8ab8ba3 | 2018-06-18 16:59:29 -0400 | [diff] [blame] | 327 | ida_tests(); |
Matthew Wilcox | 0a835c4 | 2016-12-20 10:27:56 -0500 | [diff] [blame] | 328 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 329 | printv(2, "after idr_checks: %d allocated, preempt %d\n", |
Matthew Wilcox | 0a835c4 | 2016-12-20 10:27:56 -0500 | [diff] [blame] | 330 | nr_allocated, preempt_count); |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 331 | big_gang_check(long_run); |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 332 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 333 | printv(2, "after big_gang_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 334 | nr_allocated, preempt_count); |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 335 | for (i = 0; i < (long_run ? 2000 : 3); i++) { |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 336 | copy_tag_check(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 337 | printv(2, "%d ", i); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 338 | fflush(stdout); |
| 339 | } |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 340 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 341 | printv(2, "after copy_tag_check: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 342 | nr_allocated, preempt_count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 345 | int main(int argc, char **argv) |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 346 | { |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 347 | bool long_run = false; |
| 348 | int opt; |
Matthew Wilcox | 061ef39 | 2016-12-14 15:08:08 -0800 | [diff] [blame] | 349 | unsigned int seed = time(NULL); |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 350 | |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 351 | while ((opt = getopt(argc, argv, "ls:v")) != -1) { |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 352 | if (opt == 'l') |
| 353 | long_run = true; |
Matthew Wilcox | 061ef39 | 2016-12-14 15:08:08 -0800 | [diff] [blame] | 354 | else if (opt == 's') |
| 355 | seed = strtoul(optarg, NULL, 0); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 356 | else if (opt == 'v') |
| 357 | test_verbose++; |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Matthew Wilcox | 061ef39 | 2016-12-14 15:08:08 -0800 | [diff] [blame] | 360 | printf("random seed %u\n", seed); |
| 361 | srand(seed); |
| 362 | |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 363 | printf("running tests\n"); |
| 364 | |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 365 | rcu_register_thread(); |
| 366 | radix_tree_init(); |
| 367 | |
| 368 | regression1_test(); |
| 369 | regression2_test(); |
Konstantin Khlebnikov | 2d6f45b | 2016-03-17 14:22:08 -0700 | [diff] [blame] | 370 | regression3_test(); |
Matthew Wilcox | c0cdbf8 | 2017-01-29 02:27:24 -0500 | [diff] [blame] | 371 | iteration_test(0, 10 + 90 * long_run); |
| 372 | iteration_test(7, 10 + 90 * long_run); |
Ross Zwisler | aa1d62d | 2016-05-20 17:01:45 -0700 | [diff] [blame] | 373 | single_thread_tests(long_run); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 374 | |
Matthew Wilcox | 6df5ee7 | 2016-12-14 15:08:05 -0800 | [diff] [blame] | 375 | /* Free any remaining preallocated nodes */ |
| 376 | radix_tree_cpu_dead(0); |
| 377 | |
Konstantin Khlebnikov | cfa40bc | 2016-12-14 15:08:14 -0800 | [diff] [blame] | 378 | benchmark(); |
| 379 | |
Matthew Wilcox | af1c5cc | 2016-12-14 15:08:17 -0800 | [diff] [blame] | 380 | rcu_barrier(); |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 381 | printv(2, "after rcu_barrier: %d allocated, preempt %d\n", |
Matthew Wilcox | 847d357 | 2016-12-14 15:08:02 -0800 | [diff] [blame] | 382 | nr_allocated, preempt_count); |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 383 | rcu_unregister_thread(); |
| 384 | |
Rehas Sachdeva | 73bc029 | 2017-01-04 11:55:00 -0500 | [diff] [blame] | 385 | printf("tests completed\n"); |
| 386 | |
Matthew Wilcox | 1366c37 | 2016-03-17 14:21:45 -0700 | [diff] [blame] | 387 | exit(0); |
| 388 | } |