]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Make test code work without debug enabled
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 1 Dec 2022 16:48:12 +0000 (11:48 -0500)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 27 Apr 2023 01:32:01 +0000 (21:32 -0400)
The test code is less useful without debug, but can still do general
validations.  Define mt_dump(), mas_dump() and mas_wr_dump() as a noop
if debug is not enabled and document it in the test module information
that more information can be obtained with another kernel config option.

MT_BUG_ON() will report a failures without tree dumps, and the output
will be less useful.

Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
lib/Kconfig.debug
lib/test_maple_tree.c
tools/testing/radix-tree/maple.c

index 5cd8183bb4c13e943e71cd2ee141c304c3b332c4..11736e17a62d88d8dbc042bfe6268763a42214ca 100644 (file)
@@ -2281,9 +2281,13 @@ config TEST_XARRAY
        tristate "Test the XArray code at runtime"
 
 config TEST_MAPLE_TREE
-       depends on DEBUG_KERNEL
-       select DEBUG_MAPLE_TREE
-       tristate "Test the Maple Tree code at runtime"
+       tristate "Test the Maple Tree code at runtime or module load"
+       help
+         Enable this option to test the maple tree code functions at boot, or
+         when the module is loaded. Enable "Debug Maple Trees" will enable
+         more verbose output on failures.
+
+         If unsure, say N.
 
 config TEST_RHASHTABLE
        tristate "Perform selftest on resizable hash table"
index d6929270dd36a350a239a0f8f6ed6c0752cbf8ad..93b40a78c4f55cb9f9523aa5b215db09c280c1cf 100644 (file)
 #include <linux/module.h>
 
 #define MTREE_ALLOC_MAX 0x2000000000000Ul
-#ifndef CONFIG_DEBUG_MAPLE_TREE
-#define CONFIG_DEBUG_MAPLE_TREE
-#endif
 #define CONFIG_MAPLE_SEARCH
 #define MAPLE_32BIT (MAPLE_NODE_SLOTS > 31)
 
+#ifndef CONFIG_DEBUG_MAPLE_TREE
+#define mt_dump(mt, fmt)               do {} while (0)
+#define mt_validate(mt)                        do {} while (0)
+#define mt_cache_shrink()              do {} while (0)
+#define mas_dump(mas)                  do {} while (0)
+#define mas_wr_dump(mas)               do {} while (0)
+atomic_t maple_tree_tests_run;
+atomic_t maple_tree_tests_passed;
+#undef MT_BUG_ON
+
+#define MT_BUG_ON(__tree, __x) do {                                    \
+       atomic_inc(&maple_tree_tests_run);                              \
+       if (__x) {                                                      \
+               pr_info("BUG at %s:%d (%u)\n",                          \
+               __func__, __LINE__, __x);                               \
+               pr_info("Pass: %u Run:%u\n",                            \
+                       atomic_read(&maple_tree_tests_passed),          \
+                       atomic_read(&maple_tree_tests_run));            \
+       } else {                                                        \
+               atomic_inc(&maple_tree_tests_passed);                   \
+       }                                                               \
+} while (0)
+#endif
+
 /* #define BENCH_SLOT_STORE */
 /* #define BENCH_NODE_STORE */
 /* #define BENCH_AWALK */
index ebcb3faf85ea934d6ccd7ef2787dd2bd48a3219d..cf37ed9ab6c4d27ca1f444eb68e46b1dd46b2832 100644 (file)
@@ -22,7 +22,6 @@
 #define dump_stack()   assert(0)
 
 #include "../../../lib/maple_tree.c"
-#undef CONFIG_DEBUG_MAPLE_TREE
 #include "../../../lib/test_maple_tree.c"
 
 #define RCU_RANGE_COUNT 1000