[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230828184353.5145-5-yury.norov@gmail.com>
Date: Mon, 28 Aug 2023 11:43:44 -0700
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Yury Norov <yury.norov@...il.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>
Subject: [PATCH 04/12] bitmap: add test for bitmap_bitremap()
Similarly to bitmap_remap, test bitmap_bitremap().
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
lib/test_bitmap.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index e1c22d399f24..e9211f9a0e67 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -378,6 +378,19 @@ static void __init test_weight(void)
}
}
+static __always_inline void __init __test_bitremap(unsigned long *dst, unsigned long *src,
+ unsigned long *old, unsigned long *new, unsigned long nbits)
+{
+ unsigned long oldbit, newbit;
+
+ bitmap_zero(dst, nbits);
+
+ for_each_set_bit(oldbit, src, nbits) {
+ newbit = bitmap_bitremap(oldbit, old, new, nbits);
+ __set_bit(newbit, dst);
+ }
+}
+
static void __init test_remap(void)
{
DECLARE_BITMAP(dst, 8);
@@ -402,6 +415,9 @@ static void __init test_remap(void)
bitmap_remap(dst, src, old, new, 8);
expect_eq_bitmap(exp0, dst, 8);
+ __test_bitremap(dst, src, old, new, 8);
+ expect_eq_bitmap(exp0, dst, 8);
+
/*
* When old mapping is the same as new, source bits are copied to dst.
* Real code must use bitmap_copy() if it's known in advance.
@@ -409,6 +425,9 @@ static void __init test_remap(void)
bitmap_remap(dst, src, old, old, 8);
expect_eq_bitmap(src, dst, 8);
+ __test_bitremap(dst, src, old, old, 8);
+ expect_eq_bitmap(src, dst, 8);
+
bitmap_remap(dst, src, new, new, 8);
expect_eq_bitmap(src, dst, 8);
@@ -419,23 +438,38 @@ static void __init test_remap(void)
bitmap_remap(dst, src, empty, new, 8);
expect_eq_bitmap(src, dst, 8);
+ __test_bitremap(dst, src, empty, new, 8);
+ expect_eq_bitmap(src, dst, 8);
+
bitmap_remap(dst, src, old, empty, 8);
expect_eq_bitmap(src, dst, 8);
+ __test_bitremap(dst, src, old, empty, 8);
+ expect_eq_bitmap(src, dst, 8);
+
bitmap_remap(dst, src, empty, empty, 8);
expect_eq_bitmap(src, dst, 8);
+ __test_bitremap(dst, src, empty, empty, 8);
+ expect_eq_bitmap(src, dst, 8);
+
/* Set extra bit in old map to test carry logic */
set_bit(5, old);
bitmap_remap(dst, src, old, new, 8);
expect_eq_bitmap(exp1, dst, 8);
+ __test_bitremap(dst, src, old, new, 8);
+ expect_eq_bitmap(exp1, dst, 8);
+
/* Map old bits to #7 */
bitmap_zero(new, 8);
set_bit(7, new);
bitmap_remap(dst, src, old, new, 8);
expect_eq_bitmap(exp2, dst, 8);
+ __test_bitremap(dst, src, old, new, 8);
+ expect_eq_bitmap(exp2, dst, 8);
+
bitmap_fill(perf_src, 1000);
bitmap_set(perf_old, 0, 500);
bitmap_clear(perf_old, 500, 500);
--
2.39.2
Powered by blists - more mailing lists