Skip to content

Commit 431e106

Browse files
RichardWeiYangakpm00
authored andcommitted
maple_tree: add a test checking storing null
Add a test to assert that, when storing null to am empty tree or a single entry tree it will not result into: * a root node with range [0, ULONG_MAX] set to NULL * a root node with consecutive slot set to NULL [[email protected]: work around build error (mas_root)] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Wei Yang <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Sidhartha Kumar <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0ea120b commit 431e106

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

lib/test_maple_tree.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,92 @@ static noinline void __init check_prev_entry(struct maple_tree *mt)
13871387
mas_unlock(&mas);
13881388
}
13891389

1390+
static noinline void __init check_store_null(struct maple_tree *mt)
1391+
{
1392+
MA_STATE(mas, mt, 0, ULONG_MAX);
1393+
1394+
/*
1395+
* Store NULL at range [0, ULONG_MAX] to an empty tree should result
1396+
* in an empty tree
1397+
*/
1398+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1399+
mas_lock(&mas);
1400+
mas_store_gfp(&mas, NULL, GFP_KERNEL);
1401+
MT_BUG_ON(mt, !mtree_empty(mt));
1402+
mas_unlock(&mas);
1403+
mtree_destroy(mt);
1404+
1405+
/*
1406+
* Store NULL at any range to an empty tree should result in an empty
1407+
* tree
1408+
*/
1409+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1410+
mas_lock(&mas);
1411+
mas_set_range(&mas, 3, 10);
1412+
mas_store_gfp(&mas, NULL, GFP_KERNEL);
1413+
MT_BUG_ON(mt, !mtree_empty(mt));
1414+
mas_unlock(&mas);
1415+
mtree_destroy(mt);
1416+
1417+
/*
1418+
* Store NULL at range [0, ULONG_MAX] to a single entry tree should
1419+
* result in an empty tree
1420+
*/
1421+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1422+
mas_lock(&mas);
1423+
mas_set(&mas, 0);
1424+
mas_store_gfp(&mas, &mas, GFP_KERNEL);
1425+
mas_set_range(&mas, 0, ULONG_MAX);
1426+
mas_store_gfp(&mas, NULL, GFP_KERNEL);
1427+
MT_BUG_ON(mt, !mtree_empty(mt));
1428+
mas_unlock(&mas);
1429+
mtree_destroy(mt);
1430+
1431+
/*
1432+
* Store NULL at range [0, n] to a single entry tree should
1433+
* result in an empty tree
1434+
*/
1435+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1436+
mas_lock(&mas);
1437+
mas_set(&mas, 0);
1438+
mas_store_gfp(&mas, &mas, GFP_KERNEL);
1439+
mas_set_range(&mas, 0, 5);
1440+
mas_store_gfp(&mas, NULL, GFP_KERNEL);
1441+
MT_BUG_ON(mt, !mtree_empty(mt));
1442+
mas_unlock(&mas);
1443+
mtree_destroy(mt);
1444+
1445+
/*
1446+
* Store NULL at range [m, n] where m > 0 to a single entry tree
1447+
* should still be a single entry tree
1448+
*/
1449+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1450+
mas_lock(&mas);
1451+
mas_set(&mas, 0);
1452+
mas_store_gfp(&mas, &mas, GFP_KERNEL);
1453+
mas_set_range(&mas, 2, 5);
1454+
mas_store_gfp(&mas, NULL, GFP_KERNEL);
1455+
MT_BUG_ON(mt, mtree_empty(mt));
1456+
// MT_BUG_ON(mt, xa_is_node(mas_root(&mas)));
1457+
mas_unlock(&mas);
1458+
mtree_destroy(mt);
1459+
1460+
/*
1461+
* Store NULL at range [0, ULONG_MAX] to a tree with node should
1462+
* result in an empty tree
1463+
*/
1464+
mt_init_flags(mt, MT_FLAGS_ALLOC_RANGE);
1465+
mas_lock(&mas);
1466+
mas_set_range(&mas, 1, 3);
1467+
mas_store_gfp(&mas, &mas, GFP_KERNEL);
1468+
// MT_BUG_ON(mt, !xa_is_node(mas_root(&mas)));
1469+
mas_set_range(&mas, 0, ULONG_MAX);
1470+
mas_store_gfp(&mas, NULL, GFP_KERNEL);
1471+
MT_BUG_ON(mt, !mtree_empty(mt));
1472+
mas_unlock(&mas);
1473+
mtree_destroy(mt);
1474+
}
1475+
13901476
static noinline void __init check_root_expand(struct maple_tree *mt)
13911477
{
13921478
MA_STATE(mas, mt, 0, 0);
@@ -3710,6 +3796,10 @@ static int __init maple_tree_seed(void)
37103796
goto skip;
37113797
#endif
37123798

3799+
mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
3800+
check_store_null(&tree);
3801+
mtree_destroy(&tree);
3802+
37133803
mt_init_flags(&tree, MT_FLAGS_ALLOC_RANGE);
37143804
check_root_expand(&tree);
37153805
mtree_destroy(&tree);

0 commit comments

Comments
 (0)