diff mbox series

[v3,2/3] maple_tree: add a test check deficient node

Message ID 20241113031616.10530-3-richard.weiyang@gmail.com (mailing list archive)
State New
Headers show
Series simplify split calculation | expand

Commit Message

Wei Yang Nov. 13, 2024, 3:16 a.m. UTC
Add a test to assert when resulting a deficient node on splitting.

We can achieve this by build a tree with two nodes. With the left
node with consecutive data from 0 and leave some room for the final
insert to locate in left node. And the right node a full node to force
the split happens on the left node.

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 lib/test_maple_tree.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Liam R. Howlett Nov. 13, 2024, 6:40 p.m. UTC | #1
* Wei Yang <richard.weiyang@gmail.com> [241112 22:17]:
> Add a test to assert when resulting a deficient node on splitting.
> 
> We can achieve this by build a tree with two nodes. With the left
> node with consecutive data from 0 and leave some room for the final
> insert to locate in left node. And the right node a full node to force
> the split happens on the left node.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> CC: Liam R. Howlett <Liam.Howlett@Oracle.com>
> CC: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> CC: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

Reviewed-by: Liam R. Howlett <Liam.Howlett@Oracle.com>

> ---
>  lib/test_maple_tree.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c
> index 704cb1093ae8..72bda304b595 100644
> --- a/lib/test_maple_tree.c
> +++ b/lib/test_maple_tree.c
> @@ -1563,6 +1563,30 @@ static noinline void __init check_root_expand(struct maple_tree *mt)
>  	mas_unlock(&mas);
>  }
>  
> +static noinline void __init check_deficient_node(struct maple_tree *mt)
> +{
> +	MA_STATE(mas, mt, 0, 0);
> +	int count;
> +
> +	mas_lock(&mas);
> +	for (count = 0; count < 10; count++) {
> +		mas_set(&mas, count);
> +		mas_store_gfp(&mas, xa_mk_value(count), GFP_KERNEL);
> +	}
> +
> +	for (count = 20; count < 39; count++) {
> +		mas_set(&mas, count);
> +		mas_store_gfp(&mas, xa_mk_value(count), GFP_KERNEL);
> +	}
> +
> +	for (count = 10; count < 12; count++) {
> +		mas_set(&mas, count);
> +		mas_store_gfp(&mas, xa_mk_value(count), GFP_KERNEL);
> +	}
> +	mas_unlock(&mas);
> +	mt_validate(mt);
> +}
> +
>  static noinline void __init check_gap_combining(struct maple_tree *mt)
>  {
>  	struct maple_enode *mn1, *mn2;
> @@ -3796,6 +3820,10 @@ static int __init maple_tree_seed(void)
>  	goto skip;
>  #endif
>  
> +	mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
> +	check_deficient_node(&tree);
> +	mtree_destroy(&tree);
> +
>  	mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
>  	check_store_null(&tree);
>  	mtree_destroy(&tree);
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c
index 704cb1093ae8..72bda304b595 100644
--- a/lib/test_maple_tree.c
+++ b/lib/test_maple_tree.c
@@ -1563,6 +1563,30 @@  static noinline void __init check_root_expand(struct maple_tree *mt)
 	mas_unlock(&mas);
 }
 
+static noinline void __init check_deficient_node(struct maple_tree *mt)
+{
+	MA_STATE(mas, mt, 0, 0);
+	int count;
+
+	mas_lock(&mas);
+	for (count = 0; count < 10; count++) {
+		mas_set(&mas, count);
+		mas_store_gfp(&mas, xa_mk_value(count), GFP_KERNEL);
+	}
+
+	for (count = 20; count < 39; count++) {
+		mas_set(&mas, count);
+		mas_store_gfp(&mas, xa_mk_value(count), GFP_KERNEL);
+	}
+
+	for (count = 10; count < 12; count++) {
+		mas_set(&mas, count);
+		mas_store_gfp(&mas, xa_mk_value(count), GFP_KERNEL);
+	}
+	mas_unlock(&mas);
+	mt_validate(mt);
+}
+
 static noinline void __init check_gap_combining(struct maple_tree *mt)
 {
 	struct maple_enode *mn1, *mn2;
@@ -3796,6 +3820,10 @@  static int __init maple_tree_seed(void)
 	goto skip;
 #endif
 
+	mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
+	check_deficient_node(&tree);
+	mtree_destroy(&tree);
+
 	mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
 	check_store_null(&tree);
 	mtree_destroy(&tree);