Skip to content

Commit 3e1d58c

Browse files
RichardWeiYangakpm00
authored andcommitted
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>
1 parent 4164e15 commit 3e1d58c

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

lib/interval_tree_test.c

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,13 @@ static void init(void)
5959
queries[i] = (prandom_u32_state(&rnd) >> 4) % max_endpoint;
6060
}
6161

62-
static int interval_tree_test_init(void)
62+
static int basic_check(void)
6363
{
6464
int i, j;
65-
unsigned long results;
6665
cycles_t time1, time2, time;
6766

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-
7967
printk(KERN_ALERT "interval tree insert/remove");
8068

81-
prandom_seed_state(&rnd, 3141592653589793238ULL);
8269
init();
8370

8471
time1 = get_cycles();
@@ -96,8 +83,19 @@ static int interval_tree_test_init(void)
9683
time = div_u64(time, perf_loops);
9784
printk(" -> %llu cycles\n", (unsigned long long)time);
9885

86+
return 0;
87+
}
88+
89+
static int search_check(void)
90+
{
91+
int i, j;
92+
unsigned long results;
93+
cycles_t time1, time2, time;
94+
9995
printk(KERN_ALERT "interval tree search");
10096

97+
init();
98+
10199
for (j = 0; j < nnodes; j++)
102100
interval_tree_insert(nodes + j, &root);
103101

@@ -120,6 +118,30 @@ static int interval_tree_test_init(void)
120118
printk(" -> %llu cycles (%lu results)\n",
121119
(unsigned long long)time, results);
122120

121+
for (j = 0; j < nnodes; j++)
122+
interval_tree_remove(nodes + j, &root);
123+
124+
return 0;
125+
}
126+
127+
static int interval_tree_test_init(void)
128+
{
129+
nodes = kmalloc_array(nnodes, sizeof(struct interval_tree_node),
130+
GFP_KERNEL);
131+
if (!nodes)
132+
return -ENOMEM;
133+
134+
queries = kmalloc_array(nsearches, sizeof(int), GFP_KERNEL);
135+
if (!queries) {
136+
kfree(nodes);
137+
return -ENOMEM;
138+
}
139+
140+
prandom_seed_state(&rnd, 3141592653589793238ULL);
141+
142+
basic_check();
143+
search_check();
144+
123145
kfree(queries);
124146
kfree(nodes);
125147

lib/rbtree_test.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,14 @@ static void check_augmented(int nr_nodes)
239239
}
240240
}
241241

242-
static int __init rbtree_test_init(void)
242+
static int basic_check(void)
243243
{
244244
int i, j;
245245
cycles_t time1, time2, time;
246246
struct rb_node *node;
247247

248-
nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL);
249-
if (!nodes)
250-
return -ENOMEM;
251-
252248
printk(KERN_ALERT "rbtree testing");
253249

254-
prandom_seed_state(&rnd, 3141592653589793238ULL);
255250
init();
256251

257252
time1 = get_cycles();
@@ -343,6 +338,14 @@ static int __init rbtree_test_init(void)
343338
check(0);
344339
}
345340

341+
return 0;
342+
}
343+
344+
static int augmented_check(void)
345+
{
346+
int i, j;
347+
cycles_t time1, time2, time;
348+
346349
printk(KERN_ALERT "augmented rbtree testing");
347350

348351
init();
@@ -390,6 +393,20 @@ static int __init rbtree_test_init(void)
390393
check_augmented(0);
391394
}
392395

396+
return 0;
397+
}
398+
399+
static int __init rbtree_test_init(void)
400+
{
401+
nodes = kmalloc_array(nnodes, sizeof(*nodes), GFP_KERNEL);
402+
if (!nodes)
403+
return -ENOMEM;
404+
405+
prandom_seed_state(&rnd, 3141592653589793238ULL);
406+
407+
basic_check();
408+
augmented_check();
409+
393410
kfree(nodes);
394411

395412
return -EAGAIN; /* Fail will directly unload the module */

0 commit comments

Comments
 (0)