lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221018140027.48086-5-alexandr.lobakin@intel.com>
Date:   Tue, 18 Oct 2022 16:00:25 +0200
From:   Alexander Lobakin <alexandr.lobakin@...el.com>
To:     "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>
Cc:     Yury Norov <yury.norov@...il.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Michal Swiatkowski <michal.swiatkowski@...ux.intel.com>,
        Maciej Fijalkowski <maciej.fijalkowski@...el.com>,
        Alexander Lobakin <alexandr.lobakin@...el.com>,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        Andy Shevchenko <andy.shevchenko@...ux.intel.com>
Subject: [PATCH v2 net-next 4/6] lib/test_bitmap: test the newly added arr32 functions

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@...ux.intel.com>
Signed-off-by: Alexander Lobakin <alexandr.lobakin@...el.com>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