diff mbox series

[v2,net-next,4/6] lib/test_bitmap: test the newly added arr32 functions

Message ID 20221018140027.48086-5-alexandr.lobakin@intel.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series netlink: add universal 'bigint' attribute type | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 0 this patch: 6
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang fail Errors and warnings before: 0 this patch: 6
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 0 this patch: 6
netdev/checkpatch fail CHECK: Please use a blank line after function/struct/union/enum declarations ERROR: Use of __initconst requires a separate use of const
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Alexander Lobakin Oct. 18, 2022, 2 p.m. UTC
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@linux.intel.com>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 lib/test_bitmap.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
diff mbox series

Patch

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)