maple_tree: make test code work without debug enabled
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 18 May 2023 14:55:25 +0000 (10:55 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 9 Jun 2023 23:25:31 +0000 (16:25 -0700)
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.

Link: https://lkml.kernel.org/r/20230518145544.1722059-17-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: David Binderman <dcb314@hotmail.com>
Cc: Peng Zhang <zhangpeng.00@bytedance.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Vernon Yang <vernon2gm@gmail.com>
Cc: Wei Yang <richard.weiyang@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/Kconfig.debug
lib/test_maple_tree.c
tools/testing/radix-tree/maple.c

index ce51d4dc6803ede3cc16008ef0eeec481c40c2be..f202648dead956660d78ba80fdf7bab9f9736485 100644 (file)
@@ -2302,9 +2302,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