On Mon, 8 Jun 2020 13:12:14 +0300
Andy Shevchenko <[email protected]> wrote:

> On Mon, Jun 08, 2020 at 11:13:29AM +0200, Stefano Brivio wrote:
> > Based on an original patch by Yury Norov: introduce a test for
> > bitmap_cut() that also makes sure functionality is as described for
> > partially overlapping src and dst.  
> 
> > Co-authored-by: Yury Norov <[email protected]>  
> 
> Co-developed-by (and it requires Yury's SoB as well).

Oops, sorry, I didn't remember this part from submitting-patches.rst
correctly. Thanks for pointing this out.

Yury, let me know if I should re-post with both Co-authored-by: and
Signed-off-by: you -- otherwise I'll repost without both.

> > Signed-off-by: Stefano Brivio <[email protected]>  
> 
> ...
> 
> > +static struct test_bitmap_cut test_cut[] = {
> > +   {  0,  0,  8, { 0x0000000aUL, }, { 0x0000000aUL, }, },
> > +   {  0,  0, 32, { 0xdadadeadUL, }, { 0xdadadeadUL, }, },
> > +   {  0,  3,  8, { 0x000000aaUL, }, { 0x00000015UL, }, },
> > +   {  3,  3,  8, { 0x000000aaUL, }, { 0x00000012UL, }, },
> > +   {  0,  1, 32, { 0xa5a5a5a5UL, }, { 0x52d2d2d2UL, }, },
> > +   {  0,  8, 32, { 0xdeadc0deUL, }, { 0x00deadc0UL, }, },
> > +   {  1,  1, 32, { 0x5a5a5a5aUL, }, { 0x2d2d2d2cUL, }, },
> > +   {  0, 15, 32, { 0xa5a5a5a5UL, }, { 0x00014b4bUL, }, },
> > +   {  0, 16, 32, { 0xa5a5a5a5UL, }, { 0x0000a5a5UL, }, },
> > +   { 15, 15, 32, { 0xa5a5a5a5UL, }, { 0x000125a5UL, }, },
> > +   { 15, 16, 32, { 0xa5a5a5a5UL, }, { 0x0000a5a5UL, }, },
> > +   { 16, 15, 32, { 0xa5a5a5a5UL, }, { 0x0001a5a5UL, }, },
> > +
> > +   { BITS_PER_LONG, BITS_PER_LONG, BITS_PER_LONG,
> > +           { 0xa5a5a5a5UL, 0xa5a5a5a5UL, },
> > +           { 0xa5a5a5a5UL, 0xa5a5a5a5UL, },
> > +   },
> > +   { 1, BITS_PER_LONG - 1, BITS_PER_LONG,
> > +           { 0xa5a5a5a5UL, 0xa5a5a5a5UL, },
> > +           { 0x00000001UL, 0x00000001UL, },
> > +   },
> > +
> > +   { 0, BITS_PER_LONG * 2, BITS_PER_LONG * 2 + 1,
> > +           { 0xa5a5a5a5UL, 0x00000001UL, 0x00000001UL, 0x00000001UL },  
> 
> Perhaps leave comma as well?

I have a full explicit initialiser for this one, hence the "missing"
comma, I find it clearer. Any specific reason why I should add it?

> 
> > +           { 0x00000001UL, },
> > +   },
> > +   { 16, BITS_PER_LONG * 2 + 1, BITS_PER_LONG * 2 + 1 + 16,  
> 
> > +           { 0x0000ffffUL, 0x5a5a5a5aUL, 0x5a5a5a5aUL, 0x5a5a5a5aUL },  
> 
> Ditto.
> 
> > +           { 0x2d2dffffUL, },
> > +   },
> > +};
> > +
> > +static void __init test_bitmap_cut(void)
> > +{
> > +   unsigned long b[4], *in = &b[1], *out = &b[0];  /* Partial overlap */
> > +   int i;
> > +
> > +   for (i = 0; i < ARRAY_SIZE(test_cut); i++) {
> > +           struct test_bitmap_cut *t = &test_cut[i];
> > +
> > +           memcpy(in, t->in, sizeof(t->in));
> > +
> > +           bitmap_cut(out, in, t->first, t->cut, t->nbits);  
> 
> > +           if (!bitmap_equal(out, t->expected, t->nbits)) {
> > +                   pr_err("bitmap_cut failed: expected %*pb, got %*pb\n",
> > +                          t->nbits, t->expected, t->nbits, out);
> > +           }  
> 
> Perhaps
> 
>       if (bitmap_equal(...))
>               continue;
> 
>       ...
> 
> ?

That's five lines instead of four (I can't get pr_err() on one line
anyway) and it looks less straightforward: "if it doesn't match we have
an error" vs. "if it matches go to next case. We have an error". Any
specific reason I'm missing?

-- 
Stefano

Reply via email to