Re: [PATCH v5 5/7] test_bits: add tests for __GENMASK() and __GENMASK_ULL()

Vincent Mailhol
2025-03-13T06:01:00Z

On 13/03/2025 at 13:13, Lucas De Marchi wrote:
> On Thu, Mar 06, 2025 at 08:29:56PM +0900, Vincent Mailhol via B4 Relay
> wrote:
>> From: Vincent Mailhol <mailhol.vincent@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.
>>
>> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>> ---
>> lib/test_bits.c | 18 ++++++++++++++++++
>> 1 file changed, 18 insertions(+)
>>
>> diff --git a/lib/test_bits.c b/lib/test_bits.c
>> index
>> c7b38d91e1f16d42b7ca92e62fbd6c19b37e76a0..dc93ded9fdb201e0d44b3c1cd71e233fd62258a5 100644
>> --- a/lib/test_bits.c
>> +++ b/lib/test_bits.c
>> @@ -7,6 +7,22 @@
>> #include <linux/bits.h>
>>
>>
>> +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));
>
> why are you dropping the ones for TEST_GENMASK_FAILURES ?

Because the __GENMASK() and the __GENMASK_ULL() do not use
GENMASK_INPUT_CHECK(), it is not possible to have those
TEST_GENMASK_FAILURES negative test cases here.

I will add one sentence to the commit message to explain this.

>> +}
>> +
>> +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));
>
> ditto
>
> thanks
> Lucas De Marchi
>
>> +    KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, __GENMASK_ULL(63, 0));
>> +}
>> +
>> static void genmask_test(struct kunit *test)
>> {
>>     KUNIT_EXPECT_EQ(test, 1ul, GENMASK(0, 0));
>> @@ -93,6 +109,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),

Yours sincerely,
Vincent Mailhol