diff options
| author | Yury Norov <ynorov@nvidia.com> | 2026-03-19 03:43:46 +0300 |
|---|---|---|
| committer | Yury Norov <ynorov@nvidia.com> | 2026-03-23 20:56:25 +0300 |
| commit | e9cf8f83c9857a32494002c72b5f6e36ff4dfcd5 (patch) | |
| tree | c5b8b042b2ce58d07c79e8b2cce2078aa5b731a5 | |
| parent | f3e9c1138e9d20677ed085107cd2872d5218e3b1 (diff) | |
| download | linux-e9cf8f83c9857a32494002c72b5f6e36ff4dfcd5.tar.xz | |
bitmap: test bitmap_weight() for more
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>
| -rw-r--r-- | lib/test_bitmap.c | 19 |
1 files changed, 19 insertions, 0 deletions
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) |
