From: Yury Norov <ynorov@nvidia.com>
To: linux-kernel@vger.kernel.org
Cc: Yury Norov <ynorov@nvidia.com>, Yury Norov <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 1/3] bitmap: test bitmap_weight() for more
Date: Wed, 18 Mar 2026 20:43:46 -0400 [thread overview]
Message-ID: <20260319004349.849281-2-ynorov@nvidia.com> (raw)
In-Reply-To: <20260319004349.849281-1-ynorov@nvidia.com>
Test the function for correctness when some bits are set in the last word
of bitmap beyond nbits. This is motivated by commit a9dadc1c512807f9
("powerpc/xive: Fix the size of the cpumask used in
xive_find_target_in_mask()").
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
lib/test_bitmap.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index cd4cb36e42a5..eeb497016ed3 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -858,6 +858,7 @@ static void __init test_bitmap_weight(void)
{
unsigned int bit, w1, w2, w;
DECLARE_BITMAP(b, 30);
+ DECLARE_BITMAP(b1, 128);
bitmap_parselist("all:1/2", b, 30);
@@ -877,6 +878,24 @@ static void __init test_bitmap_weight(void)
w2 = bitmap_weight_from(exp1, bit, EXP1_IN_BITS);
expect_eq_uint(w1 + w2, w);
}
+
+ /* Test out-of-range */
+ w = bitmap_weight_from(b, 31, 30);
+ expect_eq_uint(0, !!(w < 30));
+
+ /*
+ * Test bitmap_weight() for correctness in case of some bits set between
+ * nbits and end of the last word.
+ */
+ bitmap_fill(b1, 128);
+
+ /* Inline */
+ expect_eq_uint(30, bitmap_weight(b1, 30));
+ expect_eq_uint(100, bitmap_weight(b1, 100));
+
+ /* Outline */
+ for (int i = 1; i < 128; i++)
+ expect_eq_uint(i, bitmap_weight(b1, i));
}
static void __init test_for_each_clear_bit(void)
--
2.43.0
next prev parent reply other threads:[~2026-03-19 0:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 0:43 [PATCH 0/3] bitmap: add new tests Yury Norov
2026-03-19 0:43 ` Yury Norov [this message]
2026-03-19 0:43 ` [PATCH 2/3] bitmap: exclude nbits == 0 cases from bitmap test Yury Norov
2026-03-19 0:43 ` [PATCH 3/3] bitmap: add test_zero_nbits() Yury Norov
2026-03-21 17:09 ` kernel test robot
2026-03-23 17:56 ` Yury Norov
2026-03-24 0:52 ` Philip Li
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=20260319004349.849281-2-ynorov@nvidia.com \
--to=ynorov@nvidia.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--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