From: Liam R. Howlett Date: Mon, 1 Mar 2021 19:36:18 +0000 (-0500) Subject: lib/test_maple_tree: Rename zero() to not_empty(), use mas_set(), add more allocation... X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=3dca0bfb4c52d2ec690af880e37bb01cfa6e5b2c;p=users%2Fjedix%2Flinux-maple.git lib/test_maple_tree: Rename zero() to not_empty(), use mas_set(), add more allocation tests Signed-off-by: Liam R. Howlett --- diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 8e4ebda159ca..0f5548cd4bca 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -198,7 +198,7 @@ static noinline void check_nomem(struct maple_tree *mt) mtree_destroy(mt); } -static inline int zeroed(struct maple_node *node) +static inline int not_empty(struct maple_node *node) { int i; @@ -215,7 +215,7 @@ static inline int zeroed(struct maple_node *node) static noinline void check_new_node(struct maple_tree *mt) { - struct maple_node *mn; + struct maple_node *mn, *mn2, *mn3; struct maple_alloc *smn; struct maple_node *nodes[100]; int i, j, total; @@ -234,7 +234,7 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mas_allocated(&mas) != 3); mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, mas.alloc == NULL); MT_BUG_ON(mt, mas.alloc->slot[0] == NULL); @@ -254,7 +254,7 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL)); // Eat the requested node. mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, mn->slot[0] != NULL); MT_BUG_ON(mt, mn->slot[1] != NULL); @@ -289,7 +289,7 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mas_allocated(&mas) != 1); // Check the node is only one node. mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != 0); MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, mn->slot[0] != NULL); @@ -311,7 +311,7 @@ static noinline void check_new_node(struct maple_tree *mt) mn = mas_pop_node(&mas); MT_BUG_ON(mt, mas_allocated(&mas) != i); MT_BUG_ON(mt, !mn); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); ma_free_rcu(mn); } @@ -331,7 +331,7 @@ static noinline void check_new_node(struct maple_tree *mt) e = i - 2; MT_BUG_ON(mt, mas.alloc->node_count != e); mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != i - 1); MT_BUG_ON(mt, !mn); ma_free_rcu(mn); @@ -346,11 +346,11 @@ static noinline void check_new_node(struct maple_tree *mt) mn = mas_pop_node(&mas); MT_BUG_ON(mt, mas_allocated(&mas) != j - 1); MT_BUG_ON(mt, !mn); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); mas_push_node(&mas, (struct maple_enode *)mn); MT_BUG_ON(mt, mas_allocated(&mas) != j); mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != j - 1); ma_free_rcu(mn); } @@ -374,7 +374,7 @@ static noinline void check_new_node(struct maple_tree *mt) for (j = 0; j <= i/2; j++) { MT_BUG_ON(mt, mas_allocated(&mas) != i - j); mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); ma_free_rcu(mn); MT_BUG_ON(mt, mas_allocated(&mas) != i - j - 1); } @@ -410,7 +410,7 @@ static noinline void check_new_node(struct maple_tree *mt) for (j = i; j > 0; j--) { //Free the requests mn = mas_pop_node(&mas); // get the next node. MT_BUG_ON(mt, mn == NULL); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); ma_free_rcu(mn); } MT_BUG_ON(mt, mas_allocated(&mas) != 0); @@ -424,7 +424,7 @@ static noinline void check_new_node(struct maple_tree *mt) for (j = 1; j <= i; j++) { // Move the allocations to mas2 mn = mas_pop_node(&mas); // get the next node. MT_BUG_ON(mt, mn == NULL); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); mas_push_node(&mas2, (struct maple_enode *)mn); MT_BUG_ON(mt, mas_allocated(&mas2) != j); } @@ -435,7 +435,7 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mas_allocated(&mas2) != j); mn = mas_pop_node(&mas2); // get the next node. MT_BUG_ON(mt, mn == NULL); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); ma_free_rcu(mn); } MT_BUG_ON(mt, mas_allocated(&mas2) != 0); @@ -451,7 +451,7 @@ static noinline void check_new_node(struct maple_tree *mt) mn = mas_pop_node(&mas); // get the next node. MT_BUG_ON(mt, mn == NULL); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS); MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 2); @@ -468,21 +468,92 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mas.alloc->node_count); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 2); mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 1); MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 1); mas_push_node(&mas, (struct maple_enode *)mn); MT_BUG_ON(mt, mas.alloc->node_count); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 2); mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); ma_free_rcu(mn); for (i = 1; i <= MAPLE_ALLOC_SLOTS + 1; i++) { mn = mas_pop_node(&mas); - MT_BUG_ON(mt, zeroed(mn)); + MT_BUG_ON(mt, not_empty(mn)); ma_free_rcu(mn); } MT_BUG_ON(mt, mas_allocated(&mas) != 0); + + + for (i = 3; i < MAPLE_NODE_MASK * 3; i++) { + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, i); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mn = mas_pop_node(&mas); // get the next node. + mas_push_node(&mas, (struct maple_enode *)mn); // put it back + mas_destroy(&mas); + + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, i); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mn = mas_pop_node(&mas); // get the next node. + mn2 = mas_pop_node(&mas); // get the next node. + mas_push_node(&mas, (struct maple_enode *)mn); // put them back + mas_push_node(&mas, (struct maple_enode *)mn2); + mas_destroy(&mas); + + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, i); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mn = mas_pop_node(&mas); // get the next node. + mn2 = mas_pop_node(&mas); // get the next node. + mn3 = mas_pop_node(&mas); // get the next node. + mas_push_node(&mas, (struct maple_enode *)mn); // put them back + mas_push_node(&mas, (struct maple_enode *)mn2); + mas_push_node(&mas, (struct maple_enode *)mn3); + mas_destroy(&mas); + + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, i); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mn = mas_pop_node(&mas); // get the next node. + ma_free_rcu(mn); + mas_destroy(&mas); + + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, i); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mn = mas_pop_node(&mas); // get the next node. + ma_free_rcu(mn); + mn = mas_pop_node(&mas); // get the next node. + ma_free_rcu(mn); + mn = mas_pop_node(&mas); // get the next node. + ma_free_rcu(mn); + mas_destroy(&mas); + } + + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, 5); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + MT_BUG_ON(mt, mas_allocated(&mas) != 5); + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, 10); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mas.node = MAS_START; + MT_BUG_ON(mt, mas_allocated(&mas) != 10); + mas_destroy(&mas); + + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, MAPLE_ALLOC_SLOTS - 1); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS - 1); + mas.node = MA_ERROR(-ENOMEM); + mas_node_count(&mas, 10 + MAPLE_ALLOC_SLOTS - 1); // Request + mas_nomem(&mas, GFP_KERNEL); // Fill request + mas.node = MAS_START; + MT_BUG_ON(mt, mas_allocated(&mas) != 10 + MAPLE_ALLOC_SLOTS - 1); + mas_destroy(&mas); + mtree_unlock(mt); mtree_destroy(mt); } @@ -622,9 +693,8 @@ static noinline void check_find(struct maple_tree *mt) } val = 0; - mas_reset(&mas); - mas.index = val; - + mas_set(&mas, val); + mas_lock(&mas); while ((entry = mas_find(&mas, 268435456)) != NULL) { if (val != 64) MT_BUG_ON(mt, xa_mk_value(val) != entry); @@ -636,10 +706,11 @@ static noinline void check_find(struct maple_tree *mt) if (!val) val = 1; } + mas_unlock(&mas); val = 0; - mas_reset(&mas); - mas.index = val; + mas_set(&mas, val); + mas_lock(&mas); mas_for_each(&mas, entry, ULONG_MAX) { if (val != 64) MT_BUG_ON(mt, xa_mk_value(val) != entry); @@ -650,6 +721,7 @@ static noinline void check_find(struct maple_tree *mt) if (!val) val = 1; } + mas_unlock(&mas); /* Test mas_pause */ val = 0; @@ -721,7 +793,6 @@ static noinline void check_find(struct maple_tree *mt) val = 0; mas_set(&mas, 0); - mas_reset(&mas); mas_lock(&mas); mas_for_each(&mas, entry, ULONG_MAX) { if (val == 64) @@ -779,9 +850,7 @@ static noinline void check_find(struct maple_tree *mt) entry2 = mas_prev(&mas, 0); MT_BUG_ON(mt, entry != entry2); - mas_reset(&mas); - mas.index = 0; - mas.last = 0; + mas_set(&mas, 0); MT_BUG_ON(mt, !!mas_prev(&mas, 0)); mas_unlock(&mas); @@ -35444,7 +35513,7 @@ static noinline void check_mas_store_gfp(struct maple_tree *mt) newmas.last = mas.last; mas_store_gfp(&newmas, val, GFP_KERNEL); } - printk("alloc is %px\n", newmas.alloc); + mt_validate(&newmt); mt_set_non_kernel(0); mtree_destroy(&newmt);