diff mbox series

[03/21] bcachefs: Run the eytzinger tests on modprobe

Message ID 20250128163859.1883260-4-agruenba@redhat.com (mailing list archive)
State New
Headers show
Series bcachefs: eytzinger code | expand

Commit Message

Andreas Gruenbacher Jan. 28, 2025, 4:38 p.m. UTC
FOR DEBUGGING ONLY -- DO NOT MERGE!

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/bcachefs/eytzinger.c | 12 +++---------
 fs/bcachefs/eytzinger.h |  4 ++++
 fs/bcachefs/super.c     |  5 +++++
 fs/bcachefs/util.c      |  2 +-
 fs/bcachefs/util.h      |  4 ++++
 5 files changed, 17 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/fs/bcachefs/eytzinger.c b/fs/bcachefs/eytzinger.c
index c0fdfe909cf2..08549ab3c18e 100644
--- a/fs/bcachefs/eytzinger.c
+++ b/fs/bcachefs/eytzinger.c
@@ -242,7 +242,7 @@  void eytzinger0_sort(void *base, size_t n, size_t size,
 	return eytzinger0_sort_r(base, n, size, _CMP_WRAPPER, SWAP_WRAPPER, &w);
 }
 
-#if 0
+#if 1
 #include <linux/slab.h>
 #include <linux/random.h>
 #include <linux/ktime.h>
@@ -263,7 +263,7 @@  static int mycmp(const void *a, const void *b)
 		return 0;
 }
 
-static int test(void)
+void eytzinger_sort_test(void)
 {
 	size_t N, i;
 	ktime_t start, end;
@@ -288,17 +288,11 @@  static int test(void)
 		u32 prev = 0;
 
 		eytzinger0_for_each(i, N) {
-			if (prev > arr[i])
-				goto err;
+			BUG_ON(prev > arr[i]);
 			prev = arr[i];
 		}
 
 		kfree(arr);
 	}
-	return 0;
-
-err:
-	kfree(arr);
-	return -1;
 }
 #endif
diff --git a/fs/bcachefs/eytzinger.h b/fs/bcachefs/eytzinger.h
index 0541192d7bc0..16303908ccff 100644
--- a/fs/bcachefs/eytzinger.h
+++ b/fs/bcachefs/eytzinger.h
@@ -5,6 +5,8 @@ 
 #include <linux/bitops.h>
 #include <linux/log2.h>
 
+#define EYTZINGER_DEBUG
+
 #ifdef EYTZINGER_DEBUG
 #define EYTZINGER_BUG_ON(cond)		BUG_ON(cond)
 #else
@@ -316,4 +318,6 @@  void eytzinger0_sort_r(void *, size_t, size_t,
 		       cmp_r_func_t, swap_r_func_t, const void *);
 void eytzinger0_sort(void *, size_t, size_t, cmp_func_t, swap_func_t);
 
+void eytzinger_sort_test(void);
+
 #endif /* _EYTZINGER_H */
diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c
index a6ed9a0bf1c7..d8ad43fb48fc 100644
--- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -2120,6 +2120,11 @@  static int __init bcachefs_init(void)
 {
 	bch2_bkey_pack_test();
 
+	eytzinger_sort_test();
+	eytzinger1_test();
+	eytzinger0_test();
+	eytzinger0_find_test();
+
 	if (!(bcachefs_kset = kset_create_and_add("bcachefs", NULL, fs_kobj)) ||
 	    bch2_btree_key_cache_init() ||
 	    bch2_chardev_init() ||
diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c
index e0a876cbaa6b..9a63d971ee65 100644
--- a/fs/bcachefs/util.c
+++ b/fs/bcachefs/util.c
@@ -698,7 +698,7 @@  void memcpy_from_bio(void *dst, struct bio *src, struct bvec_iter src_iter)
 	}
 }
 
-#if 0
+#if 1
 void eytzinger1_test(void)
 {
 	unsigned inorder, eytz, size;
diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h
index fb02c1c36004..b963c523f5d7 100644
--- a/fs/bcachefs/util.h
+++ b/fs/bcachefs/util.h
@@ -696,4 +696,8 @@  static inline bool test_bit_le64(size_t bit, __le64 *addr)
 	return (addr[bit / 64] & cpu_to_le64(BIT_ULL(bit % 64))) != 0;
 }
 
+void eytzinger1_test(void);
+void eytzinger0_test(void);
+void eytzinger0_find_test(void);
+
 #endif /* _BCACHEFS_UTIL_H */