[PATCH] lib/tests: extend cmdline next_arg() coverage with mixed tokens
From: Shuvam Pandey
Date: Mon Mar 16 2026 - 17:17:59 EST
The cmdline KUnit suite now covers quoted values and the bare quote
regression path in next_arg(), but it still does not exercise a mixed
sequence containing an empty value, a bare token, and a quoted value
with '='.
Andy Shevchenko suggested covering a sequence such as
"bbb= jjj kkk=\"a=b\"". Add that case so the suite checks all three
forms in one parse stream.
Validated with the arm64 cmdline KUnit suite and a W=1 rebuild of
lib/tests/cmdline_kunit.o.
Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
Signed-off-by: Shuvam Pandey <shuvampandey1@xxxxxxxxx>
---
lib/tests/cmdline_kunit.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/lib/tests/cmdline_kunit.c b/lib/tests/cmdline_kunit.c
index b5c7aba65f43..af44ae9e92c3 100644
--- a/lib/tests/cmdline_kunit.c
+++ b/lib/tests/cmdline_kunit.c
@@ -175,6 +175,29 @@ static void cmdline_test_next_arg_bare_quote_regression(struct kunit *test)
KUNIT_EXPECT_STREQ(test, next, "");
}
+static void cmdline_test_next_arg_mixed_tokens(struct kunit *test)
+{
+ char in[] = "bbb= jjj kkk=\"a=b\"";
+ char *next, *param, *val;
+
+ next = next_arg(in, ¶m, &val);
+ KUNIT_EXPECT_STREQ(test, param, "bbb");
+ KUNIT_ASSERT_NOT_NULL(test, val);
+ KUNIT_EXPECT_STREQ(test, val, "");
+ KUNIT_EXPECT_STREQ(test, next, "jjj kkk=\"a=b\"");
+
+ next = next_arg(next, ¶m, &val);
+ KUNIT_EXPECT_STREQ(test, param, "jjj");
+ KUNIT_EXPECT_NULL(test, val);
+ KUNIT_EXPECT_STREQ(test, next, "kkk=\"a=b\"");
+
+ next = next_arg(next, ¶m, &val);
+ KUNIT_EXPECT_STREQ(test, param, "kkk");
+ KUNIT_ASSERT_NOT_NULL(test, val);
+ KUNIT_EXPECT_STREQ(test, val, "a=b");
+ KUNIT_EXPECT_STREQ(test, next, "");
+}
+
static struct kunit_case cmdline_test_cases[] = {
KUNIT_CASE(cmdline_test_noint),
KUNIT_CASE(cmdline_test_lead_int),
@@ -182,6 +205,7 @@ static struct kunit_case cmdline_test_cases[] = {
KUNIT_CASE(cmdline_test_range),
KUNIT_CASE(cmdline_test_next_arg_quoted_value),
KUNIT_CASE(cmdline_test_next_arg_bare_quote_regression),
+ KUNIT_CASE(cmdline_test_next_arg_mixed_tokens),
{}
};
--
2.50.1 (Apple Git-155)