Skip to contentSkip to conversation

lib/tests: add KUnit test for argv_split()

PATCH Superseded Ryota Sakamoto 2 participants 2 messages Feb 2

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/tests: add KUnit test for argv_split()

Add KUnit test for argv_split() to ensure that it correctly splits strings and handles edge cases such as multiple spaces, leading/trailing and whitespace.

Currently, there is no dedicated test for argv_split. Moving towards KUnit allows for easier regression testing and validation of the function.

Sample KUnit output:
KTAP version 1
# Subtest: argv_split
# module: argv_split_kunit
1..1
KTAP version 1
# Subtest: test_argv_split
ok 1 basic words
ok 2 single word
ok 3 leading/trailing whitespace
ok 4 mixing space
ok 5 quotes are treated as literals ok 6 empty
# test_argv_split: pass:6 fail:0 skip:0 total:6 ok 1 test_argv_split

---
 lib/Kconfig.debug            | 12 ++++++
 lib/tests/Makefile           |  1 +
 lib/tests/argv_split_kunit.c | 93 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+)
lib/Kconfig.debug +12 -0
index ba36939fda79bf890834b586c366a28acd434ef9..7dacfdccdb83f639944fcdf1d9548245eb047a30 100644
@@ -2817,6 +2817,18 @@ config CMDLINE_KUNIT_TEST
 
 	  If unsure, say N.
 
+config ARGV_SPLIT_KUNIT
+	tristate "KUnit test for argv_split" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the argv_split unit tests.
+
+	  For more information on KUnit and unit tests in general please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 config BASE64_KUNIT
 	tristate "KUnit test for base64 decoding and encoding" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/tests/Makefile +1 -0
index 601dba4b7d966d568d0bb6671dffaf4d68489549..fa00737a9cf60ca881b58d915e7f931df372594a 100644
@@ -4,6 +4,7 @@
 
 # KUnit tests
 CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
+obj-$(CONFIG_ARGV_SPLIT_KUNIT) += argv_split_kunit.o
 obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o
 obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
 obj-$(CONFIG_BITS_TEST) += test_bits.o
lib/tests/argv_split_kunit.c new file +93 -0

93 lines not on this page · raw message

---
base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62
change-id: 20260131-kunit-argv_split-ca2a1d9fd82b

Best regards,

Signature · 1 line
Ryota Sakamoto <[email protected]>
#1 lore raw
kernel test robot noticed the following build errors:

Hi Ryota,

kernel test robot noticed the following build errors:

[auto build test ERROR on 18f7fcd5e69a04df57b563360b88be72471d6b62]

url:    https://github.com/intel-lab-lkp/linux/commits/Ryota-Sakamoto/lib-tests-add-KUnit-test-for-argv_split/20260203-004209
base:   18f7fcd5e69a04df57b563360b88be72471d6b62
patch link:    https://lore.kernel.org/r/20260203-kunit-argv_split-v1-1-0d3545314a41%40gmail.com
patch subject: [PATCH] lib/tests: add KUnit test for argv_split()
config: sparc-randconfig-001-20260203 (https://download.01.org/0day-ci/archive/20260203/[email protected]/config)
compiler: sparc-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260203/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

>> lib/tests/argv_split_kunit.c:55:3: warning: braces around scalar initializer
      .argv = {},
      ^
   lib/tests/argv_split_kunit.c:55:3: note: (near initialization for 'argv_split_cases[5].argv')
>> lib/tests/argv_split_kunit.c:55:11: error: empty scalar initializer
      .argv = {},
              ^

lib/tests/argv_split_kunit.c:55:11: note: (near initialization for 'argv_split_cases[5].argv')

vim +55 lib/tests/argv_split_kunit.c

    19	
    20	static struct argv_split_test_case argv_split_cases[] = {
    21		{
    22			.str = "basic words",
    23			.input = "foo bar",
    24			.argc = 2,
    25			.argv = (const char *[]){ "foo", "bar" },
    26		},
    27		{
    28			.str = "single word",
    29			.input = "foobar",
    30			.argc = 1,
    31			.argv = (const char *[]){ "foobar" },
    32		},
    33		{
    34			.str = "leading/trailing whitespace",
    35			.input = "   hello  world ",
    36			.argc = 2,
    37			.argv = (const char *[]){ "hello", "world" },
    38		},
    39		{
    40			.str = "mixing space",
    41			.input = " \t foo \n bar   baz",
    42			.argc = 3,
    43			.argv = (const char *[]){ "foo", "bar", "baz" },
    44		},
    45		{
    46			.str = "quotes are treated as literals",
    47			.input = "ls \"my file/\"",
    48			.argc = 3,
    49			.argv = (const char *[]){ "ls", "\"my", "file/\"" },
    50		},
    51		{
    52			.str = "empty",
    53			.input = "",
    54			.argc = 0,
  > 55			.argv = {},
    56		},
    57	};
    58	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki