aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/radix-tree/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/testing/radix-tree/main.c')
-rw-r--r--tools/testing/radix-tree/main.c84
1 files changed, 77 insertions, 7 deletions
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c
index 0e83cad27a9f..b7619ff3b552 100644
--- a/tools/testing/radix-tree/main.c
+++ b/tools/testing/radix-tree/main.c
@@ -61,11 +61,11 @@ void __big_gang_check(void)
61 } while (!wrapped); 61 } while (!wrapped);
62} 62}
63 63
64void big_gang_check(void) 64void big_gang_check(bool long_run)
65{ 65{
66 int i; 66 int i;
67 67
68 for (i = 0; i < 1000; i++) { 68 for (i = 0; i < (long_run ? 1000 : 3); i++) {
69 __big_gang_check(); 69 __big_gang_check();
70 srand(time(0)); 70 srand(time(0));
71 printf("%d ", i); 71 printf("%d ", i);
@@ -232,10 +232,72 @@ void copy_tag_check(void)
232 item_kill_tree(&tree); 232 item_kill_tree(&tree);
233} 233}
234 234
235static void single_thread_tests(void) 235static void __locate_check(struct radix_tree_root *tree, unsigned long index,
236 unsigned order)
237{
238 struct item *item;
239 unsigned long index2;
240
241 item_insert_order(tree, index, order);
242 item = item_lookup(tree, index);
243 index2 = radix_tree_locate_item(tree, item);
244 if (index != index2) {
245 printf("index %ld order %d inserted; found %ld\n",
246 index, order, index2);
247 abort();
248 }
249}
250
251static void __order_0_locate_check(void)
252{
253 RADIX_TREE(tree, GFP_KERNEL);
254 int i;
255
256 for (i = 0; i < 50; i++)
257 __locate_check(&tree, rand() % INT_MAX, 0);
258
259 item_kill_tree(&tree);
260}
261
262static void locate_check(void)
263{
264 RADIX_TREE(tree, GFP_KERNEL);
265 unsigned order;
266 unsigned long offset, index;
267
268 __order_0_locate_check();
269
270 for (order = 0; order < 20; order++) {
271 for (offset = 0; offset < (1 << (order + 3));
272 offset += (1UL << order)) {
273 for (index = 0; index < (1UL << (order + 5));
274 index += (1UL << order)) {
275 __locate_check(&tree, index + offset, order);
276 }
277 if (radix_tree_locate_item(&tree, &tree) != -1)
278 abort();
279
280 item_kill_tree(&tree);
281 }
282 }
283
284 if (radix_tree_locate_item(&tree, &tree) != -1)
285 abort();
286 __locate_check(&tree, -1, 0);
287 if (radix_tree_locate_item(&tree, &tree) != -1)
288 abort();
289 item_kill_tree(&tree);
290}
291
292static void single_thread_tests(bool long_run)
236{ 293{
237 int i; 294 int i;
238 295
296 printf("starting single_thread_tests: %d allocated\n", nr_allocated);
297 multiorder_checks();
298 printf("after multiorder_check: %d allocated\n", nr_allocated);
299 locate_check();
300 printf("after locate_check: %d allocated\n", nr_allocated);
239 tag_check(); 301 tag_check();
240 printf("after tag_check: %d allocated\n", nr_allocated); 302 printf("after tag_check: %d allocated\n", nr_allocated);
241 gang_check(); 303 gang_check();
@@ -244,9 +306,9 @@ static void single_thread_tests(void)
244 printf("after add_and_check: %d allocated\n", nr_allocated); 306 printf("after add_and_check: %d allocated\n", nr_allocated);
245 dynamic_height_check(); 307 dynamic_height_check();
246 printf("after dynamic_height_check: %d allocated\n", nr_allocated); 308 printf("after dynamic_height_check: %d allocated\n", nr_allocated);
247 big_gang_check(); 309 big_gang_check(long_run);
248 printf("after big_gang_check: %d allocated\n", nr_allocated); 310 printf("after big_gang_check: %d allocated\n", nr_allocated);
249 for (i = 0; i < 2000; i++) { 311 for (i = 0; i < (long_run ? 2000 : 3); i++) {
250 copy_tag_check(); 312 copy_tag_check();
251 printf("%d ", i); 313 printf("%d ", i);
252 fflush(stdout); 314 fflush(stdout);
@@ -254,15 +316,23 @@ static void single_thread_tests(void)
254 printf("after copy_tag_check: %d allocated\n", nr_allocated); 316 printf("after copy_tag_check: %d allocated\n", nr_allocated);
255} 317}
256 318
257int main(void) 319int main(int argc, char **argv)
258{ 320{
321 bool long_run = false;
322 int opt;
323
324 while ((opt = getopt(argc, argv, "l")) != -1) {
325 if (opt == 'l')
326 long_run = true;
327 }
328
259 rcu_register_thread(); 329 rcu_register_thread();
260 radix_tree_init(); 330 radix_tree_init();
261 331
262 regression1_test(); 332 regression1_test();
263 regression2_test(); 333 regression2_test();
264 regression3_test(); 334 regression3_test();
265 single_thread_tests(); 335 single_thread_tests(long_run);
266 336
267 sleep(1); 337 sleep(1);
268 printf("after sleep(1): %d allocated\n", nr_allocated); 338 printf("after sleep(1): %d allocated\n", nr_allocated);