Add one simple test for UFFDIO_API. With that, I also added a bunch of
small but handy helpers along the way.
Signed-off-by: Peter Xu <peterx@xxxxxxxxxx>
---
tools/testing/selftests/mm/uffd-unit-tests.c | 111 ++++++++++++++++++-
tools/testing/selftests/mm/vm_util.c | 10 ++
2 files changed, 120 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
index 6857388783be..dfb44ffad5f5 100644
--- a/tools/testing/selftests/mm/uffd-unit-tests.c
+++ b/tools/testing/selftests/mm/uffd-unit-tests.c
@@ -9,9 +9,118 @@
#ifdef __NR_userfaultfd
+struct {
+ unsigned int pass, skip, fail, total;
+} uffd_test_acct;
+
+static void uffd_test_report(void)
+{
+ printf("Userfaults unit tests: pass=%u, skip=%u, fail=%u (total=%u)\n",
+ uffd_test_acct.pass,
+ uffd_test_acct.skip,
+ uffd_test_acct.fail,
+ uffd_test_acct.total);
+}
+
+static void uffd_test_pass(void)
+{
+ printf("done\n");
+ uffd_test_acct.pass++;
+}
+
+#define uffd_test_start(...) do { \
+ printf(__VA_ARGS__); \
+ printf("... "); \
+ uffd_test_acct.total++; \
+ } while (0)
+
+#define uffd_test_fail(...) do { \
+ printf("failed [reason: "); \
+ printf(__VA_ARGS__); \
+ printf("]\n"); \
+ uffd_test_acct.fail++; \
+ } while (0)
+
+#define uffd_test_skip(...) do { \
+ printf("skipped [reason: "); \
+ printf(__VA_ARGS__); \
+ printf("]\n"); \
+ uffd_test_acct.skip++; \
+ } while (0)
+