[PATCH v2 net-next 4/6] lib/test_bitmap: test the newly added arr32 functions
From: Alexander Lobakin
Date: Tue Oct 18 2022 - 10:02:56 EST
Add a couple of trivial test cases, which will trial three newly
added helpers to work with arr32s:
* bitmap_validate_arr32() -- test all the branches the function can
take when validating;
* bitmap_arr32_size() -- sometimes is also called inside the
previous one;
* BITMAP_TO_U64() -- testing it casted to u32 against arr32[0].
Suggested-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxxxxxxxx>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx>
---
lib/test_bitmap.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/lib/test_bitmap.c b/lib/test_bitmap.c
index c40ab3dfa776..f168f0a79e4f 100644
--- a/lib/test_bitmap.c
+++ b/lib/test_bitmap.c
@@ -600,6 +600,36 @@ static void __init test_bitmap_parse(void)
}
}
+static const struct {
+ DECLARE_BITMAP(bitmap, 128);
+ u32 nbits;
+ u32 msglen;
+ u32 exp_size;
+ u32 exp_valid:1;
+} arr32_test_cases[] __initconst = {
+#define BITMAP_ARR32_CASE(h, l, nr, len, ev, es) { \
+ .bitmap = { \
+ BITMAP_FROM_U64(l), \
+ BITMAP_FROM_U64(h), \
+ }, \
+ .nbits = (nr), \
+ .msglen = (len), \
+ .exp_valid = (ev), \
+ .exp_size = (es), \
+}
+ /* fail: msglen is not a multiple of 4 */
+ BITMAP_ARR32_CASE(0x00000000, 0x0000accedeadfeed, 48, 6, false, 8),
+ /* pass: kernel supports more bits than received */
+ BITMAP_ARR32_CASE(0x00000000, 0xacdcbadadd0afc18, 90, 8, true, 12),
+ /* fail: unsupported bits set within the last supported word */
+ BITMAP_ARR32_CASE(0xfa588103, 0xd3d0a58544864a9c, 88, 12, false, 12),
+ /* fail: unsupported bits set past the last supported word */
+ BITMAP_ARR32_CASE(0x00b84e53, 0x0000a3bafb6484f8, 64, 16, false, 8),
+ /* pass: kernel supports less bits than received, no unsupported set */
+ BITMAP_ARR32_CASE(0x00000000, 0x848d7a2acc7ff31e, 64, 16, true, 8),
+#undef BITMAP_ARR32_CASE
+};
+
static void __init test_bitmap_arr32(void)
{
unsigned int nbits, next_bit;
@@ -628,6 +658,19 @@ static void __init test_bitmap_arr32(void)
expect_eq_uint(arr[DIV_ROUND_UP(nbits, 32)],
0xa5a5a5a5);
}
+
+ for (u32 i = 0; i < ARRAY_SIZE(arr32_test_cases); i++) {
+ typeof(*arr32_test_cases) *test = &arr32_test_cases[i];
+
+ memset(arr, 0, sizeof(arr));
+ bitmap_to_arr32(arr, test->bitmap, BYTES_TO_BITS(test->msglen));
+
+ valid = bitmap_validate_arr32(arr, test->msglen, test->nbits);
+ expect_eq_uint(test->exp_valid, valid);
+
+ expect_eq_uint(test->exp_size, bitmap_arr32_size(test->nbits));
+ expect_eq_uint((u32)BITMAP_TO_U64(test->bitmap), arr[0]);
+ }
}
static void __init test_bitmap_arr64(void)
--
2.37.3