Re: [PATCH v3] bitfield: fix *_encode_bits()

From: Andy Shevchenko
Date: Mon Jun 18 2018 - 16:40:35 EST


On Mon, Jun 18, 2018 at 11:28 PM, Johannes Berg
<johannes@xxxxxxxxxxxxxxxx> wrote:
>
>> I think would be better to add test cases first, followed by fix. (1
>> patch -> 2 patches)
>> In this case Fixes tag would be only for the fix part and backporting
>> (if needed) will be much easier.
>
> Can't, unless I introduce a compilation issue in the tests first? That
> seems weird. But I guess I can do it the other way around.

Works for me.

>
>> > @@ -143,6 +143,7 @@ static __always_inline base type##_get_bits(__##type v, base field) \
>> > ____MAKE_OP(le##size,u##size,cpu_to_le##size,le##size##_to_cpu) \
>> > ____MAKE_OP(be##size,u##size,cpu_to_be##size,be##size##_to_cpu) \
>> > ____MAKE_OP(u##size,u##size,,)
>> > +____MAKE_OP(u8,u8,,)
>>
>> Is this one you need, or it's just for sake of tests?
>
> All three ;-)
>
> We'll probably need it eventually (we do have bytes to take bits out
> of), for consistency I think we want it, and I wanted to add it to the
> tests too.

Okay, but I still think it makes sense to have this oneliner as a
separate patch.

> I disagree with this. I don't see why we should have le8_encode_bits()
> and be8_encode_bits() and friends, that makes no sense.

OK, it was just a proposal.

>> I guess you rather continue and print a statistics X passed out of Y.
>> Check how it's done, for example, in other test_* modules.
>> (test_printf.c comes first to my mind).
>
> I see it's done that way elsewhere, but I don't really see the point. It
> makes the test code more complex, and if you fail here you'd better fix
> it, and if you need a few iterations for that it's not really a problem?

The idea is to print what was the input, expected output and actual result.
Then you would see what exactly is broken.

I dunno how much we may take away from this certain test case, though
it would be better for my opinion.

--
With Best Regards,
Andy Shevchenko