Skip to content

Commit 7a79e7d

Browse files
tamirdkees
authored andcommitted
printf: convert self-test to KUnit
Convert the printf() self-test to a KUnit test. In the interest of keeping the patch reasonably-sized this doesn't refactor the tests into proper parameterized tests - it's all one big test case. Signed-off-by: Tamir Duberstein <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Tested-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 6ee149f commit 7a79e7d

File tree

11 files changed

+132
-106
lines changed

11 files changed

+132
-106
lines changed

Documentation/core-api/printk-formats.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ Do *not* use it from C.
661661
Thanks
662662
======
663663

664-
If you add other %p extensions, please extend <lib/test_printf.c> with
665-
one or more test cases, if at all feasible.
664+
If you add other %p extensions, please extend <lib/tests/printf_kunit.c>
665+
with one or more test cases, if at all feasible.
666666

667667
Thank you for your cooperation and attention.

Documentation/dev-tools/kselftest.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ kselftest. We use kselftests for lib/ as an example.
347347
1. Create the test module
348348

349349
2. Create the test script that will run (load/unload) the module
350-
e.g. ``tools/testing/selftests/lib/printf.sh``
350+
e.g. ``tools/testing/selftests/lib/bitmap.sh``
351351

352352
3. Add line to config file e.g. ``tools/testing/selftests/lib/config``
353353

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25411,8 +25411,8 @@ R: Sergey Senozhatsky <[email protected]>
2541125411
S: Maintained
2541225412
T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git
2541325413
F: Documentation/core-api/printk-formats.rst
25414-
F: lib/test_printf.c
2541525414
F: lib/test_scanf.c
25415+
F: lib/tests/printf_kunit.c
2541625416
F: lib/vsprintf.c
2541725417

2541825418
VT1211 HARDWARE MONITOR DRIVER

lib/Kconfig.debug

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,15 @@ config ASYNC_RAID6_TEST
24272427
config TEST_HEXDUMP
24282428
tristate "Test functions located in the hexdump module at runtime"
24292429

2430+
config PRINTF_KUNIT_TEST
2431+
tristate "KUnit test printf() family of functions at runtime" if !KUNIT_ALL_TESTS
2432+
depends on KUNIT
2433+
default KUNIT_ALL_TESTS
2434+
help
2435+
Enable this option to test the printf functions at runtime.
2436+
2437+
If unsure, say N.
2438+
24302439
config STRING_KUNIT_TEST
24312440
tristate "KUnit test string functions at runtime" if !KUNIT_ALL_TESTS
24322441
depends on KUNIT
@@ -2440,9 +2449,6 @@ config STRING_HELPERS_KUNIT_TEST
24402449
config TEST_KSTRTOX
24412450
tristate "Test kstrto*() family of functions at runtime"
24422451

2443-
config TEST_PRINTF
2444-
tristate "Test printf() family of functions at runtime"
2445-
24462452
config TEST_SCANF
24472453
tristate "Test scanf() family of functions at runtime"
24482454

lib/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o
7777
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
7878
obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
7979
obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
80-
obj-$(CONFIG_TEST_PRINTF) += test_printf.o
8180
obj-$(CONFIG_TEST_SCANF) += test_scanf.o
8281

8382
obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o

lib/tests/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
2929
obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o
3030
CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
3131
obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
32+
obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o
3233
obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
3334
obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
3435
obj-$(CONFIG_TEST_SORT) += test_sort.o

0 commit comments

Comments
 (0)