linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/6] lib/test_bitmap.c: Add for_each_set_clump test cases
@ 2020-04-24 12:26 Syed Nayyar Waris
  2020-04-24 13:11 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Syed Nayyar Waris @ 2020-04-24 12:26 UTC (permalink / raw)
  To: akpm; +Cc: andriy.shevchenko, vilhelm.gray, linus.walleij, linux-kernel

The introduction of the generic for_each_set_clump macro need test
cases to verify the implementation. This patch adds test cases for
scenarios in which clump sizes are 8 bits, 24 bits, 30 bits and 6 bits.
The cases contain situations where clump is getting split at the word
boundary and also when zeroes are present in the start and middle of
bitmap.

Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 lib/test_bitmap.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 159 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 6b13150..5c1f98f 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -155,6 +155,38 @@ static bool __init __check_eq_clump8(const char *srcfile, unsigned int line,
 	return true;
 }
 
+static bool __init __check_eq_clump(const char *srcfile, unsigned int line,
+				    const unsigned int offset,
+				    const unsigned int size,
+				    const unsigned long *const clump_exp,
+				    const unsigned long *const clump,
+				    const unsigned long clump_size)
+{
+	unsigned long exp;
+
+	if (offset >= size) {
+		pr_warn("[%s:%u] bit offset for clump out-of-bounds: expected less than %u, got %u\n",
+			srcfile, line, size, offset);
+		return false;
+	}
+
+	exp = clump_exp[offset / clump_size];
+	if (!exp) {
+		pr_warn("[%s:%u] bit offset for zero clump: expected nonzero clump, got bit offset %u with clump value 0",
+			srcfile, line, offset);
+		return false;
+	}
+
+	if (*clump != exp) {
+		pr_warn("[%s:%u] expected clump value of 0x%lX, got clump value of 0x%lX",
+			srcfile, line, exp, *clump);
+		return false;
+	}
+
+	return true;
+}
+
+
 #define __expect_eq(suffix, ...)					\
 	({								\
 		int result = 0;						\
@@ -172,6 +204,7 @@ static bool __init __check_eq_clump8(const char *srcfile, unsigned int line,
 #define expect_eq_pbl(...)		__expect_eq(pbl, ##__VA_ARGS__)
 #define expect_eq_u32_array(...)	__expect_eq(u32_array, ##__VA_ARGS__)
 #define expect_eq_clump8(...)		__expect_eq(clump8, ##__VA_ARGS__)
+#define expect_eq_clump(...)		__expect_eq(clump, ##__VA_ARGS__)
 
 static void __init test_zero_clear(void)
 {
@@ -588,6 +621,46 @@ static const unsigned char clump_exp[] __initconst = {
 	0x05,	/* non-adjacent 2 bits set */
 };
 
+static const unsigned long clump_exp1[] __initconst = {
+	0x01,	/* 1 bit set */
+	0x02,	/* non-edge 1 bit set */
+	0x00,	/* zero bits set */
+	0x38,	/* 3 bits set across 4-bit boundary */
+	0x38,	/* Repeated clump */
+	0x0F,	/* 4 bits set */
+	0xFF,	/* all bits set */
+	0x05,	/* non-adjacent 2 bits set */
+};
+
+static const unsigned long clump_exp2[] __initconst = {
+	0xfedcba,	/* 24 bits */
+	0xabcdef,
+	0xaabbbb,	/* Clump split between 2 words */
+	0x000000,	/* zeroes in between */
+	0x0000aa,
+	0x000000,
+	0x0000ff,
+	0xaaaaaa,
+	0x000000,
+	0x0000ff,
+};
+
+static const unsigned long clump_exp3[] __initconst = {
+	0x00000000,	/* starting with 0s*/
+	0x00000000,	/* All 0s */
+	0x00000000,
+	0x00000000,
+	0x3f00000f,     /* Non zero set */
+	0x2aa80003,
+	0x00000aaa,
+	0x00003fc0,
+};
+
+static const unsigned long clump_exp4[] __initconst = {
+	0x00,
+	0x2b,
+};
+
 static void __init test_for_each_set_clump8(void)
 {
 #define CLUMP_EXP_NUMBITS 64
@@ -610,6 +683,88 @@ static void __init test_for_each_set_clump8(void)
 		expect_eq_clump8(start, CLUMP_EXP_NUMBITS, clump_exp, &clump);
 }
 
+static void __init test_for_each_set_clump_8(void)  /* 8 bit clumps test using
+						  new for_each_set_clump */
+{
+#define CLUMP_EXP_NUMBITS 64
+	DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS);
+	unsigned long start, clump, clump_size = 8;
+
+	/* set bitmap to test case */
+	bitmap_zero(bits, CLUMP_EXP_NUMBITS);
+	bitmap_set_value(bits, 0x38000201, 0, 32);
+	bitmap_set_value(bits, 0x05ff0f38, 32, 32);
+
+	for_each_set_clump(start, clump, bits, CLUMP_EXP_NUMBITS, clump_size)
+		expect_eq_clump(start, CLUMP_EXP_NUMBITS, clump_exp1, &clump, clump_size);
+}
+
+static void __init test_for_each_set_clump_24(void)  /* 24 bit clumps */
+{
+#define CLUMP_EXP_NUMBITS_2 256
+	DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
+	unsigned long start, clump, clump_size = 24;
+	unsigned long size = clump_size * 10;
+
+	/* set bitmap to test case */
+	bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
+	bitmap_set_value(bits, 0xeffedcba, 0, 32);
+	bitmap_set_value(bits, 0xbbbbabcd, 32, 32);
+	bitmap_set_value(bits, 0x000000aa, 64, 32);
+	bitmap_set_value(bits, 0x000000aa, 96, 32);
+	bitmap_set_value(bits, 0x00ff0000, 128, 32);
+	bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
+	bitmap_set_value(bits, 0xff000000, 192, 32);
+	bitmap_set_value(bits, 0x00aa0000, 224, 32);
+
+	for_each_set_clump(start, clump, bits, size, clump_size)
+		expect_eq_clump(start, size, clump_exp2, &clump, clump_size);
+}
+
+static void __init test_for_each_set_clump_30(void)   /* 30 bit clumps */
+{
+#define CLUMP_EXP_NUMBITS_2 256
+	DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
+	unsigned long start, clump, clump_size = 30;
+	unsigned long size = clump_size * 8;
+
+	/* set bitmap to test case */
+	bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
+	bitmap_set_value(bits, 0x00000000, 0, 32);
+	bitmap_set_value(bits, 0x00000000, 32, 32);
+	bitmap_set_value(bits, 0x00000000, 64, 32);
+	bitmap_set_value(bits, 0x0f000000, 96, 32);
+	bitmap_set_value(bits, 0x00ff0000, 128, 32);
+	bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
+	bitmap_set_value(bits, 0xff000000, 192, 32);
+	bitmap_set_value(bits, 0x00aa0000, 224, 32);
+
+	for_each_set_clump(start, clump, bits, size, clump_size)
+		expect_eq_clump(start, size, clump_exp3, &clump, clump_size);
+}
+
+static void __init test_for_each_set_clump_6(void)   /* 6 bit clumps */
+{
+#define CLUMP_EXP_NUMBITS_2 256
+	DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
+	unsigned long start, clump, clump_size = 6;
+	unsigned long size = clump_size * 3;
+
+	/* set bitmap to test case */
+	bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
+	bitmap_set_value(bits, 0x00000ac0, 0, 32);
+	bitmap_set_value(bits, 0x00000000, 32, 32);
+	bitmap_set_value(bits, 0x00000000, 64, 32);
+	bitmap_set_value(bits, 0x0f000000, 96, 32);
+	bitmap_set_value(bits, 0x00ff0000, 128, 32);
+	bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
+	bitmap_set_value(bits, 0xff000000, 192, 32);
+	bitmap_set_value(bits, 0x00aa0000, 224, 32);
+
+	for_each_set_clump(start, clump, bits, size, clump_size)
+		expect_eq_clump(start, size, clump_exp4, &clump, clump_size);
+}
+
 static void __init selftest(void)
 {
 	test_zero_clear();
@@ -623,6 +778,10 @@ static void __init selftest(void)
 	test_bitmap_parselist_user();
 	test_mem_optimisations();
 	test_for_each_set_clump8();
+	test_for_each_set_clump_8();
+	test_for_each_set_clump_24();
+	test_for_each_set_clump_30();
+	test_for_each_set_clump_6();
 }
 
 KSTM_MODULE_LOADERS(test_bitmap);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/6] lib/test_bitmap.c: Add for_each_set_clump test cases
  2020-04-24 12:26 [PATCH 2/6] lib/test_bitmap.c: Add for_each_set_clump test cases Syed Nayyar Waris
@ 2020-04-24 13:11 ` Andy Shevchenko
  2020-04-24 18:26   ` Syed Nayyar Waris
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2020-04-24 13:11 UTC (permalink / raw)
  To: Syed Nayyar Waris
  Cc: Andrew Morton, Andy Shevchenko, William Breathitt Gray,
	Linus Walleij, Linux Kernel Mailing List

On Fri, Apr 24, 2020 at 3:29 PM Syed Nayyar Waris <syednwaris@gmail.com> wrote:
>
> The introduction of the generic for_each_set_clump macro need test
> cases to verify the implementation. This patch adds test cases for
> scenarios in which clump sizes are 8 bits, 24 bits, 30 bits and 6 bits.
> The cases contain situations where clump is getting split at the word
> boundary and also when zeroes are present in the start and middle of
> bitmap.

...

>  #define expect_eq_clump8(...)          __expect_eq(clump8, ##__VA_ARGS__)
> +#define expect_eq_clump(...)           __expect_eq(clump, ##__VA_ARGS__)

What the difference with clump8() ? Can either of them use another?

...

>  #define CLUMP_EXP_NUMBITS 64

> +static void __init test_for_each_set_clump_8(void)  /* 8 bit clumps test using
> +                                                 new for_each_set_clump */
> +{

> +#define CLUMP_EXP_NUMBITS 64

Isn't it a redefinition? Shouldn't we undef all local definitions
above and below?

Also, can we derive it's size based on ARRAY_SIZE() and clump size?

> +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS);
> +       unsigned long start, clump, clump_size = 8;
> +
> +       /* set bitmap to test case */
> +       bitmap_zero(bits, CLUMP_EXP_NUMBITS);
> +       bitmap_set_value(bits, 0x38000201, 0, 32);
> +       bitmap_set_value(bits, 0x05ff0f38, 32, 32);
> +
> +       for_each_set_clump(start, clump, bits, CLUMP_EXP_NUMBITS, clump_size)
> +               expect_eq_clump(start, CLUMP_EXP_NUMBITS, clump_exp1, &clump, clump_size);
> +}
> +
> +static void __init test_for_each_set_clump_24(void)  /* 24 bit clumps */
> +{
> +#define CLUMP_EXP_NUMBITS_2 256
> +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
> +       unsigned long start, clump, clump_size = 24;
> +       unsigned long size = clump_size * 10;
> +
> +       /* set bitmap to test case */
> +       bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
> +       bitmap_set_value(bits, 0xeffedcba, 0, 32);
> +       bitmap_set_value(bits, 0xbbbbabcd, 32, 32);
> +       bitmap_set_value(bits, 0x000000aa, 64, 32);
> +       bitmap_set_value(bits, 0x000000aa, 96, 32);
> +       bitmap_set_value(bits, 0x00ff0000, 128, 32);
> +       bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
> +       bitmap_set_value(bits, 0xff000000, 192, 32);
> +       bitmap_set_value(bits, 0x00aa0000, 224, 32);
> +
> +       for_each_set_clump(start, clump, bits, size, clump_size)
> +               expect_eq_clump(start, size, clump_exp2, &clump, clump_size);
> +}
> +
> +static void __init test_for_each_set_clump_30(void)   /* 30 bit clumps */
> +{
> +#define CLUMP_EXP_NUMBITS_2 256
> +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
> +       unsigned long start, clump, clump_size = 30;
> +       unsigned long size = clump_size * 8;
> +
> +       /* set bitmap to test case */
> +       bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
> +       bitmap_set_value(bits, 0x00000000, 0, 32);
> +       bitmap_set_value(bits, 0x00000000, 32, 32);
> +       bitmap_set_value(bits, 0x00000000, 64, 32);
> +       bitmap_set_value(bits, 0x0f000000, 96, 32);
> +       bitmap_set_value(bits, 0x00ff0000, 128, 32);
> +       bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
> +       bitmap_set_value(bits, 0xff000000, 192, 32);
> +       bitmap_set_value(bits, 0x00aa0000, 224, 32);
> +
> +       for_each_set_clump(start, clump, bits, size, clump_size)
> +               expect_eq_clump(start, size, clump_exp3, &clump, clump_size);
> +}
> +
> +static void __init test_for_each_set_clump_6(void)   /* 6 bit clumps */
> +{
> +#define CLUMP_EXP_NUMBITS_2 256
> +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
> +       unsigned long start, clump, clump_size = 6;
> +       unsigned long size = clump_size * 3;
> +
> +       /* set bitmap to test case */
> +       bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
> +       bitmap_set_value(bits, 0x00000ac0, 0, 32);
> +       bitmap_set_value(bits, 0x00000000, 32, 32);
> +       bitmap_set_value(bits, 0x00000000, 64, 32);
> +       bitmap_set_value(bits, 0x0f000000, 96, 32);
> +       bitmap_set_value(bits, 0x00ff0000, 128, 32);
> +       bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
> +       bitmap_set_value(bits, 0xff000000, 192, 32);
> +       bitmap_set_value(bits, 0x00aa0000, 224, 32);
> +
> +       for_each_set_clump(start, clump, bits, size, clump_size)
> +               expect_eq_clump(start, size, clump_exp4, &clump, clump_size);
> +}

Can we unify all above and provide simple two test data sets:
expected, input, clump size and other information as function
parameter?

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/6] lib/test_bitmap.c: Add for_each_set_clump test cases
  2020-04-24 13:11 ` Andy Shevchenko
@ 2020-04-24 18:26   ` Syed Nayyar Waris
  0 siblings, 0 replies; 3+ messages in thread
