diff options
Diffstat (limited to 'tools/testing/radix-tree/main.c')
-rw-r--r-- | tools/testing/radix-tree/main.c | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c index daa9010693e8..f7e9801a6754 100644 --- a/tools/testing/radix-tree/main.c +++ b/tools/testing/radix-tree/main.c | |||
@@ -67,7 +67,6 @@ void big_gang_check(bool long_run) | |||
67 | 67 | ||
68 | for (i = 0; i < (long_run ? 1000 : 3); i++) { | 68 | for (i = 0; i < (long_run ? 1000 : 3); i++) { |
69 | __big_gang_check(); | 69 | __big_gang_check(); |
70 | srand(time(0)); | ||
71 | printf("%d ", i); | 70 | printf("%d ", i); |
72 | fflush(stdout); | 71 | fflush(stdout); |
73 | } | 72 | } |
@@ -206,8 +205,7 @@ void copy_tag_check(void) | |||
206 | } | 205 | } |
207 | 206 | ||
208 | // printf("\ncopying tags...\n"); | 207 | // printf("\ncopying tags...\n"); |
209 | cur = start; | 208 | tagged = tag_tagged_items(&tree, NULL, start, end, ITEMS, 0, 1); |
210 | tagged = radix_tree_range_tag_if_tagged(&tree, &cur, end, ITEMS, 0, 1); | ||
211 | 209 | ||
212 | // printf("checking copied tags\n"); | 210 | // printf("checking copied tags\n"); |
213 | assert(tagged == count); | 211 | assert(tagged == count); |
@@ -215,16 +213,13 @@ void copy_tag_check(void) | |||
215 | 213 | ||
216 | /* Copy tags in several rounds */ | 214 | /* Copy tags in several rounds */ |
217 | // printf("\ncopying tags...\n"); | 215 | // printf("\ncopying tags...\n"); |
218 | cur = start; | 216 | tmp = rand() % (count / 10 + 2); |
219 | do { | 217 | tagged = tag_tagged_items(&tree, NULL, start, end, tmp, 0, 2); |
220 | tmp = rand() % (count/10+2); | 218 | assert(tagged == count); |
221 | tagged = radix_tree_range_tag_if_tagged(&tree, &cur, end, tmp, 0, 2); | ||
222 | } while (tmp == tagged); | ||
223 | 219 | ||
224 | // printf("%lu %lu %lu\n", tagged, tmp, count); | 220 | // printf("%lu %lu %lu\n", tagged, tmp, count); |
225 | // printf("checking copied tags\n"); | 221 | // printf("checking copied tags\n"); |
226 | check_copied_tags(&tree, start, end, idx, ITEMS, 0, 2); | 222 | check_copied_tags(&tree, start, end, idx, ITEMS, 0, 2); |
227 | assert(tagged < tmp); | ||
228 | verify_tag_consistency(&tree, 0); | 223 | verify_tag_consistency(&tree, 0); |
229 | verify_tag_consistency(&tree, 1); | 224 | verify_tag_consistency(&tree, 1); |
230 | verify_tag_consistency(&tree, 2); | 225 | verify_tag_consistency(&tree, 2); |
@@ -240,7 +235,7 @@ static void __locate_check(struct radix_tree_root *tree, unsigned long index, | |||
240 | 235 | ||
241 | item_insert_order(tree, index, order); | 236 | item_insert_order(tree, index, order); |
242 | item = item_lookup(tree, index); | 237 | item = item_lookup(tree, index); |
243 | index2 = radix_tree_locate_item(tree, item); | 238 | index2 = find_item(tree, item); |
244 | if (index != index2) { | 239 | if (index != index2) { |
245 | printf("index %ld order %d inserted; found %ld\n", | 240 | printf("index %ld order %d inserted; found %ld\n", |
246 | index, order, index2); | 241 | index, order, index2); |
@@ -274,17 +269,17 @@ static void locate_check(void) | |||
274 | index += (1UL << order)) { | 269 | index += (1UL << order)) { |
275 | __locate_check(&tree, index + offset, order); | 270 | __locate_check(&tree, index + offset, order); |
276 | } | 271 | } |
277 | if (radix_tree_locate_item(&tree, &tree) != -1) | 272 | if (find_item(&tree, &tree) != -1) |
278 | abort(); | 273 | abort(); |
279 | 274 | ||
280 | item_kill_tree(&tree); | 275 | item_kill_tree(&tree); |
281 | } | 276 | } |
282 | } | 277 | } |
283 | 278 | ||
284 | if (radix_tree_locate_item(&tree, &tree) != -1) | 279 | if (find_item(&tree, &tree) != -1) |
285 | abort(); | 280 | abort(); |
286 | __locate_check(&tree, -1, 0); | 281 | __locate_check(&tree, -1, 0); |
287 | if (radix_tree_locate_item(&tree, &tree) != -1) | 282 | if (find_item(&tree, &tree) != -1) |
288 | abort(); | 283 | abort(); |
289 | item_kill_tree(&tree); | 284 | item_kill_tree(&tree); |
290 | } | 285 | } |
@@ -293,50 +288,80 @@ static void single_thread_tests(bool long_run) | |||
293 | { | 288 | { |
294 | int i; | 289 | int i; |
295 | 290 | ||
296 | printf("starting single_thread_tests: %d allocated\n", nr_allocated); | 291 | printf("starting single_thread_tests: %d allocated, preempt %d\n", |
292 | nr_allocated, preempt_count); | ||
297 | multiorder_checks(); | 293 | multiorder_checks(); |
298 | printf("after multiorder_check: %d allocated\n", nr_allocated); | 294 | rcu_barrier(); |
295 | printf("after multiorder_check: %d allocated, preempt %d\n", | ||
296 | nr_allocated, preempt_count); | ||
299 | locate_check(); | 297 | locate_check(); |
300 | printf("after locate_check: %d allocated\n", nr_allocated); | 298 | rcu_barrier(); |
299 | printf("after locate_check: %d allocated, preempt %d\n", | ||
300 | nr_allocated, preempt_count); | ||
301 | tag_check(); | 301 | tag_check(); |
302 | printf("after tag_check: %d allocated\n", nr_allocated); | 302 | rcu_barrier(); |
303 | printf("after tag_check: %d allocated, preempt %d\n", | ||
304 | nr_allocated, preempt_count); | ||
303 | gang_check(); | 305 | gang_check(); |
304 | printf("after gang_check: %d allocated\n", nr_allocated); | 306 | rcu_barrier(); |
307 | printf("after gang_check: %d allocated, preempt %d\n", | ||
308 | nr_allocated, preempt_count); | ||
305 | add_and_check(); | 309 | add_and_check(); |
306 | printf("after add_and_check: %d allocated\n", nr_allocated); | 310 | rcu_barrier(); |
311 | printf("after add_and_check: %d allocated, preempt %d\n", | ||
312 | nr_allocated, preempt_count); | ||
307 | dynamic_height_check(); | 313 | dynamic_height_check(); |
308 | printf("after dynamic_height_check: %d allocated\n", nr_allocated); | 314 | rcu_barrier(); |
315 | printf("after dynamic_height_check: %d allocated, preempt %d\n", | ||
316 | nr_allocated, preempt_count); | ||
309 | big_gang_check(long_run); | 317 | big_gang_check(long_run); |
310 | printf("after big_gang_check: %d allocated\n", nr_allocated); | 318 | rcu_barrier(); |
319 | printf("after big_gang_check: %d allocated, preempt %d\n", | ||
320 | nr_allocated, preempt_count); | ||
311 | for (i = 0; i < (long_run ? 2000 : 3); i++) { | 321 | for (i = 0; i < (long_run ? 2000 : 3); i++) { |
312 | copy_tag_check(); | 322 | copy_tag_check(); |
313 | printf("%d ", i); | 323 | printf("%d ", i); |
314 | fflush(stdout); | 324 | fflush(stdout); |
315 | } | 325 | } |
316 | printf("after copy_tag_check: %d allocated\n", nr_allocated); | 326 | rcu_barrier(); |
327 | printf("after copy_tag_check: %d allocated, preempt %d\n", | ||
328 | nr_allocated, preempt_count); | ||
317 | } | 329 | } |
318 | 330 | ||
319 | int main(int argc, char **argv) | 331 | int main(int argc, char **argv) |
320 | { | 332 | { |
321 | bool long_run = false; | 333 | bool long_run = false; |
322 | int opt; | 334 | int opt; |
335 | unsigned int seed = time(NULL); | ||
323 | 336 | ||
324 | while ((opt = getopt(argc, argv, "l")) != -1) { | 337 | while ((opt = getopt(argc, argv, "ls:")) != -1) { |
325 | if (opt == 'l') | 338 | if (opt == 'l') |
326 | long_run = true; | 339 | long_run = true; |
340 | else if (opt == 's') | ||
341 | seed = strtoul(optarg, NULL, 0); | ||
327 | } | 342 | } |
328 | 343 | ||
344 | printf("random seed %u\n", seed); | ||
345 | srand(seed); | ||
346 | |||
329 | rcu_register_thread(); | 347 | rcu_register_thread(); |
330 | radix_tree_init(); | 348 | radix_tree_init(); |
331 | 349 | ||
332 | regression1_test(); | 350 | regression1_test(); |
333 | regression2_test(); | 351 | regression2_test(); |
334 | regression3_test(); | 352 | regression3_test(); |
335 | iteration_test(); | 353 | iteration_test(0, 10); |
354 | iteration_test(7, 20); | ||
336 | single_thread_tests(long_run); | 355 | single_thread_tests(long_run); |
337 | 356 | ||
338 | sleep(1); | 357 | /* Free any remaining preallocated nodes */ |
339 | printf("after sleep(1): %d allocated\n", nr_allocated); | 358 | radix_tree_cpu_dead(0); |
359 | |||
360 | benchmark(); | ||
361 | |||
362 | rcu_barrier(); | ||
363 | printf("after rcu_barrier: %d allocated, preempt %d\n", | ||
364 | nr_allocated, preempt_count); | ||
340 | rcu_unregister_thread(); | 365 | rcu_unregister_thread(); |
341 | 366 | ||
342 | exit(0); | 367 | exit(0); |