@@ -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);
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(-)