xref: /linux/tools/testing/rbtree/interval_tree_test.c (revision 16b1936ae6d1858252413bf4bae8bcf247eb4b4c)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * interval_tree.c: Userspace Interval Tree test-suite
4  * Copyright (c) 2025 Wei Yang <richard.weiyang@gmail.com>
5  */
6 #include <linux/math64.h>
7 #include <linux/kern_levels.h>
8 #include "shared.h"
9 
10 #include "../../../lib/interval_tree_test.c"
11 
12 int usage(void)
13 {
14 	fprintf(stderr, "Userland interval tree test cases\n");
15 	fprintf(stderr, "  -n: Number of nodes in the interval tree\n");
16 	fprintf(stderr, "  -p: Number of iterations modifying the tree\n");
17 	fprintf(stderr, "  -q: Number of searches to the interval tree\n");
18 	fprintf(stderr, "  -s: Number of iterations searching the tree\n");
19 	fprintf(stderr, "  -a: Searches will iterate all nodes in the tree\n");
20 	fprintf(stderr, "  -m: Largest value for the interval's endpoint\n");
21 	fprintf(stderr, "  -r: Random seed\n");
22 	exit(-1);
23 }
24 
25 void interval_tree_tests(void)
26 {
27 	interval_tree_test_init();
28 	interval_tree_test_exit();
29 }
30 
31 int main(int argc, char **argv)
32 {
33 	int opt;
34 
35 	while ((opt = getopt(argc, argv, "n:p:q:s:am:r:")) != -1) {
36 		if (opt == 'n')
37 			nnodes = strtoul(optarg, NULL, 0);
38 		else if (opt == 'p')
39 			perf_loops = strtoul(optarg, NULL, 0);
40 		else if (opt == 'q')
41 			nsearches = strtoul(optarg, NULL, 0);
42 		else if (opt == 's')
43 			search_loops = strtoul(optarg, NULL, 0);
44 		else if (opt == 'a')
45 			search_all = true;
46 		else if (opt == 'm')
47 			max_endpoint = strtoul(optarg, NULL, 0);
48 		else if (opt == 'r')
49 			seed = strtoul(optarg, NULL, 0);
50 		else
51 			usage();
52 	}
53 
54 	interval_tree_tests();
55 	return 0;
56 }
57