Skip to content

Commit 16b1936

Browse files
RichardWeiYangakpm00
authored andcommitted
lib/rbtree: add random seed
Current test use pseudo rand function with fixed seed, which means the test data is the same pattern each time. Add random seed parameter to randomize the test. Link: https://lkml.kernel.org/r/20250310074938.26756-4-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 3e1d58c commit 16b1936

File tree

6 files changed

+15
-4
lines changed

6 files changed

+15
-4
lines changed

include/linux/types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ typedef unsigned char unchar;
9292
typedef unsigned short ushort;
9393
typedef unsigned int uint;
9494
typedef unsigned long ulong;
95+
typedef unsigned long long ullong;
9596

9697
#ifndef __BIT_TYPES_DEFINED__
9798
#define __BIT_TYPES_DEFINED__

lib/interval_tree_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ __param(int, search_loops, 1000, "Number of iterations searching the tree");
1919
__param(bool, search_all, false, "Searches will iterate all nodes in the tree");
2020

2121
__param(uint, max_endpoint, ~0, "Largest value for the interval's endpoint");
22+
__param(ullong, seed, 3141592653589793238ULL, "Random seed");
2223

2324
static struct rb_root_cached root = RB_ROOT_CACHED;
2425
static struct interval_tree_node *nodes = NULL;
@@ -137,7 +138,7 @@ static int interval_tree_test_init(void)
137138
return -ENOMEM;
138139
}
139140

140-
prandom_seed_state(&rnd, 3141592653589793238ULL);
141+
prandom_seed_state(&rnd, seed);
141142

142143
basic_check();
143144
search_check();

lib/rbtree_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
__param(int, nnodes, 100, "Number of nodes in the rb-tree");
1515
__param(int, perf_loops, 1000, "Number of iterations modifying the rb-tree");
1616
__param(int, check_loops, 100, "Number of iterations modifying and verifying the rb-tree");
17+
__param(ullong, seed, 3141592653589793238ULL, "Random seed");
1718

1819
struct test_node {
1920
u32 key;
@@ -402,7 +403,7 @@ static int __init rbtree_test_init(void)
402403
if (!nodes)
403404
return -ENOMEM;
404405

405-
prandom_seed_state(&rnd, 3141592653589793238ULL);
406+
prandom_seed_state(&rnd, seed);
406407

407408
basic_check();
408409
augmented_check();

tools/include/linux/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ typedef __s16 s16;
4242
typedef __u8 u8;
4343
typedef __s8 s8;
4444

45+
typedef unsigned long long ullong;
46+
4547
#ifdef __CHECKER__
4648
#define __bitwise __attribute__((bitwise))
4749
#else

tools/testing/rbtree/interval_tree_test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int usage(void)
1818
fprintf(stderr, " -s: Number of iterations searching the tree\n");
1919
fprintf(stderr, " -a: Searches will iterate all nodes in the tree\n");
2020
fprintf(stderr, " -m: Largest value for the interval's endpoint\n");
21+
fprintf(stderr, " -r: Random seed\n");
2122
exit(-1);
2223
}
2324

@@ -31,7 +32,7 @@ int main(int argc, char **argv)
3132
{
3233
int opt;
3334

34-
while ((opt = getopt(argc, argv, "n:p:q:s:am:")) != -1) {
35+
while ((opt = getopt(argc, argv, "n:p:q:s:am:r:")) != -1) {
3536
if (opt == 'n')
3637
nnodes = strtoul(optarg, NULL, 0);
3738
else if (opt == 'p')
@@ -44,6 +45,8 @@ int main(int argc, char **argv)
4445
search_all = true;
4546
else if (opt == 'm')
4647
max_endpoint = strtoul(optarg, NULL, 0);
48+
else if (opt == 'r')
49+
seed = strtoul(optarg, NULL, 0);
4750
else
4851
usage();
4952
}

tools/testing/rbtree/rbtree_test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int usage(void)
1616
fprintf(stderr, " -n: Number of nodes in the rb-tree\n");
1717
fprintf(stderr, " -p: Number of iterations modifying the rb-tree\n");
1818
fprintf(stderr, " -c: Number of iterations modifying and verifying the rb-tree\n");
19+
fprintf(stderr, " -r: Random seed\n");
1920
exit(-1);
2021
}
2122

@@ -29,13 +30,15 @@ int main(int argc, char **argv)
2930
{
3031
int opt;
3132

32-
while ((opt = getopt(argc, argv, "n:p:c:")) != -1) {
33+
while ((opt = getopt(argc, argv, "n:p:c:r:")) != -1) {
3334
if (opt == 'n')
3435
nnodes = strtoul(optarg, NULL, 0);
3536
else if (opt == 'p')
3637
perf_loops = strtoul(optarg, NULL, 0);
3738
else if (opt == 'c')
3839
check_loops = strtoul(optarg, NULL, 0);
40+
else if (opt == 'r')
41+
seed = strtoul(optarg, NULL, 0);
3942
else
4043
usage();
4144
}

0 commit comments

Comments
 (0)