[PATCH v2 net-next 3/6] lib/test_bitmap: verify intermediate arr32 when converting <-> bitmap

From: Alexander Lobakin
Date: Tue Oct 18 2022 - 10:02:52 EST


When testing converting bitmaps from/to arr32, use
bitmap_validate_arr32() to test whether the tail of the intermediate
array was cleared correctly. Previously there were checks only for
the actual bitmap generated with the double-conversion.
Note that we pass bitmap_arr32_size() instead of `sizeof(arr)`, as
we poison the bytes past the last used word with 0xa5s. Also, for
@nbits == 0, the validation function must return false, account that
case as well.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx>
---
lib/test_bitmap.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index a8005ad3bd58..c40ab3dfa776 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -605,6 +605,7 @@ static void __init test_bitmap_arr32(void)
unsigned int nbits, next_bit;
u32 arr[EXP1_IN_BITS / 32];
DECLARE_BITMAP(bmap2, EXP1_IN_BITS);
+ bool valid;

memset(arr, 0xa5, sizeof(arr));

@@ -620,6 +621,9 @@ static void __init test_bitmap_arr32(void)
" tail is not safely cleared: %d\n",
nbits, next_bit);

+ valid = bitmap_validate_arr32(arr, bitmap_arr32_size(nbits), nbits);
+ expect_eq_uint(!!nbits, valid);
+
if (nbits < EXP1_IN_BITS - 32)
expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
0xa5a5a5a5);
--
2.37.3