scanf: convert self-test to KUnit
Subsystems (4)
PATCH 1/1 scanf: convert self-test to KUnit
Convert the scanf() self-test to a KUnit test.
In the interest of keeping the patch reasonably-sized this doesn't rename the file in accordance with usual kunit conventions nor does it refactor the tests into proper parameterized tests - it's all one big test case.
---
This is one of just 3 remaining "Test Module" kselftests (the others being bitmap and printf), the rest having been converted to KUnit. In addition to the enclosed patch, please consider this an RFC on the removal of the "Test Module" kselftest machinery.
I tested this using:
$ tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 scanf --- arch/m68k/configs/amiga_defconfig | 1 - arch/m68k/configs/apollo_defconfig | 1 - arch/m68k/configs/atari_defconfig | 1 - arch/m68k/configs/bvme6000_defconfig | 1 - arch/m68k/configs/hp300_defconfig | 1 - arch/m68k/configs/mac_defconfig | 1 - arch/m68k/configs/multi_defconfig | 1 - arch/m68k/configs/mvme147_defconfig | 1 - arch/m68k/configs/mvme16x_defconfig | 1 - arch/m68k/configs/q40_defconfig | 1 - arch/m68k/configs/sun3_defconfig | 1 - arch/m68k/configs/sun3x_defconfig | 1 - arch/powerpc/configs/ppc64_defconfig | 1 - lib/Kconfig.debug | 20 +- lib/Makefile | 2 +- lib/test_scanf.c | 704 +++++++++++++++++------------------ tools/testing/selftests/lib/Makefile | 2 +- tools/testing/selftests/lib/config | 1 - tools/testing/selftests/lib/scanf.sh | 4 - 19 files changed, 358 insertions(+), 388 deletions(-)
arch/m68k/configs/amiga_defconfig +0 -1
@@ -623,7 +623,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/apollo_defconfig +0 -1
@@ -580,7 +580,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/atari_defconfig +0 -1
@@ -600,7 +600,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/bvme6000_defconfig +0 -1
@@ -572,7 +572,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/hp300_defconfig +0 -1
@@ -582,7 +582,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/mac_defconfig +0 -1
@@ -599,7 +599,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/multi_defconfig +0 -1
@@ -686,7 +686,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/mvme147_defconfig +0 -1
@@ -572,7 +572,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/mvme16x_defconfig +0 -1
@@ -573,7 +573,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/q40_defconfig +0 -1
@@ -589,7 +589,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/sun3_defconfig +0 -1
@@ -569,7 +569,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/m68k/configs/sun3x_defconfig +0 -1
@@ -570,7 +570,6 @@ CONFIG_ASYNC_RAID6_TEST=m CONFIG_TEST_HEXDUMP=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
arch/powerpc/configs/ppc64_defconfig +0 -1
@@ -445,7 +445,6 @@ CONFIG_STRING_SELFTEST=m CONFIG_TEST_STRING_HELPERS=m CONFIG_TEST_KSTRTOX=m CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_TEST_UUID=m CONFIG_TEST_XARRAY=m
lib/Kconfig.debug +17 -3
@@ -2427,6 +2427,23 @@ config ASYNC_RAID6_TEST config TEST_HEXDUMP tristate "Test functions located in the hexdump module at runtime" +config SCANF_KUNIT_TEST + tristate "KUnit test scanf() family of functions at runtime" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test the scanf functions at boot. + + KUnit tests run during boot and output the results to the debug log + in TAP format (http://testanything.org/). Only useful for kernel devs + running the KUnit test harness, and not intended for inclusion into a + production build. + + 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 STRING_KUNIT_TEST tristate "KUnit test string functions at runtime" if !KUNIT_ALL_TESTS depends on KUNIT
@@ -2443,9 +2460,6 @@ config TEST_KSTRTOX config TEST_PRINTF tristate "Test printf() family of functions at runtime" -config TEST_SCANF - tristate "Test scanf() family of functions at runtime" - config TEST_BITMAP tristate "Test bitmap_*() family of functions at runtime" help
lib/Makefile +1 -1
@@ -52,6 +52,7 @@ obj-y += bcd.o sort.o parser.o debug_locks.o random32.o \ percpu-refcount.o rhashtable.o base64.o \ once.o refcount.o rcuref.o usercopy.o errseq.o bucket_locks.o \ generic-radix-tree.o bitmap-str.o +obj-$(CONFIG_SCANF_KUNIT_TEST) += test_scanf.o obj-$(CONFIG_STRING_KUNIT_TEST) += string_kunit.o obj-y += string_helpers.o obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) += string_helpers_kunit.o
@@ -85,7 +86,6 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o obj-$(CONFIG_TEST_PRINTF) += test_printf.o -obj-$(CONFIG_TEST_SCANF) += test_scanf.o obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
lib/test_scanf.c +339 -365
1,042 lines not on this page · raw message
tools/testing/selftests/lib/Makefile +1 -1
@@ -4,5 +4,5 @@ # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" all: -TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh scanf.sh +TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh include ../lib.mk
tools/testing/selftests/lib/config +0 -1
@@ -1,5 +1,4 @@ CONFIG_TEST_PRINTF=m -CONFIG_TEST_SCANF=m CONFIG_TEST_BITMAP=m CONFIG_PRIME_NUMBERS=m CONFIG_TEST_BITOPS=m
tools/testing/selftests/lib/scanf.sh deleted +0 -4
@@ -1,4 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 -# Tests the scanf infrastructure using test_scanf kernel module. -$(dirname $0)/../kselftest/module.sh "scanf" test_scanf
---
base-commit: 18fe18c99c8d90d77c7ed6b42f48fa5b4e5c99c3
change-id: 20250131-scanf-kunit-convert-f70dc33bb34c
Best regards,
Signature · 1 line
Tamir Duberstein <[email protected]>
Quoted 6 lines · Tamir Duberstein
Convert the
scanf()self-test to a KUnit test.In the interest of keeping the patch reasonably-sized this doesn't rename the file in accordance with usual kunit conventions nor does it refactor the tests into proper parameterized tests - it's all one big test case.
Rename of the file may be done, but you need to use -M -C when formatting patch, in such a case the diff will be moderate in side and easy to review.
P.S. The test modules in defconfig is something which puzzling me. I would remove all of them at once, if somebody wants debug configuration, they would specify it and use with help of merge_config or alike.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 6 lines · Tamir Duberstein
Convert the
scanf()self-test to a KUnit test.In the interest of keeping the patch reasonably-sized this doesn't rename the file in accordance with usual kunit conventions nor does it refactor the tests into proper parameterized tests - it's all one big test case.
Rename of the file may be done, but you need to use -M -C when formatting patch, in such a case the diff will be moderate in side and easy to review.
If you prefer that I rename the file, I can do so in v2.
Can you explain what you mean by using -M -C? The formatting was done by hand, is there an automated tool? I tried using clang-format but the result was a change on almost every line.
Note also that though it looks like a lot of formatting has changed, in reality almost every changed line has non-formatting changes due to passing test around.
Quoted 3 lines
P.S. The test modules in defconfig is something which puzzling me. I would remove all of them at once, if somebody wants debug configuration, they would specify it and use with help ofmerge_configor alike.
I'm not sure what you mean? I removed instances of CONFIG_TEST_SCANF from defconfig because that option no longer exists.
Cheers.
Tamir
Quoted 17 lines · Tamir Duberstein
Quoted 11 lines · Andy Shevchenko
Quoted 6 lines · Tamir Duberstein
Convert the
scanf()self-test to a KUnit test.In the interest of keeping the patch reasonably-sized this doesn't rename the file in accordance with usual kunit conventions nor does it refactor the tests into proper parameterized tests - it's all one big test case.
Rename of the file may be done, but you need to use -M -C when formatting patch, in such a case the diff will be moderate in side and easy to review.
If you prefer that I rename the file, I can do so in v2.
Quoted 7 lines
Can you explain what you mean by using -M -C? The formatting was done by hand, is there an automated tool? I tried using clang-format but the result was a change on almost every line.
Note also that though it looks like a lot of formatting has changed, in reality almost every changed line has non-formatting changes due to passing
testaround.
Ah, you were referring to git format-patch. Sure, if you'd like me to rename the file, I'll use those flags in v2.
Quoted 10 lines
Quoted 3 lines
P.S. The test modules in defconfig is something which puzzling me. I would remove all of them at once, if somebody wants debug configuration, they would specify it and use with help ofmerge_configor alike.I'm not sure what you mean? I removed instances of
CONFIG_TEST_SCANFfrom defconfig because that option no longer exists.Cheers.
Tamir
Quoted 3 lines · Tamir Duberstein
Quoted 2 lines · Tamir Duberstein
On Fri, Jan 31, 2025 at 12:11 PM Andy Shevchenko
<[email protected]> wrote:
...
Quoted 10 lines
Quoted 7 lines
Can you explain what you mean by using -M -C? The formatting was done by hand, is there an automated tool? I tried using clang-format but the result was a change on almost every line.
Note also that though it looks like a lot of formatting has changed, in reality almost every changed line has non-formatting changes due to passing
testaround.Ah, you were referring to git format-patch. Sure, if you'd like me to rename the file, I'll use those flags in v2.
Yes.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Tamir Duberstein
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Tamir Duberstein
Convert the
scanf()self-test to a KUnit test.In the interest of keeping the patch reasonably-sized this doesn't rename the file in accordance with usual kunit conventions nor does it refactor the tests into proper parameterized tests - it's all one big test case.
Quoted 4 lines
Quoted 2 lines
Rename of the file may be done, but you need to use -M -C when formatting patch, in such a case the diff will be moderate in side and easy to review.
If you prefer that I rename the file, I can do so in v2.
Yes, please.
Quoted 1 line
Can you explain what you mean by using -M -C?
Parameters to git format-patch.
Quoted 8 lines
The formatting was done
by hand, is there an automated tool? I tried using clang-format but the result was a change on almost every line.Note also that though it looks like a lot of formatting has changed, in reality almost every changed line has non-formatting changes due to passing
testaround.
Quoted 6 lines
Quoted 3 lines
P.S. The test modules in defconfig is something which puzzling me. I would remove all of them at once, if somebody wants debug configuration, they would specify it and use with help ofmerge_configor alike.I'm not sure what you mean? I removed instances of
CONFIG_TEST_SCANFfrom defconfig because that option no longer exists.
There are other options like CONFIG_TEST_PRINTF or so in defconfig files. Why are they there to begin with? The answer to this Q will affect the change you have done in this patch.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Tamir Duberstein
Quoted 1 line · Andy Shevchenko
On Fri, Jan 31, 2025 at 10:47:49AM -0500, Tamir Duberstein wrote:
[...]
Quoted 3 lines
There are other options like
CONFIG_TEST_PRINTFor so in defconfig files. Why are they there to begin with? The answer to this Q will affect the change you have done in this patch.
CONFIG_TEST_PRINTF still exists; that test has not been converted to kunit.
Quoted 9 lines · Tamir Duberstein
Quoted 5 lines · Andy Shevchenko
Quoted 3 lines · Tamir Duberstein
Quoted 1 line · Andy Shevchenko
On Fri, Jan 31, 2025 at 10:47:49AM -0500, Tamir Duberstein wrote:
Quoted 7 lines
[...]
Quoted 3 lines
There are other options like
CONFIG_TEST_PRINTFor so in defconfig files. Why are they there to begin with? The answer to this Q will affect the change you have done in this patch.
CONFIG_TEST_PRINTFstill exists; that test has not been converted to kunit.
Ah, sorry, I had misunderstood your question. These were there to enable those tests; when the tests are ported to KUnit this is no longer necessary because of the presence of CONFIG_KUNIT_ALL_TESTS.
Geert Uytterhoeven
maintainerHi Andy,
Quoted 3 lines · Andy Shevchenko
P.S. The test modules in defconfig is something which puzzling me. I would remove all of them at once, if somebody wants debug configuration, they would specify it and use with help ofmerge_configor alike.
I really like having all tests available as modules. Fortunately all of these will be gone, once all tests have been converted to kunit, and have a "default KUNIT_ALL_TESTS" line...
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 14 lines · Tamir Duberstein
Convert the
scanf()self-test to a KUnit test.In the interest of keeping the patch reasonably-sized this doesn't rename the file in accordance with usual kunit conventions nor does it refactor the tests into proper parameterized tests - it's all one big test case.
Signed-off-by Tamir Duberstein <[email protected]>---
This is one of just 3 remaining "Test Module" kselftests (the others being bitmap and printf), the rest having been converted to KUnit. In addition to the enclosed patch, please consider this an RFC on the removal of the "Test Module" kselftest machinery.
Quoted 3 lines
I tested this using:
$ tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 scanf
Sounds way too complicated: "modprobe test_scanf" ;-)
Quoted 4 lines
arch/m68k/configs/amiga_defconfig | 1 - arch/m68k/configs/apollo_defconfig | 1 - arch/m68k/configs/atari_defconfig | 1 - arch/m68k/configs/bvme6000_defconfig | 1 -
Quoted 8 lines
arch/m68k/configs/hp300_defconfig | 1 - arch/m68k/configs/mac_defconfig | 1 - arch/m68k/configs/multi_defconfig | 1 - arch/m68k/configs/mvme147_defconfig | 1 - arch/m68k/configs/mvme16x_defconfig | 1 - arch/m68k/configs/q40_defconfig | 1 - arch/m68k/configs/sun3_defconfig | 1 - arch/m68k/configs/sun3x_defconfig | 1 -
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds