xref: /openbmc/linux/tools/testing/radix-tree/maple.c (revision ae108c48)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * maple_tree.c: Userspace shim for maple tree test-suite
4  * Copyright (c) 2018 Liam R. Howlett <Liam.Howlett@Oracle.com>
5  */
6 
7 #define CONFIG_DEBUG_MAPLE_TREE
8 #define CONFIG_MAPLE_SEARCH
9 #include "test.h"
10 
11 #define module_init(x)
12 #define module_exit(x)
13 #define MODULE_AUTHOR(x)
14 #define MODULE_LICENSE(x)
15 #define dump_stack()	assert(0)
16 
17 #include "../../../lib/maple_tree.c"
18 #undef CONFIG_DEBUG_MAPLE_TREE
19 #include "../../../lib/test_maple_tree.c"
20 
21 void farmer_tests(void)
22 {
23 	struct maple_node *node;
24 	DEFINE_MTREE(tree);
25 
26 	mt_dump(&tree);
27 
28 	tree.ma_root = xa_mk_value(0);
29 	mt_dump(&tree);
30 
31 	node = mt_alloc_one(GFP_KERNEL);
32 	node->parent = (void *)((unsigned long)(&tree) | 1);
33 	node->slot[0] = xa_mk_value(0);
34 	node->slot[1] = xa_mk_value(1);
35 	node->mr64.pivot[0] = 0;
36 	node->mr64.pivot[1] = 1;
37 	node->mr64.pivot[2] = 0;
38 	tree.ma_root = mt_mk_node(node, maple_leaf_64);
39 	mt_dump(&tree);
40 
41 	ma_free_rcu(node);
42 }
43 
44 void maple_tree_tests(void)
45 {
46 	farmer_tests();
47 	maple_tree_seed();
48 	maple_tree_harvest();
49 }
50 
51 int __weak main(void)
52 {
53 	maple_tree_init();
54 	maple_tree_tests();
55 	rcu_barrier();
56 	if (nr_allocated)
57 		printf("nr_allocated = %d\n", nr_allocated);
58 	return 0;
59 }
60