]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
test_maple_tree: Re-implement old allocation tests for new API.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 28 Jan 2019 18:30:15 +0000 (13:30 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:28:02 +0000 (12:28 -0500)
Rewrite the allocation tests for maple2 rewrite.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/test_maple_tree.c

index 3be618811071a9bea2498b2bdbbdec55a5851c94..22d912ddce5dfa19d0890a21b0c131cb302332a1 100644 (file)
@@ -142,59 +142,57 @@ static noinline void check_nomem(struct maple_tree *mt)
        mtree_destroy(mt);
 }
 
-static noinline int alloc_req(struct ma_state *ms) {
-       return (int)(((unsigned long)ms->alloc & 0x03));
-}
 static noinline void check_new_node(struct maple_tree *mt)
 {
-#if 0
 
        struct maple_node *mn;
-       MA_STATE(ms, mt, 0, 0);
+       MA_STATE(mas, 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));
+       mas_node_cnt(&mas, 3); // request 3 nodes to be allocated.
+       MT_BUG_ON(mt, ma_get_alloc_req(&mas) != 3); // Allocation request of 3.
+       MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM)); // Allocate failed.
+       MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL));
 
 
-       MT_BUG_ON(mt, ma_get_alloc_cnt(&ms) != 3);
-       mn = ma_get_alloc(&ms);
+       MT_BUG_ON(mt, ma_get_alloc_cnt(&mas) != 3);
+       mn = ma_get_alloc(&mas);
        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;
+       mas_nomem(&mas, 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);
+       ma_set_alloc_req(&mas, 1); // Set allocation request to 1.
+       MT_BUG_ON(mt, ma_get_alloc_req(&mas) != 1); // Check Allocation request of 1.
+       mas_set_err(&mas, -ENOMEM);
+       MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL)); // Validate allocation request.
+       mn = ma_next_alloc(&mas); // Eat the requested node.
 
        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.
+       MT_BUG_ON(mt, ma_get_alloc_cnt(&mas) != 0);
 
-       mas_nomem(&ms, GFP_KERNEL); // Validate request for 2 more.
+       mt_free(mn);
+       mas_node_cnt(&mas, 3); // Allocate 3 nodes, will fail.
+       mas_nomem(&mas, GFP_KERNEL); // Drop the lock and allocate 3 nodes.
+       MT_BUG_ON(mt, ma_get_alloc_cnt(&mas) != 3); // Ensure 3 are allocated.
+       MT_BUG_ON(mt, ma_get_alloc_req(&mas) != 0); // Allocation request of 0.
+
+       mn = mas.alloc;
        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.
+       MT_BUG_ON(mt, ma_get_alloc_cnt(&mas) != 3); // Ensure we counted 3.
+       mas_nomem(&mas, GFP_KERNEL); // Free.
 
        mtree_unlock(mt);
        mtree_destroy(mt);
-#endif
 }
 static noinline void check_seq(struct maple_tree *mt)
 {