Skip to content

Commit fb57550

Browse files
committed
string: Convert helpers selftest to KUnit
Convert test-string_helpers.c to KUnit so it can be easily run with everything else. Failure reporting doesn't need to be open-coded in most places, for example, forcing a failure in the expected output for upper/lower testing looks like this: [12:18:43] # test_upper_lower: EXPECTATION FAILED at lib/string_helpers_kunit.c:579 [12:18:43] Expected dst == strings_upper[i].out, but [12:18:43] dst == "ABCDEFGH1234567890TEST" [12:18:43] strings_upper[i].out == "ABCDEFGH1234567890TeST" [12:18:43] [FAILED] test_upper_lower Currently passes without problems: $ ./tools/testing/kunit/kunit.py run string_helpers ... [12:23:55] Starting KUnit Kernel (1/1)... [12:23:55] ============================================================ [12:23:55] =============== string_helpers (3 subtests) ================ [12:23:55] [PASSED] test_get_size [12:23:55] [PASSED] test_upper_lower [12:23:55] [PASSED] test_unescape [12:23:55] ================= [PASSED] string_helpers ================== [12:23:55] ============================================================ [12:23:55] Testing complete. Ran 3 tests: passed: 3 [12:23:55] Elapsed time: 6.709s total, 0.001s configuring, 6.591s building, 0.066s running Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 29d8568 commit fb57550

File tree

4 files changed

+101
-125
lines changed

4 files changed

+101
-125
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8978,7 +8978,7 @@ F: include/linux/string_helpers.h
89788978
F: lib/string.c
89798979
F: lib/string_kunit.c
89808980
F: lib/string_helpers.c
8981-
F: lib/test-string_helpers.c
8981+
F: lib/string_helpers_kunit.c
89828982
F: scripts/coccinelle/api/string_choices.cocci
89838983

89848984
GENERIC UIO DRIVER FOR PCI DEVICES

lib/Kconfig.debug

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,8 +2357,10 @@ config STRING_KUNIT_TEST
23572357
depends on KUNIT
23582358
default KUNIT_ALL_TESTS
23592359

2360-
config TEST_STRING_HELPERS
2361-
tristate "Test functions located in the string_helpers module at runtime"
2360+
config STRING_HELPERS_KUNIT_TEST
2361+
tristate "KUnit test string helpers at runtime" if !KUNIT_ALL_TESTS
2362+
depends on KUNIT
2363+
default KUNIT_ALL_TESTS
23622364

23632365
config TEST_KSTRTOX
23642366
tristate "Test kstrto*() family of functions at runtime"

lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ obj-y += bcd.o sort.o parser.o debug_locks.o random32.o \
5151
generic-radix-tree.o bitmap-str.o
5252
obj-$(CONFIG_STRING_KUNIT_TEST) += string_kunit.o
5353
obj-y += string_helpers.o
54-
obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
54+
obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) += string_helpers_kunit.o
5555
obj-y += hexdump.o
5656
obj-$(CONFIG_TEST_HEXDUMP) += test_hexdump.o
5757
obj-y += kstrtox.o

0 commit comments

Comments
 (0)