lib/tests: add KUnit test for argv_split()
PATCH v2 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
---
Changes in v2:
- Fix build error on sparc-linux-gcc (GCC) 8.5.0 due to empty scalar initializer
- Add Reported-by tag
--- 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
@@ -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
@@ -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]>