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

Configure Feed

Select the types of activity you want to include in your feed.

lib/rbtree: split tests

Current tests are gathered in one big function.

Split tests into its own function for better understanding and also it
is a preparation for introducing new test cases.

Link: https://lkml.kernel.org/r/20250310074938.26756-3-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michel Lespinasse <michel@lespinasse.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Wei Yang and committed by
Andrew Morton
3e1d58cd 4164e152

+59 -20
+36 -14
lib/interval_tree_test.c
··· 59 59 queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint; 60 60 } 61 61 62 - static int interval_tree_test_init(void) 62 + static int basic_check(void) 63 63 { 64 64 int i, j; 65 - unsigned long results; 66 65 cycles_t time1, time2, time; 67 - 68 - nodes = kmalloc_array(nnodes, sizeof(struct interval_tree_node), 69 - GFP_KERNEL); 70 - if (!nodes) 71 - return -ENOMEM; 72 - 73 - queries = kmalloc_array(nsearches, sizeof(int), GFP_KERNEL); 74 - if (!queries) { 75 - kfree(nodes); 76 - return -ENOMEM; 77 - } 78 66 79 67 printk(KERN_ALERT "interval tree insert/remove"); 80 68 81 - prandom_seed_state(&rnd, 3141592653589793238ULL); 82 69 init(); 83 70 84 71 time1 = get_cycles(); ··· 83 96 time = div_u64(time, perf_loops); 84 97 printk(" -> %llu cycles\n", (unsigned long long)time); 85 98 99 + return 0; 100 + } 101 + 102 + static int search_check(void) 103 + { 104 + int i, j; 105 + unsigned long results; 106 + cycles_t time1, time2, time; 107 + 86 108 printk(KERN_ALERT "interval tree search"); 109 + 110 + init(); 87 111 88 112 for (j = 0; j < nnodes; j++) 89 113 interval_tree_insert(nodes + j, &root); ··· 117 119 results = div_u64(results, search_loops); 118 120 printk(" -> %llu cycles (%lu results)\n", 119 121 (unsigned long long)time, results); 122 + 123 + for (j = 0; j < nnodes; j++) 124 + interval_tree_remove(nodes + j, &root); 125 + 126 + return 0; 127 + } 128 + 129 + static int interval_tree_test_init(void) 130 + { 131 + nodes = kmalloc_array(nnodes, sizeof(struct interval_tree_node), 132 + GFP_KERNEL); 133 + if (!nodes) 134 + return -ENOMEM; 135 + 136 + queries = kmalloc_array(nsearches, sizeof(int), GFP_KERNEL); 137 + if (!queries) { 138 + kfree(nodes); 139 + return -ENOMEM; 140 + } 141 + 142 + prandom_seed_state(&rnd, 3141592653589793238ULL); 143 + 144 + basic_check(); 145 + search_check(); 120 146 121 147 kfree(queries); 122 148 kfree(nodes);
+23 -6
lib/rbtree_test.c
··· 239 239 } 240 240 } 241 241 242 - static int __init rbtree_test_init(void) 242 + static int basic_check(void) 243 243 { 244 244 int i, j; 245 245 cycles_t time1, time2, time; 246 246 struct rb_node *node; 247 247 248 - nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL); 249 - if (!nodes) 250 - return -ENOMEM; 251 - 252 248 printk(KERN_ALERT "rbtree testing"); 253 249 254 - prandom_seed_state(&rnd, 3141592653589793238ULL); 255 250 init(); 256 251 257 252 time1 = get_cycles(); ··· 338 343 check(0); 339 344 } 340 345 346 + return 0; 347 + } 348 + 349 + static int augmented_check(void) 350 + { 351 + int i, j; 352 + cycles_t time1, time2, time; 353 + 341 354 printk(KERN_ALERT "augmented rbtree testing"); 342 355 343 356 init(); ··· 392 389 } 393 390 check_augmented(0); 394 391 } 392 + 393 + return 0; 394 + } 395 + 396 + static int __init rbtree_test_init(void) 397 + { 398 + nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL); 399 + if (!nodes) 400 + return -ENOMEM; 401 + 402 + prandom_seed_state(&rnd, 3141592653589793238ULL); 403 + 404 + basic_check(); 405 + augmented_check(); 395 406 396 407 kfree(nodes); 397 408