mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@caviumnetworks.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Noam Camus <noamca@mellanox.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Matthew Wilcox <mawilcox@microsoft.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-kernel@vger.kernel.org,
	Yury Norov <ynorov@caviumnetworks.com>
Subject: [PATCH 2/2] lib: add test for bitmap_parselist()
Date: Tue,  8 Aug 2017 01:54:38 +0300	[thread overview]
Message-ID: <20170807225438.16161-2-ynorov@caviumnetworks.com> (raw)
In-Reply-To: <20170807225438.16161-1-ynorov@caviumnetworks.com>

Do some basic checks for the bitmap_parselist().

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 lib/test_bitmap.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 2526a2975c51..5b80dd94e4d1 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -165,6 +165,78 @@ static void __init test_zero_fill_copy(void)
 	expect_eq_pbl("128-1023", bmap2, 1024);
 }
 
+#define PARSE_TIME 0x1
+
+struct test_bitmap_parselist{
+	const int errno;
+	const char *in;
+	const unsigned long *expected;
+	const int nbits;
+	const int flags;
+};
+
+static const unsigned long exp[] = {1, 2, 0x0000ffff, 0xffff0000, 0x55555555,
+				0xaaaaaaaa, 0x11111111, 0x22222222, 0xffffffff,
+				0xfffffffe, 0x3333333311111111, 0xffffffff77777777};
+static const unsigned long exp2[] = {0x3333333311111111, 0xffffffff77777777};
+
+static const struct test_bitmap_parselist parselist_tests[] __initconst = {
+	{0, "0",			&exp[0], 8, 0},
+	{0, "1",			&exp[1], 8, 0},
+	{0, "0-15",			&exp[2], 32, 0},
+	{0, "16-31",			&exp[3], 32, 0},
+	{0, "0-31:1/2",			&exp[4], 32, 0},
+	{0, "1-31:1/2",			&exp[5], 32, 0},
+	{0, "0-31:1/4",			&exp[6], 32, 0},
+	{0, "1-31:1/4",			&exp[7], 32, 0},
+	{0, "0-31:4/4",			&exp[8], 32, 0},
+	{0, "1-31:4/4",			&exp[9], 32, 0},
+	{0, "0-31:1/4,32-63:2/4",	&exp[10], 64, 0},
+	{0, "0-31:3/4,32-63:4/4",	&exp[11], 64, 0},
+
+	{0, "0-31:1/4,32-63:2/4,64-95:3/4,96-127:4/4",	exp2, 128, 0},
+
+	{0, "0-2047:128/256", NULL, 2048, PARSE_TIME},
+
+	{-EINVAL, "-1",	NULL, 8, 0},
+	{-EINVAL, "-0",	NULL, 8, 0},
+	{-EINVAL, "10-1", NULL, 8, 0},
+	{-EINVAL, "0-31:10/1", NULL, 8, 0},
+};
+
+static void __init test_bitmap_parselist(void)
+{
+	int i;
+	int err;
+	cycles_t cycles;
+	DECLARE_BITMAP(bmap, 2048);
+
+	for (i = 0; i < ARRAY_SIZE(parselist_tests); i++) {
+#define ptest parselist_tests[i]
+
+		cycles = get_cycles();
+		err = bitmap_parselist(ptest.in, bmap, ptest.nbits);
+		cycles = get_cycles() - cycles;
+
+		if (err != ptest.errno) {
+			pr_err("test %d: input is %s, errno is %d, expected %d\n",
+					i, ptest.in, err, ptest.errno);
+			continue;
+		}
+
+		if (!err && ptest.expected
+			 && !__bitmap_equal(bmap, ptest.expected, ptest.nbits)) {
+			pr_err("test %d: input is %s, result is 0x%lx, expected 0x%lx\n",
+					i, ptest.in, bmap[0], *ptest.expected);
+			continue;
+		}
+
+		if (ptest.flags & PARSE_TIME)
+			pr_err("test %d: input is '%s' OK, Time: %lu\n",
+					i, ptest.in, cycles);
+	}
+}
+
 static void __init test_bitmap_u32_array_conversions(void)
 {
 	DECLARE_BITMAP(bmap1, 1024);
@@ -365,6 +437,7 @@ static int __init test_bitmap_init(void)
 {
 	test_zero_fill_copy();
 	test_bitmap_u32_array_conversions();
+	test_bitmap_parselist();
 	test_mem_optimisations();
 
 	if (failed_tests == 0)
-- 
2.11.0

  reply	other threads:[~2017-08-07 22:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-07 22:54 [PATCH 1/2] lib: make bitmap_parselist thread-safe and much faster Yury Norov
2017-08-07 22:54 ` Yury Norov [this message]
2017-08-09  3:28   ` [PATCH 2/2] lib: add test for bitmap_parselist() kbuild test robot
2017-08-09 20:33     ` Andrew Morton
2017-08-09 22:52       ` Yury Norov
2017-08-10  7:30         ` Rasmus Villemoes
2017-08-10 10:37           ` Yury Norov
2017-08-09  4:11   ` kbuild test robot
2017-08-09 20:28     ` Andrew Morton

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=20170807225438.16161-2-ynorov@caviumnetworks.com \
    --to=ynorov@caviumnetworks.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mawilcox@microsoft.com \
    --cc=mchehab@kernel.org \
    --cc=noamca@mellanox.com \
    /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

all inboxes | Powered by JetHome®