Re: [PATCH v6 1/2] scanf: convert self-test to KUnit
From: Petr Mladek
Date: Tue Feb 11 2025 - 06:44:41 EST
On Mon 2025-02-10 13:13:48, Tamir Duberstein wrote:
> Convert the scanf() 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.
>
> Acked-by: Petr Mladek <pmladek@xxxxxxxx>
Please, remove this. The patchset has changed a lot and it is not
longer true.
> --- a/lib/test_scanf.c
> +++ b/lib/scanf_kunit.c
> @@ -15,67 +13,49 @@
[...]
> #define _check_numbers_template(arg_fmt, expect, str, fmt, n_args, ap) \
> do { \
> - pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \
> + kunit_printk(KERN_DEBUG, test, "\"%s\", \"%s\" ->", str, fmt); \
The switch from pr_debug() to kunit_printk() causes printing huge
amount of messages even when the test passes.
[ 5780.664377] KTAP version 1
[ 5780.664891] 1..1
[ 5780.665376] KTAP version 1
[ 5780.665765] # Subtest: scanf
[ 5780.666104] # module: scanf_kunit
[ 5780.666112] 1..10
[ 5780.667354] # numbers_simple: "0", "%llu" ->
[ 5780.667371] # numbers_simple: 0
[ 5780.667923] # numbers_simple: "0", "%llu" ->
[ 5780.668321] # numbers_simple: 0
[ 5780.668803] # numbers_simple: "1", "%llu" ->
[ 5780.669175] # numbers_simple: 1
[ 5780.669624] # numbers_simple: "18446744073709551615", "%llu" ->
[... skipping 7500+ lines ...]
[ 5783.157777] # test_simple_strtol: simple_strtol("0x7fffffffffffffff", 0) -> 0x7fffffffffffffff
[ 5783.158229] # test_simple_strtol: simple_strtol("0x8000000000000001", 0) -> 0x8000000000000001
[ 5783.158683] # test_simple_strtol: simple_strtol("0x8000000000000000", 0) -> 0x8000000000000000
[ 5783.159131] # test_simple_strtol: simple_strtol("0x8000000000000000", 0) -> 0x8000000000000000
[ 5783.159586] # test_simple_strtol: simple_strtol("0x8000000000000001", 0) -> 0x8000000000000001
[ 5783.160048] # test_simple_strtol: simple_strtol("0x7fffffffffffffff", 0) -> 0x7fffffffffffffff
[ 5783.160506] # test_simple_strtol: simple_strtol("0xfffffffffffffffe", 0) -> 0xfffffffffffffffe
[ 5783.160957] # test_simple_strtol: simple_strtol("0x2", 0) -> 0x2
[ 5783.161467] # test_simple_strtol: simple_strtol("0xffffffffffffffff", 0) -> 0xffffffffffffffff
[ 5783.161806] # test_simple_strtol: simple_strtol("0x1", 0) -> 0x1
[ 5783.162564] ok 10 test_simple_strtol
[ 5783.163145] # scanf: pass:10 fail:0 skip:0 total:10
[ 5783.163537] # Totals: pass:22 fail:0 skip:0 total:22
[ 5783.164052] ok 1 scanf
Yes, it would help with debugging. But we should print these details
only when the test fails!
Partial solution might be to use pr_debug(). The messages will be
disabled by default and can be enabled via /sys/kernel/debug/dynamic_debug/control
Here is some POC: