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: <20260122111254.1111811-2-dmantipov@yandex.ru>
Date: Thu, 22 Jan 2026 14:12:53 +0300
From: Dmitry Antipov <dmantipov@...dex.ru>
To: Andy Shevchenko <andriy.shevchenko@...el.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
	Kees Cook <kees@...nel.org>,
	"Darrick J . Wong" <djwong@...nel.org>,
	linux-hardening@...r.kernel.org,
	Dmitry Antipov <dmantipov@...dex.ru>
Subject: [PATCH 1/2] lib/cmdline_kunit: add test case for memparse()

Better late than never, now there is a long-awaited basic
test for 'memparse()' which is provided by cmdline.c.

Suggested-by: Andy Shevchenko <andriy.shevchenko@...el.com>
Signed-off-by: Dmitry Antipov <dmantipov@...dex.ru>
---
 lib/tests/cmdline_kunit.c | 50 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/lib/tests/cmdline_kunit.c b/lib/tests/cmdline_kunit.c
index c1602f797637..afde35f44690 100644
--- a/lib/tests/cmdline_kunit.c
+++ b/lib/tests/cmdline_kunit.c
@@ -139,11 +139,61 @@ static void cmdline_test_range(struct kunit *test)
 	} while (++i < ARRAY_SIZE(cmdline_test_range_strings));
 }
 
+struct cmdline_test_memparse_entry {
+	const char *input;
+	const char *unrecognized;
+	unsigned long long result;
+};
+
+static const struct cmdline_test_memparse_entry testdata[] = {
+	{ "0",			"",	0ULL },
+	{ "1",			"",	1ULL },
+	{ "a",			"a",	0ULL },
+	{ "0xb",		"",	11ULL },
+	{ "0xz",		"x",	0ULL },
+	{ "1234",		"",	1234ULL },
+	{ "04567",		"",	2423ULL },
+	{ "0x9876",		"",	39030LL },
+	{ "05678",		"8",	375ULL },
+	{ "0xabcdefz",		"z",	11259375ULL },
+	{ "0cdba",		"c",	0ULL },
+	{ "4K",			"",	4096ULL },
+	{ "0x10k@...aaabbbb",	"@",	16384ULL },
+	{ "32M",		"",	33554432ULL },
+	{ "067m:foo",		":",	57671680ULL },
+	{ "2G;bar=baz",		";",	2147483648ULL },
+	{ "07gz",		"z",	7516192768ULL },
+	{ "3T+data",		"+",	3298534883328ULL },
+	{ "04t,ro",		",",	4398046511104ULL },
+	{ "012p",		"",	11258999068426240ULL },
+	{ "7P,sync",		",",	7881299347898368ULL },
+	{ "0x2e",		"",	46ULL },
+	{ "2E and more",	" ",	2305843009213693952ULL },
+	{ "18446744073709551615", "",	18446744073709551615ULL },
+	{ "18446744073709551616", "",	0ULL }
+};
+
+static void cmdline_test_memparse(struct kunit *test)
+{
+	const struct cmdline_test_memparse_entry *e;
+	unsigned long long ret;
+	char *retptr;
+
+	for (e = testdata; e < testdata + ARRAY_SIZE(testdata); e++) {
+		ret = memparse(e->input, &retptr);
+		KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
+				    "    when parsing '%s'", e->input);
+		KUNIT_EXPECT_EQ_MSG(test, *retptr, *e->unrecognized,
+				    "    when parsing '%s'", e->input);
+	}
+}
+
 static struct kunit_case cmdline_test_cases[] = {
 	KUNIT_CASE(cmdline_test_noint),
 	KUNIT_CASE(cmdline_test_lead_int),
 	KUNIT_CASE(cmdline_test_tail_int),
 	KUNIT_CASE(cmdline_test_range),
+	KUNIT_CASE(cmdline_test_memparse),
 	{}
 };
 
-- 
2.52.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