linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: William Breathitt Gray <vilhelm.gray@gmail.com>
To: linus.walleij@linaro.org, akpm@linux-foundation.org
Cc: linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org, andriy.shevchenko@linux.intel.com,
	linux@rasmusvillemoes.dk,
	William Breathitt Gray <vilhelm.gray@gmail.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: [RESEND PATCH v4 2/8] lib/test_bitmap.c: Add for_each_set_clump test cases
Date: Tue,  2 Oct 2018 10:14:33 +0900	[thread overview]
Message-ID: <9ac7e59bb34a9abb4430e7594dd183d7858679d1.1538441919.git.vilhelm.gray@gmail.com> (raw)
In-Reply-To: <cover.1538441919.git.vilhelm.gray@gmail.com>

The introduction of the for_each_set_clump macro warrants test cases to
verify the implementation. This patch adds test case checks for whether
an out-of-bounds clump index is returned, a zero clump is returned, or
the returned clump value differs from the expected clump value. A 4-bit
clump size is chosen in order to verify non-8-bit iteration.

Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
 lib/test_bitmap.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 6cd7d0740005..0a63313873c0 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -88,6 +88,39 @@ __check_eq_u32_array(const char *srcfile, unsigned int line,
 	return true;
 }
 
+static bool __init __check_eq_clump(const char *srcfile, unsigned int line,
+				    const size_t clump_index, const size_t size,
+				    const unsigned char *const clump_exp,
+				    const unsigned long *const bits,
+				    const size_t index,
+				    const unsigned int offset)
+{
+	unsigned long clump;
+	unsigned long exp;
+
+	if (clump_index >= size) {
+		pr_warn("[%s:%u] clump index out-of-bounds: expected less than %zu, got %zu\n",
+			srcfile, line, size, clump_index);
+		return false;
+	}
+
+	exp = clump_exp[clump_index];
+	if (!exp) {
+		pr_warn("[%s:%u] clump index for zero clump: expected nonzero clump, got clump index %zu with clump value 0",
+			srcfile, line, clump_index);
+		return false;
+	}
+
+	clump = (bits[index] >> offset) & 0xF;
+	if (clump != exp) {
+		pr_warn("[%s:%u] expected 0x%lX, got 0x%lX",
+			srcfile, line, exp, clump);
+		return false;
+	}
+
+	return true;
+}
+
 #define __expect_eq(suffix, ...)					\
 	({								\
 		int result = 0;						\
@@ -104,6 +137,7 @@ __check_eq_u32_array(const char *srcfile, unsigned int line,
 #define expect_eq_bitmap(...)		__expect_eq(bitmap, ##__VA_ARGS__)
 #define expect_eq_pbl(...)		__expect_eq(pbl, ##__VA_ARGS__)
 #define expect_eq_u32_array(...)	__expect_eq(u32_array, ##__VA_ARGS__)
+#define expect_eq_clump(...)		__expect_eq(clump, ##__VA_ARGS__)
 
 static void __init test_zero_clear(void)
 {
@@ -361,6 +395,42 @@ static void noinline __init test_mem_optimisations(void)
 	}
 }
 
+static const unsigned char clump_exp[] __initconst = {
+	0x1,	/* 1 bit set */
+	0x2,	/* non-edge 1 bit set */
+	0x0,	/* zero bits set */
+	0xE,	/* 3 bits set */
+	0xE,	/* Repeated clump */
+	0xF,	/* 4 bits set */
+	0x3,	/* 2 bits set */
+	0x5,	/* non-adjacent 2 bits set */
+};
+
+static void __init test_for_each_set_clump(void)
+{
+	size_t clump;
+	size_t index;
+	unsigned int offset;
+#define CLUMP_BITMAP_NUMBITS 32
+	DECLARE_BITMAP(bits, CLUMP_BITMAP_NUMBITS);
+#define CLUMP_SIZE 4
+	const size_t size = DIV_ROUND_UP(CLUMP_BITMAP_NUMBITS, CLUMP_SIZE);
+
+	/* set bitmap to test case */
+	bitmap_zero(bits, CLUMP_BITMAP_NUMBITS);
+	bitmap_set(bits, 0, 1);		/* 0x1 */
+	bitmap_set(bits, 5, 1);		/* 0x2 */
+	bitmap_set(bits, 13, 3);	/* 0xE */
+	bitmap_set(bits, 17, 3);	/* 0xE */
+	bitmap_set(bits, 20, 4);	/* 0xF */
+	bitmap_set(bits, 24, 2);	/* 0x3 */
+	bitmap_set(bits, 28, 1);	/* 0x5 - part 1 */
+	bitmap_set(bits, 30, 1);	/* 0x5 - part 2 */
+
+	for_each_set_clump(clump, index, offset, bits, size, CLUMP_SIZE)
+		expect_eq_clump(clump, size, clump_exp, bits, index, offset);
+}
+
 static int __init test_bitmap_init(void)
 {
 	test_zero_clear();
@@ -369,6 +439,7 @@ static int __init test_bitmap_init(void)
 	test_bitmap_arr32();
 	test_bitmap_parselist();
 	test_mem_optimisations();
+	test_for_each_set_clump();
 
 	if (failed_tests == 0)
 		pr_info("all %u tests passed\n", total_tests);
-- 
2.19.0


  parent reply	other threads:[~2018-10-02  1:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02  1:12 [RESEND PATCH v4 0/8] Introduce the for_each_set_clump macro William Breathitt Gray
2018-10-02  1:13 ` [RESEND PATCH v4 1/8] bitops: " William Breathitt Gray
2018-10-02  7:42   ` Rasmus Villemoes
2018-10-02  8:21     ` Andy Shevchenko
2018-10-03 11:48       ` Andy Shevchenko
2018-10-04 10:36         ` William Breathitt Gray
2018-10-04 12:10           ` Andy Shevchenko
2018-10-04 10:30       ` William Breathitt Gray
2018-10-04 10:03     ` William Breathitt Gray
2018-10-02  1:14 ` William Breathitt Gray [this message]
2018-10-02  1:14 ` [RESEND PATCH v4 3/8] gpio: 104-dio-48e: Utilize " William Breathitt Gray
2018-10-02  7:00   ` Rasmus Villemoes
2018-10-14  4:19     ` William Breathitt Gray
2018-10-15 11:59       ` Rasmus Villemoes
2018-10-17  1:54         ` William Breathitt Gray
2018-10-02  1:15 ` [RESEND PATCH v4 4/8] gpio: 104-idi-48: " William Breathitt Gray
2018-10-02  1:15 ` [RESEND PATCH v4 5/8] gpio: gpio-mm: " William Breathitt Gray
2018-10-02  1:15 ` [RESEND PATCH v4 6/8] gpio: ws16c48: " William Breathitt Gray
2018-10-02  1:16 ` [RESEND PATCH v4 7/8] gpio: pci-idio-16: " William Breathitt Gray
2018-10-02  1:16 ` [RESEND PATCH v4 8/8] gpio: pcie-idio-24: " William Breathitt Gray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ac7e59bb34a9abb4430e7594dd183d7858679d1.1538441919.git.vilhelm.gray@gmail.com \
    --to=vilhelm.gray@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).