]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
tools: Add support for running rosebush tests in userspace
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 21 Jun 2024 19:01:14 +0000 (15:01 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 26 Jun 2024 13:08:24 +0000 (09:08 -0400)
Enable make -C tools/testing/radix-tree.  Much easier to debug than
an in-kernel module.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
tools/include/linux/rosebush.h [new file with mode: 0644]
tools/testing/radix-tree/.gitignore
tools/testing/radix-tree/Makefile
tools/testing/radix-tree/kunit/test.h [new file with mode: 0644]
tools/testing/radix-tree/rosebush.c [new file with mode: 0644]

diff --git a/tools/include/linux/rosebush.h b/tools/include/linux/rosebush.h
new file mode 100644 (file)
index 0000000..3f12f42
--- /dev/null
@@ -0,0 +1 @@
+#include "../../../include/linux/rosebush.h"
index 49bccb90c35ba00d05353624b70393e1fd0c5243..fb154f26bdabd045c604ce280b4b1eced7a8b518 100644 (file)
@@ -9,3 +9,4 @@ radix-tree.c
 xarray
 maple
 ma_xa_benchmark
+rosebush
index 7527f738b4a14b28d243f9e263428caf06458c9f..982ff4b7fdeb4f1e3614e6269ca361ecf717ca1f 100644 (file)
@@ -4,7 +4,7 @@ CFLAGS += -I. -I../../include -I../../../lib -g -Og -Wall \
          -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined
 LDFLAGS += -fsanitize=address -fsanitize=undefined
 LDLIBS+= -lpthread -lurcu
-TARGETS = main idr-test multiorder xarray maple
+TARGETS = main idr-test multiorder xarray maple rosebush
 CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o \
                         slab.o maple.o
 OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \
@@ -36,6 +36,8 @@ xarray: $(CORE_OFILES)
 
 maple: $(CORE_OFILES)
 
+rosebush: $(CORE_OFILES)
+
 multiorder: multiorder.o $(CORE_OFILES)
 
 clean:
@@ -62,6 +64,8 @@ xarray.o: ../../../lib/xarray.c ../../../lib/test_xarray.c
 
 maple.o: ../../../lib/maple_tree.c ../../../lib/test_maple_tree.c
 
+rosebush.o: ../../../lib/rosebush.c ../../../lib/test_rosebush.c
+
 generated/map-shift.h:
        @if ! grep -qws $(SHIFT) generated/map-shift.h; then            \
                echo "#define XA_CHUNK_SHIFT $(SHIFT)" >                \
diff --git a/tools/testing/radix-tree/kunit/test.h b/tools/testing/radix-tree/kunit/test.h
new file mode 100644 (file)
index 0000000..0805e36
--- /dev/null
@@ -0,0 +1,20 @@
+struct kunit {
+};
+
+struct kunit_case {
+       void (*run_case)(struct kunit *test);
+};
+
+struct kunit_suite {
+       char *name;
+       struct kunit_case *test_cases;
+};
+
+#define KUNIT_CASE(test_name) { .run_case = test_name, }
+#define kunit_test_suite(x)
+
+#define KUNIT_EXPECT_EQ(test, left, right)                             \
+       KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, NULL)
+#define KUNIT_EXPECT_PTR_EQ_MSG(test, left, right, fmt, ...)           \
+       assert(left == right)
+
diff --git a/tools/testing/radix-tree/rosebush.c b/tools/testing/radix-tree/rosebush.c
new file mode 100644 (file)
index 0000000..5170373
--- /dev/null
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * rosebush.c: Userspace testing for rosebush test-suite
+ * Copyright (c) 2024 Oracle Corporation
+ * Author: Matthew Wilcox <willy@infradead.org>
+ */
+
+#include "test.h"
+#include <stdlib.h>
+#include <time.h>
+
+#define module_init(x)
+#define module_exit(x)
+#define MODULE_AUTHOR(x)
+#define MODULE_LICENSE(x)
+#define dump_stack()   assert(0)
+
+#include "../../../lib/rosebush.c"
+#include "../../../lib/test_rosebush.c"
+
+int __weak main(void)
+{
+       struct kunit test;
+       int i;
+
+       assert(rosebush_suite.test_cases == rosebush_cases);
+
+       for (i = 0; i < ARRAY_SIZE(rosebush_cases); i++) {
+               if (!rosebush_cases[i].run_case)
+                       continue;
+               printf("i = %d %p\n", i, rosebush_cases[i].run_case);
+               rosebush_cases[i].run_case(&test);
+       }
+
+       return 0;
+}