From: Liam R. Howlett Date: Mon, 10 Dec 2018 19:07:17 +0000 (-0500) Subject: lib/test_maple_tree: Add tests for allocations. X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1b57e1551d64b6282135e6ff10320465cde1be3f;p=users%2Fjedix%2Flinux-maple.git lib/test_maple_tree: Add tests for allocations. Try allocating 3 nodes, free them, allocate 1 and then 2 more. Signed-off-by: Liam R. Howlett --- diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index c2cfd60f5097..f03c77174862 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -129,6 +129,60 @@ static noinline void check_nomem(struct maple_tree *mt) mtree_destroy(mt); } +static noinline int alloc_req(struct maple_state *ms) { + return (int)(((unsigned long)ms->alloc & 0x03)); +} + +static noinline void check_new_node(struct maple_tree *mt) +{ + + struct maple_node *mn; + MAP_STATE(ms, mt, 0, 0); + + /* Try allocating 3 nodes */ + mtree_lock(mt); + maple_state_node(&ms, 3); // req allocate 3 node. + MT_BUG_ON(mt, alloc_req(&ms) != 3); // Allocation request of 3. + + MT_BUG_ON(mt, ms.node != MA_ERROR(-ENOMEM)); // Allocate failed. + MT_BUG_ON(mt, !mas_nomem(&ms, GFP_KERNEL)); + + + MT_BUG_ON(mt, ma_get_alloc_cnt(&ms) != 3); + mn = ma_get_alloc(&ms); + MT_BUG_ON(mt, mn == NULL); + MT_BUG_ON(mt, mn->slot[0] == NULL); + MT_BUG_ON(mt, mn->slot[1] == NULL); + mas_nomem(&ms, GFP_KERNEL); // free; + mtree_unlock(mt); + + + /* Try allocating 1 node, then 2 more */ + mtree_lock(mt); + maple_state_node(&ms, 1); // allocate 1 node. + MT_BUG_ON(mt, alloc_req(&ms) != 1); // Allocation request of 1. + MT_BUG_ON(mt, !mas_nomem(&ms, GFP_KERNEL)); // Validate allocation request. + mn = ma_get_alloc(&ms); + + MT_BUG_ON(mt, mn == NULL); + MT_BUG_ON(mt, mn->slot[0] != NULL); + MT_BUG_ON(mt, mn->slot[1] != NULL); + MT_BUG_ON(mt, ma_get_alloc_cnt(&ms) != 1); + maple_state_node(&ms, 3); // req allocate 3 node. + MT_BUG_ON(mt, ma_get_alloc_cnt(&ms) != 1); // Still only 1 allocated. + MT_BUG_ON(mt, ma_get_alloc_req(&ms) != 2); // Allocation request of 2. + + mas_nomem(&ms, GFP_KERNEL); // Validate request for 2 more. + MT_BUG_ON(mt, mn == NULL); + MT_BUG_ON(mt, mn->slot[0] == NULL); + MT_BUG_ON(mt, mn->slot[1] == NULL); + MT_BUG_ON(mt, ma_get_alloc_cnt(&ms) != 3); // Ensure we counted 3. + mas_nomem(&ms, GFP_KERNEL); // Free. + + mtree_unlock(mt); + mtree_destroy(mt); +} + static noinline void check_seq(struct maple_tree *mt) { int i, j; @@ -156,6 +210,7 @@ static int maple_tree_seed(void) mtree_init(&tree); + check_new_node(&tree); check_load(&tree, set[0], NULL); // See if 15 -> NULL check_insert(&tree, set[9], &tree); // Insert 0