From: Syed Nayyar Waris @ 2020-04-24 18:26 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andrew Morton, Andy Shevchenko, William Breathitt Gray,
	Linus Walleij, Linux Kernel Mailing List

On Fri, Apr 24, 2020 at 6:41 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Fri, Apr 24, 2020 at 3:29 PM Syed Nayyar Waris <syednwaris@gmail.com> wrote:
> >
> > The introduction of the generic for_each_set_clump macro need test
> > cases to verify the implementation. This patch adds test cases for
> > scenarios in which clump sizes are 8 bits, 24 bits, 30 bits and 6 bits.
> > The cases contain situations where clump is getting split at the word
> > boundary and also when zeroes are present in the start and middle of
> > bitmap.
>
> ...
>
> >  #define expect_eq_clump8(...)          __expect_eq(clump8, ##__VA_ARGS__)
> > +#define expect_eq_clump(...)           __expect_eq(clump, ##__VA_ARGS__)
>
> What the difference with clump8() ? Can either of them use another?
>

The difference is that generic (Non-8 version) expect_eq_clump(...)
expands to __check_eq_clump(...), which further uses clump_size
variable to check for the tests. Now this clump_size can have any
value signifying number of bits (less than or equal to BITS_PER_LONG).

While the clump8 version uses a fixed (hardcoded) value '8' for clump size.

