From: Alexander Lobakin <alexandr.lobakin@intel.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Yury Norov <yury.norov@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Michal Swiatkowski <michal.swiatkowski@linux.intel.com>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
Alexander Lobakin <alexandr.lobakin@intel.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Andy Shevchenko <andy.shevchenko@linux.intel.com>
Subject: [PATCH v2 net-next 4/6] lib/test_bitmap: test the newly added arr32 functions
Date: Tue, 18 Oct 2022 16:00:25 +0200 [thread overview]
Message-ID: <20221018140027.48086-5-alexandr.lobakin@intel.com> (raw)
In-Reply-To: <20221018140027.48086-1-alexandr.lobakin@intel.com>
Add a couple of trivial test cases, which will trial three newly
added helpers to work with arr32s:
* bitmap_validate_arr32() -- test all the branches the function can
take when validating;
* bitmap_arr32_size() -- sometimes is also called inside the
previous one;
* BITMAP_TO_U64() -- testing it casted to u32 against arr32[0].
Suggested-by: Andy Shevchenko <andy.shevchenko@linux.intel.com>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
lib/test_bitmap.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index c40ab3dfa776..f168f0a79e4f 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -600,6 +600,36 @@ static void __init test_bitmap_parse(void)
}
}
+static const struct {
+ DECLARE_BITMAP(bitmap, 128);
+ u32 nbits;
+ u32 msglen;
+ u32 exp_size;
+ u32 exp_valid:1;
+} arr32_test_cases[] __initconst = {
+#define BITMAP_ARR32_CASE(h, l, nr, len, ev, es) { \
+ .bitmap = { \
+ BITMAP_FROM_U64(l), \
+ BITMAP_FROM_U64(h), \
+ }, \
+ .nbits = (nr), \
+ .msglen = (len), \
+ .exp_valid = (ev), \
+ .exp_size = (es), \
+}
+ /* fail: msglen is not a multiple of 4 */
+ BITMAP_ARR32_CASE(0x00000000, 0x0000accedeadfeed, 48, 6, false, 8),
+ /* pass: kernel supports more bits than received */
+ BITMAP_ARR32_CASE(0x00000000, 0xacdcbadadd0afc18, 90, 8, true, 12),
+ /* fail: unsupported bits set within the last supported word */
+ BITMAP_ARR32_CASE(0xfa588103, 0xd3d0a58544864a9c, 88, 12, false, 12),
+ /* fail: unsupported bits set past the last supported word */
+ BITMAP_ARR32_CASE(0x00b84e53, 0x0000a3bafb6484f8, 64, 16, false, 8),
+ /* pass: kernel supports less bits than received, no unsupported set */
+ BITMAP_ARR32_CASE(0x00000000, 0x848d7a2acc7ff31e, 64, 16, true, 8),
+#undef BITMAP_ARR32_CASE
+};
+
static void __init test_bitmap_arr32(void)
{
unsigned int nbits, next_bit;
@@ -628,6 +658,19 @@ static void __init test_bitmap_arr32(void)
expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
0xa5a5a5a5);
}
+
+ for (u32 i = 0; i < ARRAY_SIZE(arr32_test_cases); i++) {
+ typeof(*arr32_test_cases) *test = &arr32_test_cases[i];
+
+ memset(arr, 0, sizeof(arr));
+ bitmap_to_arr32(arr, test->bitmap, BYTES_TO_BITS(test->msglen));
+
+ valid = bitmap_validate_arr32(arr, test->msglen, test->nbits);
+ expect_eq_uint(test->exp_valid, valid);
+
+ expect_eq_uint(test->exp_size, bitmap_arr32_size(test->nbits));
+ expect_eq_uint((u32)BITMAP_TO_U64(test->bitmap), arr[0]);
+ }
}
static void __init test_bitmap_arr64(void)
--
2.37.3
next prev parent reply other threads:[~2022-10-18 14:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-18 14:00 [PATCH v2 net-next 0/6] netlink: add universal 'bigint' attribute type Alexander Lobakin
2022-10-18 14:00 ` [PATCH v2 net-next 1/6] bitmap: try to optimize arr32 <-> bitmap on 64-bit LEs Alexander Lobakin
2022-10-18 22:41 ` Yury Norov
2022-10-19 15:21 ` Alexander Lobakin
2022-10-18 14:00 ` [PATCH v2 net-next 2/6] bitmap: add a couple more helpers to work with arrays of u32s Alexander Lobakin
2022-10-20 0:21 ` Yury Norov
2022-10-20 13:18 ` Andy Shevchenko
2022-10-20 15:31 ` Yury Norov
2022-10-18 14:00 ` [PATCH v2 net-next 3/6] lib/test_bitmap: verify intermediate arr32 when converting <-> bitmap Alexander Lobakin
2022-10-18 14:00 ` Alexander Lobakin [this message]
2022-10-18 14:00 ` [PATCH v2 net-next 5/6] bitops: make BYTES_TO_BITS() treewide-available Alexander Lobakin
2022-10-18 19:55 ` Jakub Kicinski
2022-10-19 15:26 ` Alexander Lobakin
2022-10-18 14:00 ` [PATCH v2 net-next 6/6] netlink: add universal 'bigint' attribute type Alexander Lobakin
2022-10-18 14:13 ` Andy Shevchenko
2022-10-18 19:53 ` Jakub Kicinski
2022-10-19 15:34 ` Alexander Lobakin
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=20221018140027.48086-5-alexandr.lobakin@intel.com \
--to=alexandr.lobakin@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=maciej.fijalkowski@intel.com \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yury.norov@gmail.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®