From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Add some additional tests in lib/test_bits.c to cover the expected
results of the fixed type BIT_U*() macros.
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
Changelog
v4 -> v5:
- BIT_U8()/BIT_U16() are now back to u8/u16.
v3 -> v4:
- New patch.
---
lib/test_bits.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lib/test_bits.c b/lib/test_bits.c
index 91968227687bb11b7d1361b153c27eb851c6c1c2..72984fae7b815031bb6eb2892c772ffcc409cf78 100644
--- a/lib/test_bits.c
+++ b/lib/test_bits.c
@@ -9,6 +9,16 @@
#define assert_type(t, x) _Generic(x, t: x, default: 0)
+static_assert(assert_type(u8, BIT_U8(0)) == 1u);
+static_assert(assert_type(u16, BIT_U16(0)) == 1u);
+static_assert(assert_type(u32, BIT_U32(0)) == 1u);
+static_assert(assert_type(u64, BIT_U64(0)) == 1ull);
+
+static_assert(assert_type(u8, BIT_U8(7)) == 0x80u);
+static_assert(assert_type(u16, BIT_U16(15)) == 0x8000u);
+static_assert(assert_type(u32, BIT_U32(31)) == 0x80000000u);
+static_assert(assert_type(u64, BIT_U64(63)) == 0x8000000000000000ull);
+
static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX);
static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX);
static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX);
--
2.45.3
On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote: >From: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > >Add some additional tests in lib/test_bits.c to cover the expected >results of the fixed type BIT_U*() macros. > >Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> thanks Lucas De Marchi
On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote: > From: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > > Add some additional tests in lib/test_bits.c to cover the expected > results of the fixed type BIT_U*() macros. Still would be good to have a small assembly test case for GENMASK*() as they went split and it will be a good regression test in case somebody decides to unify both without much thinking.. -- With Best Regards, Andy Shevchenko
On 06/03/2025 at 22:11, Andy Shevchenko wrote:
> On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote:
>> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>>
>> Add some additional tests in lib/test_bits.c to cover the expected
>> results of the fixed type BIT_U*() macros.
>
> Still would be good to have a small assembly test case for GENMASK*() as they
> went split and it will be a good regression test in case somebody decides to
> unify both without much thinking..
Let me confirm that I correctly understood your ask. Would something
like this meet your expectations?
diff --git a/lib/test_bits.c b/lib/test_bits.c
index 72984fae7b81..869b291587e6 100644
--- a/lib/test_bits.c
+++ b/lib/test_bits.c
@@ -136,6 +136,29 @@ static void genmask_input_check_test(struct kunit
*test)
KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0));
}
+#undef __LINUX_BITS_H
+#undef GENMASK
+#undef GENMASK_ULL
+#define __ASSEMBLY__
+#include <linux/bits.h>
+static void asm_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 asm_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));
+}
+#undef __ASSEMBLY__
+#undef GENMASK
+#undef GENMASK_ULL
static struct kunit_case bits_test_cases[] = {
KUNIT_CASE(__genmask_test),
@@ -144,6 +167,8 @@ static struct kunit_case bits_test_cases[] = {
KUNIT_CASE(genmask_ull_test),
KUNIT_CASE(genmask_u128_test),
KUNIT_CASE(genmask_input_check_test),
+ KUNIT_CASE(asm_genmask_test),
+ KUNIT_CASE(asm_genmask_ull_test),
{}
};
Yours sincerely,
Vincent Mailhol
On Fri, Mar 07, 2025 at 01:08:15AM +0900, Vincent Mailhol wrote: > On 06/03/2025 at 22:11, Andy Shevchenko wrote: > > On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote: > >> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > >> > >> Add some additional tests in lib/test_bits.c to cover the expected > >> results of the fixed type BIT_U*() macros. > > > > Still would be good to have a small assembly test case for GENMASK*() as they > > went split and it will be a good regression test in case somebody decides to > > unify both without much thinking.. > > Let me confirm that I correctly understood your ask. Would something > like this meet your expectations? I believe it should be written in asm. -- With Best Regards, Andy Shevchenko
On 07/03/2025 at 02:55, Andy Shevchenko wrote: > On Fri, Mar 07, 2025 at 01:08:15AM +0900, Vincent Mailhol wrote: >> On 06/03/2025 at 22:11, Andy Shevchenko wrote: >>> On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote: >>>> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr> >>>> >>>> Add some additional tests in lib/test_bits.c to cover the expected >>>> results of the fixed type BIT_U*() macros. >>> >>> Still would be good to have a small assembly test case for GENMASK*() as they >>> went split and it will be a good regression test in case somebody decides to >>> unify both without much thinking.. >> >> Let me confirm that I correctly understood your ask. Would something >> like this meet your expectations? > > I believe it should be written in asm. I am not confident enough in my assembly skills to submit asm patches to the kernel. So, I would rather take a pass on that one. Regardless, if somebody decides to unify both without much thinking as you said, I am fully confident that the patch will get Nack-ed right away. So, I do not have any concerns. Yours sincerely, Vincent Mailhol
On Fri, Mar 07, 2025 at 07:11:42PM +0900, Vincent Mailhol wrote: > On 07/03/2025 at 02:55, Andy Shevchenko wrote: > > On Fri, Mar 07, 2025 at 01:08:15AM +0900, Vincent Mailhol wrote: > >> On 06/03/2025 at 22:11, Andy Shevchenko wrote: > >>> On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote: > >>>> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr> > >>>> > >>>> Add some additional tests in lib/test_bits.c to cover the expected > >>>> results of the fixed type BIT_U*() macros. > >>> > >>> Still would be good to have a small assembly test case for GENMASK*() as they > >>> went split and it will be a good regression test in case somebody decides to > >>> unify both without much thinking.. > >> > >> Let me confirm that I correctly understood your ask. Would something > >> like this meet your expectations? > > > > I believe it should be written in asm. > > I am not confident enough in my assembly skills to submit asm patches to > the kernel. So, I would rather take a pass on that one. > > Regardless, if somebody decides to unify both without much thinking as > you said, I am fully confident that the patch will get Nack-ed right As I said above "would be good", if you think it's not feasible by you, perhaps a comment (FIXME: ?) in the Kunit test cases that we lack of / need an asm test as well. -- With Best Regards, Andy Shevchenko
On 08/03/2025 at 01:07, Andy Shevchenko wrote: > On Fri, Mar 07, 2025 at 07:11:42PM +0900, Vincent Mailhol wrote: >> On 07/03/2025 at 02:55, Andy Shevchenko wrote: >>> On Fri, Mar 07, 2025 at 01:08:15AM +0900, Vincent Mailhol wrote: >>>> On 06/03/2025 at 22:11, Andy Shevchenko wrote: >>>>> On Thu, Mar 06, 2025 at 08:29:58PM +0900, Vincent Mailhol via B4 Relay wrote: >>>>>> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr> >>>>>> >>>>>> Add some additional tests in lib/test_bits.c to cover the expected >>>>>> results of the fixed type BIT_U*() macros. >>>>> >>>>> Still would be good to have a small assembly test case for GENMASK*() as they >>>>> went split and it will be a good regression test in case somebody decides to >>>>> unify both without much thinking.. >>>> >>>> Let me confirm that I correctly understood your ask. Would something >>>> like this meet your expectations? >>> >>> I believe it should be written in asm. >> >> I am not confident enough in my assembly skills to submit asm patches to >> the kernel. So, I would rather take a pass on that one. >> >> Regardless, if somebody decides to unify both without much thinking as >> you said, I am fully confident that the patch will get Nack-ed right > > As I said above "would be good", if you think it's not feasible by you, perhaps > a comment (FIXME: ?) in the Kunit test cases that we lack of / need an asm test > as well. Ack. I will add a FIXME message in v6. Yours sincerely, Vincent Mailhol
© 2016 - 2026 Red Hat, Inc.