netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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: Alexander Lobakin <alexandr.lobakin@intel.com>,
	Yury Norov <yury.norov@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Michal Swiatkowski <michal.swiatkowski@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Nikolay Aleksandrov <razor@blackwall.org>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next 3/4] lib/test_bitmap: cover explicitly byteordered arr64s
Date: Thu, 21 Jul 2022 17:59:49 +0200	[thread overview]
Message-ID: <20220721155950.747251-4-alexandr.lobakin@intel.com> (raw)
In-Reply-To: <20220721155950.747251-1-alexandr.lobakin@intel.com>

When testing converting bitmaps <-> arr64, test Big and Little
Endianned variants as well to make sure it works as expected on
all platforms.
Also, use more complex bitmap_validate_arr64_type() instead of just
checking the tail. It will handle different Endiannesses correctly
(note we don't pass `sizeof(arr)` to it as we poison it with 0xa5).

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 lib/test_bitmap.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index 98754ff9fe68..8a44290b60ba 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -585,7 +585,7 @@ static void __init test_bitmap_arr32(void)
 	}
 }
 
-static void __init test_bitmap_arr64(void)
+static void __init test_bitmap_arr64_type(u32 type)
 {
 	unsigned int nbits, next_bit;
 	u64 arr[EXP1_IN_BITS / 64];
@@ -594,9 +594,11 @@ static void __init test_bitmap_arr64(void)
 	memset(arr, 0xa5, sizeof(arr));
 
 	for (nbits = 0; nbits < EXP1_IN_BITS; ++nbits) {
+		int res;
+
 		memset(bmap2, 0xff, sizeof(arr));
-		bitmap_to_arr64(arr, exp1, nbits);
-		bitmap_from_arr64(bmap2, arr, nbits);
+		bitmap_to_arr64_type(arr, exp1, nbits, type);
+		bitmap_from_arr64_type(bmap2, arr, nbits, type);
 		expect_eq_bitmap(bmap2, exp1, nbits);
 
 		next_bit = find_next_bit(bmap2, round_up(nbits, BITS_PER_LONG), nbits);
@@ -604,17 +606,21 @@ static void __init test_bitmap_arr64(void)
 			pr_err("bitmap_copy_arr64(nbits == %d:"
 				" tail is not safely cleared: %d\n", nbits, next_bit);
 
-		if ((nbits % 64) &&
-		    (arr[(nbits - 1) / 64] & ~GENMASK_ULL((nbits - 1) % 64, 0)))
-			pr_err("bitmap_to_arr64(nbits == %d): tail is not safely cleared: 0x%016llx (must be 0x%016llx)\n",
-			       nbits, arr[(nbits - 1) / 64],
-			       GENMASK_ULL((nbits - 1) % 64, 0));
+		res = bitmap_validate_arr64_type(arr, bitmap_arr64_size(nbits),
+						 nbits, type);
+		expect_eq_uint(nbits ? 0 : -EINVAL, res);
 
 		if (nbits < EXP1_IN_BITS - 64)
 			expect_eq_uint(arr[DIV_ROUND_UP(nbits, 64)], 0xa5a5a5a5);
 	}
 }
 
+static void __init test_bitmap_arr64(void)
+{
+	for (u32 type = 0; type < __BITMAP_ARR_TYPE_NUM; type++)
+		test_bitmap_arr64_type(type);
+}
+
 static void noinline __init test_mem_optimisations(void)
 {
 	DECLARE_BITMAP(bmap1, 1024);
-- 
2.36.1


  parent reply	other threads:[~2022-07-21 16:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 15:59 [PATCH net-next 0/4] netlink: add 'bitmap' attribute type and API Alexander Lobakin
2022-07-21 15:59 ` [PATCH net-next 1/4] bitmap: add converting from/to 64-bit arrays of explicit byteorder Alexander Lobakin
2022-07-21 15:59 ` [PATCH net-next 2/4] bitmap: add a couple more helpers to work with arrays of u64s Alexander Lobakin
2022-07-21 15:59 ` Alexander Lobakin [this message]
2022-07-21 15:59 ` [PATCH net-next 4/4] netlink: add 'bitmap' attribute type (%NL_ATTR_TYPE_BITMAP / %NLA_BITMAP) Alexander Lobakin
2022-07-21 18:13 ` [PATCH net-next 0/4] netlink: add 'bitmap' attribute type and API Jakub Kicinski
2022-07-22 14:55   ` Alexander Lobakin
2022-07-22 18:19     ` Jakub Kicinski
2022-07-23 15:52       ` Jakub Kicinski
2022-07-25 13:02       ` Alexander Lobakin
2022-07-25 18:53         ` Jakub Kicinski
2022-07-26 10:41           ` Alexander Lobakin
2022-07-26 17:17             ` Jakub Kicinski
     [not found]     ` <CAHp75Ve7oXjNyc0GD5x9ZW=DVgCqmLOBfCP4O2cDi2DG=4SiwQ@mail.gmail.com>
2022-07-25 10:24       ` 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=20220721155950.747251-4-alexandr.lobakin@intel.com \
    --to=alexandr.lobakin@intel.com \
    --cc=andriy.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=michal.swiatkowski@linux.intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=razor@blackwall.org \
    --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;
as well as URLs for NNTP newsgroup(s).