I don't think either of them can use another.

> ...
>
> >  #define CLUMP_EXP_NUMBITS 64
>
> > +static void __init test_for_each_set_clump_8(void)  /* 8 bit clumps test using
> > +                                                 new for_each_set_clump */
> > +{
>
> > +#define CLUMP_EXP_NUMBITS 64
>
> Isn't it a redefinition? Shouldn't we undef all local definitions
> above and below?
>
> Also, can we derive it's size based on ARRAY_SIZE() and clump size?

Actually this macro is to create bitmap having a particular size. The
size doesn't need to be related to or derived from clump_size
necessarily.  I believe I should hardcode it - as it is just a test
value. I will submit this change in next version. Let me know if you
think otherwise.

>
> > +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS);
> > +       unsigned long start, clump, clump_size = 8;
> > +
> > +       /* set bitmap to test case */
> > +       bitmap_zero(bits, CLUMP_EXP_NUMBITS);
> > +       bitmap_set_value(bits, 0x38000201, 0, 32);
> > +       bitmap_set_value(bits, 0x05ff0f38, 32, 32);
> > +
> > +       for_each_set_clump(start, clump, bits, CLUMP_EXP_NUMBITS, clump_size)
> > +               expect_eq_clump(start, CLUMP_EXP_NUMBITS, clump_exp1, &clump, clump_size);
> > +}
> > +
> > +static void __init test_for_each_set_clump_24(void)  /* 24 bit clumps */
> > +{
> > +#define CLUMP_EXP_NUMBITS_2 256
> > +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
> > +       unsigned long start, clump, clump_size = 24;
> > +       unsigned long size = clump_size * 10;
> > +
> > +       /* set bitmap to test case */
> > +       bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
> > +       bitmap_set_value(bits, 0xeffedcba, 0, 32);
> > +       bitmap_set_value(bits, 0xbbbbabcd, 32, 32);
> > +       bitmap_set_value(bits, 0x000000aa, 64, 32);
> > +       bitmap_set_value(bits, 0x000000aa, 96, 32);
> > +       bitmap_set_value(bits, 0x00ff0000, 128, 32);
> > +       bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
> > +       bitmap_set_value(bits, 0xff000000, 192, 32);
> > +       bitmap_set_value(bits, 0x00aa0000, 224, 32);
> > +
> > +       for_each_set_clump(start, clump, bits, size, clump_size)
> > +               expect_eq_clump(start, size, clump_exp2, &clump, clump_size);
> > +}
> > +
> > +static void __init test_for_each_set_clump_30(void)   /* 30 bit clumps */
> > +{
> > +#define CLUMP_EXP_NUMBITS_2 256
> > +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
> > +       unsigned long start, clump, clump_size = 30;
> > +       unsigned long size = clump_size * 8;
> > +
> > +       /* set bitmap to test case */
> > +       bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
> > +       bitmap_set_value(bits, 0x00000000, 0, 32);
> > +       bitmap_set_value(bits, 0x00000000, 32, 32);
> > +       bitmap_set_value(bits, 0x00000000, 64, 32);
> > +       bitmap_set_value(bits, 0x0f000000, 96, 32);
> > +       bitmap_set_value(bits, 0x00ff0000, 128, 32);
> > +       bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
> > +       bitmap_set_value(bits, 0xff000000, 192, 32);
> > +       bitmap_set_value(bits, 0x00aa0000, 224, 32);
> > +
> > +       for_each_set_clump(start, clump, bits, size, clump_size)
> > +               expect_eq_clump(start, size, clump_exp3, &clump, clump_size);
> > +}
> > +
> > +static void __init test_for_each_set_clump_6(void)   /* 6 bit clumps */
> > +{
> > +#define CLUMP_EXP_NUMBITS_2 256
> > +       DECLARE_BITMAP(bits, CLUMP_EXP_NUMBITS_2);
> > +       unsigned long start, clump, clump_size = 6;
> > +       unsigned long size = clump_size * 3;
> > +
> > +       /* set bitmap to test case */
> > +       bitmap_zero(bits, CLUMP_EXP_NUMBITS_2);
> > +       bitmap_set_value(bits, 0x00000ac0, 0, 32);
> > +       bitmap_set_value(bits, 0x00000000, 32, 32);
> > +       bitmap_set_value(bits, 0x00000000, 64, 32);
> > +       bitmap_set_value(bits, 0x0f000000, 96, 32);
> > +       bitmap_set_value(bits, 0x00ff0000, 128, 32);
> > +       bitmap_set_value(bits, 0xaaaaaa00, 160, 32);
> > +       bitmap_set_value(bits, 0xff000000, 192, 32);
> > +       bitmap_set_value(bits, 0x00aa0000, 224, 32);
> > +
> > +       for_each_set_clump(start, clump, bits, size, clump_size)
> > +               expect_eq_clump(start, size, clump_exp4, &clump, clump_size);
> > +}
>
> Can we unify all above and provide simple two test data sets:
> expected, input, clump size and other information as function
> parameter?

Yes I can do that. I will try it out in next version (v2).

>
> --
> With Best Regards,
> Andy Shevchenko

Thank You!
Syed Nayyar Waris

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-24 18:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-24 12:26 [PATCH 2/6] lib/test_bitmap.c: Add for_each_set_clump test cases Syed Nayyar Waris
2020-04-24 13:11 ` Andy Shevchenko
2020-04-24 18:26   ` Syed Nayyar Waris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).