mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2025-10-23 07:23:12 +02:00
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>
This commit is contained in:
parent
4164e1525d
commit
3e1d58cd5d
|
@ -59,26 +59,13 @@ static void init(void)
|
||||||
queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
|
queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int interval_tree_test_init(void)
|
static int basic_check(void)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned long results;
|
|
||||||
cycles_t time1, time2, time;
|
cycles_t time1, time2, time;
|
||||||
|
|
||||||
nodes = kmalloc_array(nnodes, sizeof(struct interval_tree_node),
|
|
||||||
GFP_KERNEL);
|
|
||||||
if (!nodes)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
queries = kmalloc_array(nsearches, sizeof(int), GFP_KERNEL);
|
|
||||||
if (!queries) {
|
|
||||||
kfree(nodes);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
printk(KERN_ALERT "interval tree insert/remove");
|
printk(KERN_ALERT "interval tree insert/remove");
|
||||||
|
|
||||||
prandom_seed_state(&rnd, 3141592653589793238ULL);
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
time1 = get_cycles();
|
time1 = get_cycles();
|
||||||
|
@ -96,8 +83,19 @@ static int interval_tree_test_init(void)
|
||||||
time = div_u64(time, perf_loops);
|
time = div_u64(time, perf_loops);
|
||||||
printk(" -> %llu cycles\n", (unsigned long long)time);
|
printk(" -> %llu cycles\n", (unsigned long long)time);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int search_check(void)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
unsigned long results;
|
||||||
|
cycles_t time1, time2, time;
|
||||||
|
|
||||||
printk(KERN_ALERT "interval tree search");
|
printk(KERN_ALERT "interval tree search");
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
for (j = 0; j < nnodes; j++)
|
for (j = 0; j < nnodes; j++)
|
||||||
interval_tree_insert(nodes + j, &root);
|
interval_tree_insert(nodes + j, &root);
|
||||||
|
|
||||||
|
@ -120,6 +118,30 @@ static int interval_tree_test_init(void)
|
||||||
printk(" -> %llu cycles (%lu results)\n",
|
printk(" -> %llu cycles (%lu results)\n",
|
||||||
(unsigned long long)time, results);
|
(unsigned long long)time, results);
|
||||||
|
|
||||||
|
for (j = 0; j < nnodes; j++)
|
||||||
|
interval_tree_remove(nodes + j, &root);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int interval_tree_test_init(void)
|
||||||
|
{
|
||||||
|
nodes = kmalloc_array(nnodes, sizeof(struct interval_tree_node),
|
||||||
|
GFP_KERNEL);
|
||||||
|
if (!nodes)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
queries = kmalloc_array(nsearches, sizeof(int), GFP_KERNEL);
|
||||||
|
if (!queries) {
|
||||||
|
kfree(nodes);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
prandom_seed_state(&rnd, 3141592653589793238ULL);
|
||||||
|
|
||||||
|
basic_check();
|
||||||
|
search_check();
|
||||||
|
|
||||||
kfree(queries);
|
kfree(queries);
|
||||||
kfree(nodes);
|
kfree(nodes);
|
||||||
|
|
||||||
|
|
|
@ -239,19 +239,14 @@ static void check_augmented(int nr_nodes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init rbtree_test_init(void)
|
static int basic_check(void)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
cycles_t time1, time2, time;
|
cycles_t time1, time2, time;
|
||||||
struct rb_node *node;
|
struct rb_node *node;
|
||||||
|
|
||||||
nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL);
|
|
||||||
if (!nodes)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
printk(KERN_ALERT "rbtree testing");
|
printk(KERN_ALERT "rbtree testing");
|
||||||
|
|
||||||
prandom_seed_state(&rnd, 3141592653589793238ULL);
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
time1 = get_cycles();
|
time1 = get_cycles();
|
||||||
|
@ -343,6 +338,14 @@ static int __init rbtree_test_init(void)
|
||||||
check(0);
|
check(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int augmented_check(void)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
cycles_t time1, time2, time;
|
||||||
|
|
||||||
printk(KERN_ALERT "augmented rbtree testing");
|
printk(KERN_ALERT "augmented rbtree testing");
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
@ -390,6 +393,20 @@ static int __init rbtree_test_init(void)
|
||||||
check_augmented(0);
|
check_augmented(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __init rbtree_test_init(void)
|
||||||
|
{
|
||||||
|
nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL);
|
||||||
|
if (!nodes)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
prandom_seed_state(&rnd, 3141592653589793238ULL);
|
||||||
|
|
||||||
|
basic_check();
|
||||||
|
augmented_check();
|
||||||
|
|
||||||
kfree(nodes);
|
kfree(nodes);
|
||||||
|
|
||||||
return -EAGAIN; /* Fail will directly unload the module */
|
return -EAGAIN; /* Fail will directly unload the module */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user