]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple tree tests: Erase entries individually
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 16 Oct 2019 00:50:29 +0000 (20:50 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 16 Oct 2019 12:48:03 +0000 (08:48 -0400)
This should result in the tree being empty.  Right now, it doesn't --
the nodes full of deleted entries are not themselves deleted.

Also fix the lack of locking around the mas iteration.

lib/test_maple_tree.c

index b9593a94ec0807c1037975feeaac9b49bc3c8df4..594d012c8376747e9e1a4c2f81a2855b121225c8 100644 (file)
@@ -36,6 +36,12 @@ int mtree_insert_index(struct maple_tree *mt, unsigned long index, gfp_t gfp)
        return mtree_insert(mt, index, xa_mk_value(index & LONG_MAX), gfp);
 }
 
+static void mtree_erase_index(struct maple_tree *mt, unsigned long index)
+{
+        MT_BUG_ON(mt, mtree_erase(mt, index) != xa_mk_value(index & LONG_MAX));
+        MT_BUG_ON(mt, mtree_load(mt, index) != NULL);
+}
+
 static int mtree_test_insert(struct maple_tree *mt, unsigned long index,
                                void *ptr)
 {
@@ -469,21 +475,29 @@ static noinline void check_find_2(struct maple_tree *mt)
        void *entry;
        MA_STATE(mas, mt, 0, 0);
 
+       rcu_read_lock();
        mas_for_each(&mas, entry, ULONG_MAX)
                MT_BUG_ON(mt, true);
+       rcu_read_unlock();
 
        for (i = 0; i < 256; i++) {
                mtree_insert_index(mt, i, GFP_KERNEL);
                j = 0;
                mas_set(&mas, 0);
+               rcu_read_lock();
                mas_for_each(&mas, entry, ULONG_MAX) {
                        MT_BUG_ON(mt, entry != xa_mk_value(j));
                        j++;
                }
+               rcu_read_unlock();
                MT_BUG_ON(mt, j != i + 1);
        }
 
-       mtree_destroy(mt);
+       for (i = 0; i < 256; i++) {
+               mtree_erase_index(mt, i);
+       }
+
+       MT_BUG_ON(mt, !mtree_empty(mt));
 }
 
 #define erase_ptr(i) entry[i%2]