[PATCH v6 5/7] test_bits: add tests for __GENMASK() and __GENMASK_ULL()
Vincent Mailhol via B4 Relay
devnull+mailhol.vincent.wanadoo.fr at kernel.org
Fri Mar 7 16:48:52 UTC 2025
From: Vincent Mailhol <mailhol.vincent at wanadoo.fr>
The definitions of GENMASK() and GENMASK_ULL() do not depend any more
on __GENMASK() and __GENMASK_ULL(). Duplicate the existing unit tests
so that __GENMASK{,ULL}() is still covered.
It would be good to have a small assembly test case for GENMASK*() in
case somebody decides to unify both in the future. However, I lack
expertise in assembly to do so. Instead add a FIXME message to
highlight the absence of the asm unit test.
Signed-off-by: Vincent Mailhol <mailhol.vincent at wanadoo.fr>
---
Changelog:
v5 -> v6:
- Add a FIXME message to highlight the absence of the asm
GENMASK*() unit tests.
v4 -> v5:
- No changes.
v3 -> v4:
- New patch.
---
lib/test_bits.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/lib/test_bits.c b/lib/test_bits.c
index c7b38d91e1f16d42b7ca92e62fbd6c19b37e76a0..b0c29b01fb30cbcc759ac1e7106457b18bcd73a0 100644
--- a/lib/test_bits.c
+++ b/lib/test_bits.c
@@ -6,6 +6,23 @@
#include <kunit/test.h>
#include <linux/bits.h>
+/* FIXME: add a test case written in asm for GENMASK() and GENMASK_ULL() */
+
+static void __genmask_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 1ul, __GENMASK(0, 0));
+ KUNIT_EXPECT_EQ(test, 3ul, __GENMASK(1, 0));
+ KUNIT_EXPECT_EQ(test, 6ul, __GENMASK(2, 1));
+ KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, __GENMASK(31, 0));
+}
+
+static void __genmask_ull_test(struct kunit *test)
+{
+ KUNIT_EXPECT_EQ(test, 1ull, __GENMASK_ULL(0, 0));
+ KUNIT_EXPECT_EQ(test, 3ull, __GENMASK_ULL(1, 0));
+ KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, __GENMASK_ULL(39, 21));
+ KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, __GENMASK_ULL(63, 0));
+}
static void genmask_test(struct kunit *test)
{
@@ -93,6 +110,8 @@ static void genmask_input_check_test(struct kunit *test)
static struct kunit_case bits_test_cases[] = {
+ KUNIT_CASE(__genmask_test),
+ KUNIT_CASE(__genmask_ull_test),
KUNIT_CASE(genmask_test),
KUNIT_CASE(genmask_ull_test),
KUNIT_CASE(genmask_u128_test),
--
2.45.3
More information about the dri-devel
mailing list