]> git.baikalelectronics.ru Git - kernel.git/commitdiff
lib/test_bitmap.c: add test for bitmap_cut()
authorStefano Brivio <sbrivio@redhat.com>
Wed, 12 Aug 2020 01:34:32 +0000 (18:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 12 Aug 2020 17:57:59 +0000 (10:57 -0700)
Inspired by an original patch from Yury Norov: introduce a test for
bitmap_cut() that also makes sure functionality is as described for
partially overlapping src and dst.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Yury Norov <yury.norov@gmail.com>
Link: http://lkml.kernel.org/r/5fc45e6bbd4fa837cd9577f8a0c1d639df90a4ce.1592155364.git.sbrivio@redhat.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/test_bitmap.c

index 6b13150667f50f087570c69ce8c646850c5e6f43..df903c53952bb9caf7899c6435c4a908c8488d53 100644 (file)
@@ -610,6 +610,63 @@ static void __init test_for_each_set_clump8(void)
                expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump);
 }
 
+struct test_bitmap_cut {
+       unsigned int first;
+       unsigned int cut;
+       unsigned int nbits;
+       unsigned long in[4];
+       unsigned long expected[4];
+};
+
+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 },
+               { 0x00000001UL, },
+       },
+       { 16, BITS_PER_LONG * 2 + 1, BITS_PER_LONG * 2 + 1 + 16,
+               { 0x0000ffffUL, 0x5a5a5a5aUL, 0x5a5a5a5aUL, 0x5a5a5a5aUL },
+               { 0x2d2dffffUL, },
+       },
+};
+
+static void __init test_bitmap_cut(void)
+{
+       unsigned long b[5], *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);
+
+               expect_eq_bitmap(t->expected, out, t->nbits);
+       }
+}
+
 static void __init selftest(void)
 {
        test_zero_clear();
@@ -623,6 +680,7 @@ static void __init selftest(void)
        test_bitmap_parselist_user();
        test_mem_optimisations();
        test_for_each_set_clump8();
+       test_bitmap_cut();
 }
 
 KSTM_MODULE_LOADERS(test_bitmap);