scanf: convert self-test to KUnit
Subsystems (2)
v7 cover scanf: convert self-test to KUnit
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
---
Changes in v7:
- Remove redundant debug logs. (Petr Mladek)
- Drop Petr's Acked-by.
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334
not ok 1 " "
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28
not ok 2 ":"
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614
not ok 3 ","
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381
not ok 4 "-"
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328
not ok 5 "/"
# numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5
not ok 4 numbers_list_field_width_val_width
# numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- s/at boot/at runtime/ for consistency with the printf series.
- Go back to kmalloc. (Geert Uytterhoeven)
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Remove extraneous trailing newlines from failure messages.
- Replace pr_debug with kunit_printk.
- Use static char arrays instead of kmalloc.
- Drop KUnit boilerplate from CONFIG_SCANF_KUNIT_TEST help text.
- Drop arch changes.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Bake test into various macros, greatly reducing diff noise.
- Revert control flow changes.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Reduce diff noise in lib/Makefile. (Petr Mladek)
- Split scanf_test into a few test cases. New output:
: =================== scanf (10 subtests) ====================
: [PASSED] numbers_simple
: ====================== numbers_list =======================
: [PASSED] delim=" "
: [PASSED] delim=":"
: [PASSED] delim=","
: [PASSED] delim="-"
: [PASSED] delim="/"
: ================== [PASSED] numbers_list ===================
: ============ numbers_list_field_width_typemax =============
: [PASSED] delim=" "
: [PASSED] delim=":"
: [PASSED] delim=","
: [PASSED] delim="-"
: [PASSED] delim="/"
: ======== [PASSED] numbers_list_field_width_typemax =========
: =========== numbers_list_field_width_val_width ============
: [PASSED] delim=" "
: [PASSED] delim=":"
: [PASSED] delim=","
: [PASSED] delim="-"
: [PASSED] delim="/"
: ======= [PASSED] numbers_list_field_width_val_width ========
: [PASSED] numbers_slice
: [PASSED] numbers_prefix_overflow
: [PASSED] test_simple_strtoull
: [PASSED] test_simple_strtoll
: [PASSED] test_simple_strtoul
: [PASSED] test_simple_strtol
: ====================== [PASSED] scanf ======================
: ============================================================
: Testing complete. Ran 22 tests: passed: 22
: Elapsed time: 5.517s total, 0.001s configuring, 5.440s building, 0.067s running
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Rename lib/{test_scanf.c => scanf_kunit.c}. (Andy Shevchenko)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Tamir Duberstein (3):
scanf: remove redundant debug logs
scanf: convert self-test to KUnit
scanf: break kunit into test cases
MAINTAINERS | 2 +-
lib/Kconfig.debug | 12 +-
lib/Makefile | 2 +-
lib/{test_scanf.c => scanf_kunit.c} | 270 +++++++++++++++++------------------
tools/testing/selftests/lib/Makefile | 2 +-
tools/testing/selftests/lib/config | 1 -
tools/testing/selftests/lib/scanf.sh | 4 -
7 files changed, 143 insertions(+), 150 deletions(-)---
base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3
change-id: 20250131-scanf-kunit-convert-f70dc33bb34c
Best regards,
Signature · 1 line
Tamir Duberstein <[email protected]>
PATCH v7 1/3 scanf: remove redundant debug logs
The test already prints the same information on failure; remove redundant pr_debug() logs.
--- lib/test_scanf.c | 3 --- 1 file changed, 3 deletions(-)
lib/test_scanf.c +0 -3
@@ -62,10 +62,8 @@ _test(check_fn fn, const void *check_data, const char *string, const char *fmt,#define _check_numbers_template (arg_fmt, expect, str, fmt, n_args, ap) \ do { \ - pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \ for (; n_args > 0; n_args--, expect++) { \ typeof(*expect) got = *va_arg(ap, typeof(expect)); \ - pr_debug("\t" arg_fmt "\n", got); \ if (got != *expect) { \ pr_warn("vsscanf(\"%s\", \"%s\", ...) expected " arg_fmt " got " arg_fmt "\n", \ str, fmt, *expect, got); \
@@ -689,7 +687,6 @@ do { \ total_tests++; \ len =snprintf (test_buffer,BUF_SIZE , gen_fmt, expect); \ got = (fn)(test_buffer, &endp, base); \ - pr_debug(#fn "(\"%s\", %d) -> " gen_fmt "\n", test_buffer, base, got); \if (got != (expect)) { \ fail = true; \ pr_warn(#fn "(\"%s\", %d): got " gen_fmt " expected " gen_fmt "\n", \
Signature · 1 line
2.48.1
Re: [PATCH v7 1/3] scanf: remove redundant debug logs
Quoted 2 lines · Tamir Duberstein
The test already prints the same information on failure; remove redundant
pr_debug()logs.
...
lib/test_scanf.c _test(check_fn fn, const void *check_data, const char *string, const char *fmt, · line 65
Quoted 3 lines
#define
_check_numbers_template(arg_fmt, expect, str, fmt, n_args, ap)\
do { \lib/test_scanf.c +0
-1-pr_debug ("\"%s\", \"%s\" ->\n" , str, fmt); \
What *if* the n_args == 0 here?
Quoted 14 lines
lib/test_scanf.c +0
-2for (; n_args >0 ; n_args--, expect++) { \ typeof(*expect) got = *va_arg(ap, typeof(expect)); \ -pr_debug ("\t" arg_fmt"\n" , got); \if (got != *expect) { \pr_warn ("vsscanf(\"%s\", \"%s\", ...) expected " arg_fmt" got " arg_fmt"\n" , \ str, fmt, *expect, got); \@@ -689,7 +687,6 @@ do { \ total_tests++; \ len =snprintf (test_buffer,BUF_SIZE , gen_fmt, expect); \ got = (fn)(test_buffer, &endp, base); \ - pr_debug(#fn "(\"%s\", %d) -> " gen_fmt "\n", test_buffer, base, got); \if (got != (expect)) { \ fail = true; \ pr_warn(#fn "(\"%s\", %d): got " gen_fmt " expected " gen_fmt "\n", \
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 1/3] scanf: remove redundant debug logs
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Tamir Duberstein
The test already prints the same information on failure; remove redundant
pr_debug()logs.
Quoted 7 lines
...
Quoted 3 lines
#define
_check_numbers_template(arg_fmt, expect, str, fmt, n_args, ap)\
do { \
-pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \What *if* the
n_args== 0 here?
Then there's no assertion in this block, so the test cannot possibly fail here.
Quoted 20 lines
Quoted 7 lines
for (; n_args > 0; n_args--, expect++) { \ typeof(*expect) got = *va_arg(ap, typeof(expect)); \lib/test_scanf.c +0
-1-pr_debug ("\t" arg_fmt"\n" , got); \if (got != *expect) { \pr_warn ("vsscanf(\"%s\", \"%s\", ...) expected " arg_fmt" got " arg_fmt"\n" , \ str, fmt, *expect, got); \lib/test_scanf.c do { \ · line 692
Quoted 7 lines
lib/test_scanf.c +0
-1@@ -689,7 +687,6 @@ do { \ total_tests++; \ len =snprintf (test_buffer,BUF_SIZE , gen_fmt, expect); \ got = (fn)(test_buffer, &endp, base); \ - pr_debug(#fn "(\"%s\", %d) -> " gen_fmt "\n", test_buffer, base, got); \if (got != (expect)) { \ fail = true; \ pr_warn(#fn "(\"%s\", %d): got " gen_fmt " expected " gen_fmt "\n", \--
With Best Regards,
Andy Shevchenko
Re: [PATCH v7 1/3] scanf: remove redundant debug logs
Quoted 5 lines · Tamir Duberstein
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tamir Duberstein
The test already prints the same information on failure; remove redundant
pr_debug()logs.
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
-
pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \What *if* the
n_args== 0 here?Then there's no assertion in this block, so the test cannot possibly fail here.
Correct, but I'm talking about this in a scope of the removed debug print. I.o.w. how would we even know that this was the case?
(I'm not objecting removal, what I want from you is to have a descriptive and
explanatory commit message that's answers to "why is this needed?" and "why is it safe to do?")
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 1/3] scanf: remove redundant debug logs
Quoted 14 lines · Andy Shevchenko
Quoted 5 lines · Tamir Duberstein
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tamir Duberstein
The test already prints the same information on failure; remove redundant
pr_debug()logs....
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
-
pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \What *if* the
n_args== 0 here?
Quoted 8 lines
Quoted 1 line
Then there's no assertion in this block, so the test cannot possibly fail here.
Correct, but I'm talking about this in a scope of the removed debug print. I.o.w. how would we even know that this was the case?
(I'm not objecting removal, what I want from you is to have a descriptive and
explanatory commit message that's answers to "why is this needed?" and "why is it safe to do?")
The true answer to "why is this needed" is Petr requested it in
https://lore.kernel.org/all/[email protected]/ (again, lore is having issues):
Quoted 10 lines · Petr Mladek
[...]
But when thinking more about it. I think that even
pr_debug()is not the right solution.IMHO, we really want to print these details only when the test fails.
Best Regards,
Petr
The commit message already answers "why is it safe to do":
Quoted 2 lines
The test already prints the same information on failure; remove redundant
pr_debug()logs.
Perhaps what you're asking for is an assertion to be added if n_args == 0? I think that would make sense. Does it belong in this series?
Tamir
Re: [PATCH v7 1/3] scanf: remove redundant debug logs
Quoted 8 lines · Tamir Duberstein
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Tamir Duberstein
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tamir Duberstein
The test already prints the same information on failure; remove redundant
pr_debug()logs.
...
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
-
pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \What *if* the
n_args== 0 here?Quoted 8 lines
Quoted 1 line
Then there's no assertion in this block, so the test cannot possibly fail here.
Correct, but I'm talking about this in a scope of the removed debug print. I.o.w. how would we even know that this was the case?
(I'm not objecting removal, what I want from you is to have a descriptive and
explanatory commit message that's answers to "why is this needed?" and "why is it safe to do?")The true answer to "why is this needed" is Petr requested it in
https://lore.kernel.org/all/[email protected]/ (again, lore is having issues):On Tue, Feb 11, 2025 at 6:37 AM Petr Mladek <[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 7 lines
But when thinking more about it. I think that even
pr_debug()is not the right solution.IMHO, we really want to print these details only when the test fails.
Best Regards,
PetrThe commit message already answers "why is it safe to do":
Not really. It answers that "why is it safe to do when test case fails?".
Quoted 5 lines
Quoted 2 lines
The test already prints the same information on failure; remove redundant
pr_debug()logs.Perhaps what you're asking for is an assertion to be added if
n_args== 0? I think that would make sense. Does it belong in this series?
I don't know if it's possible case. I don't know if we need an assertion. Please, research.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 1/3] scanf: remove redundant debug logs
Quoted 46 lines · Andy Shevchenko
Quoted 8 lines · Tamir Duberstein
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Tamir Duberstein
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Tamir Duberstein
The test already prints the same information on failure; remove redundant
pr_debug()logs....
Quoted 18 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
-
pr_debug("\"%s\", \"%s\" ->\n", str, fmt); \What *if* the
n_args== 0 here?Quoted 8 lines
Quoted 1 line
Then there's no assertion in this block, so the test cannot possibly fail here.
Correct, but I'm talking about this in a scope of the removed debug print. I.o.w. how would we even know that this was the case?
(I'm not objecting removal, what I want from you is to have a descriptive and
explanatory commit message that's answers to "why is this needed?" and "why is it safe to do?")The true answer to "why is this needed" is Petr requested it in
https://lore.kernel.org/all/[email protected]/ (again, lore is having issues):On Tue, Feb 11, 2025 at 6:37 AM Petr Mladek <[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 7 lines
But when thinking more about it. I think that even
pr_debug()is not the right solution.IMHO, we really want to print these details only when the test fails.
Best Regards,
PetrThe commit message already answers "why is it safe to do":
Not really. It answers that "why is it safe to do when test case fails?".
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The test already prints the same information on failure; remove redundant
pr_debug()logs.Perhaps what you're asking for is an assertion to be added if
n_args== 0? I think that would make sense. Does it belong in this series?I don't know if it's possible case. I don't know if we need an assertion. Please, research.
Such an assertion is not necessary. _check_numbers_template is called from check_{ull,ll,ulong,long,uint,int,ushort,short,uchar,char} which are in turn called from _test:
Quoted 5 lines
if (ret !=
n_args) {
KUNIT_FAIL(test, "vsscanf(\"%s\", \"%s\", ...) returned %d expected %d", string, fmt, ret, n_args);
} else {
(*fn)(test,check_data, string, fmt,n_args, ap); // <--fnischeck_*.
}
So n_args comes from the test expectation, and it's already checked against the return value of vsscanf.
PATCH v7 2/3 scanf: convert self-test to KUnit
In reply to Tamir DubersteinConvert 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.
---
MAINTAINERS | 2 +-
lib/Kconfig.debug | 12 +-
lib/Makefile | 2 +-
lib/{test_scanf.c => scanf_kunit.c} | 221 +++++++++++++++++------------------
tools/testing/selftests/lib/Makefile | 2 +-
tools/testing/selftests/lib/config | 1 -
tools/testing/selftests/lib/scanf.sh | 4 -
7 files changed, 116 insertions(+), 128 deletions(-)MAINTAINERS +1 -1
@@ -25411,8 +25411,8 @@ R: Sergey Senozhatsky <[email protected]> S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git F: Documentation/core-api/printk-formats.rst +F: lib/scanf_kunit.c F: lib/test_printf.c -F: lib/test_scanf.c F: lib/vsprintf.c VT1211 HARDWARE MONITOR DRIVER
lib/Kconfig.debug +9 -3
@@ -2427,6 +2427,15 @@ 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 runtime. + + If unsure, say N. + config STRING_KUNIT_TEST tristate "KUnit test string functions at runtime" if !KUNIT_ALL_TESTS depends on KUNIT
@@ -2443,9 +2452,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
@@ -85,7 +85,7 @@ 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_SCANF_KUNIT_TEST) += scanf_kunit.o obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_KASAN),yy)
lib/scanf_kunit.c renamed from lib/test_scanf.c +104 -117
560 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
Signature · 1 line
2.48.1
PATCH v7 3/3 scanf: break kunit into test cases
In reply to Tamir DubersteinUse suite_init and move some tests into scanf_test_cases. This gives us nicer output in the event of a failure.
--- lib/scanf_kunit.c | 94 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 43 deletions(-)
lib/scanf_kunit.c +51 -43
@@ -4,14 +4,10 @@*/ #include <kunit/test.h> -#include <linux/bitops.h> -#include <linux/kernel.h> #include <linux/module.h> -#include <linux/overflow.h> -#include <linux/printk.h> #include <linux/prandom.h> #include <linux/slab.h> -#include <linux/string.h> +#include <linux/sprintf.h> #define BUF_SIZE 1024
@@ -49,9 +45,9 @@ do { \for (; n_args >0 ; n_args--, expect++) { \ typeof(*expect) got = *va_arg(ap, typeof(expect)); \if (got != *expect) { \ -KUNIT_FAIL (test, \ -"vsscanf(\"%s\", \"%s\", ...) expected " arg_fmt" got " arg_fmt, \ - str, fmt, *expect, got); \ +KUNIT_FAIL_AND_ABORT (test, \ +"vsscanf(\"%s\", \"%s\", ...) expected " arg_fmt" got " arg_fmt, \ + str, fmt, *expect, got); \ } \ } \ }while (0 )
@@ -429,8 +425,11 @@ static void numbers_list_hh(struct kunit *test, const char *delim) numbers_list_8(signed char, "0x%hhx", delim, "hhi", check_char); } -static void numbers_list (struct kunit *test,const char *delim) +static void numbers_list (struct kunit *test) { +const char *const *param = test->param_value; +const char *delim = *param; +numbers_list_ll (test, delim);numbers_list_l (test, delim);numbers_list_d (test, delim);
@@ -501,8 +500,11 @@ static void numbers_list_field_width_hh(struct kunit *test, const char *delim)* List of numbers separated by delim. Each field width specifier is the * maximum possible digits for the given type and base. */ -static void numbers_list_field_width_typemax (struct kunit *test,const char *delim) +static void numbers_list_field_width_typemax (struct kunit *test) { +const char *const *param = test->param_value; +const char *delim = *param; +numbers_list_field_width_ll (test, delim);numbers_list_field_width_l (test, delim);numbers_list_field_width_d (test, delim);
@@ -564,8 +566,11 @@ static void numbers_list_field_width_val_hh(struct kunit *test, const char *deli* List of numbers separated by delim. Each field width specifier is the * exact length of the corresponding value digits in the string being scanned. */ -static void numbers_list_field_width_val_width (struct kunit *test,const char *delim) +static void numbers_list_field_width_val_width (struct kunit *test) { +const char *const *param = test->param_value; +const char *delim = *param; +numbers_list_field_width_val_ll (test, delim);numbers_list_field_width_val_l (test, delim);numbers_list_field_width_val_d (test, delim);
@@ -581,7 +586,12 @@ static void numbers_list_field_width_val_width(struct kunit *test, const char *d*/ static void numbers_slice (struct kunit *test) { -numbers_list_field_width_val_width (test,"" ); +const char *delim ="" ; + +KUNIT_ASSERT_PTR_EQ (test, test->param_value,NULL ); + test->param_value = &delim; + +numbers_list_field_width_val_width (test); }#define test_number_prefix (T , str, scan_fmt, expect0, expect1, n_args, fn) \
@@ -732,62 +742,60 @@ static const char * const number_delimiters[] = { " ", ":", ",", "-", "/", }; -static void test_numbers (struct kunit *test) +static void number_delimiter_param_desc (const char *const *param, +char *desc) { -int i; +snprintf (desc,KUNIT_PARAM_DESC_SIZE ,"\"%s\"" , *param); +} -/* String containing only one number. */ -numbers_simple (test); +KUNIT_ARRAY_PARAM (number_delimiters, number_delimiters, number_delimiter_param_desc); +static struct kunit_case scanf_test_cases[] = { +KUNIT_CASE (numbers_simple),/* String with multiple numbers separated by delimiter. */ -for (i =0 ; i <ARRAY_SIZE (number_delimiters); i++) { -numbers_list (test, number_delimiters[i]); - -/* Field width may be longer than actual field digits. */ -numbers_list_field_width_typemax (test, number_delimiters[i]); - -/* Each field width exactly length of actual field digits. */ -numbers_list_field_width_val_width (test, number_delimiters[i]); - } - +KUNIT_CASE_PARAM (numbers_list, number_delimiters_gen_params), +/* Field width may be longer than actual field digits. */ +KUNIT_CASE_PARAM (numbers_list_field_width_typemax, number_delimiters_gen_params), +/* Each field width exactly length of actual field digits. */ +KUNIT_CASE_PARAM (numbers_list_field_width_val_width, number_delimiters_gen_params),/* Slice continuous sequence of digits using field widths. */ -numbers_slice (test); +KUNIT_CASE (numbers_slice), +KUNIT_CASE (numbers_prefix_overflow), -numbers_prefix_overflow (test); -} +KUNIT_CASE (test_simple_strtoull), +KUNIT_CASE (test_simple_strtoll), +KUNIT_CASE (test_simple_strtoul), +KUNIT_CASE (test_simple_strtol), + {} +}; -static void scanf_test (struct kunit *test) +static int scanf_suite_init (struct kunit_suite *suite) { test_buffer =kmalloc (BUF_SIZE ,GFP_KERNEL );if (!test_buffer) -return ; +return -ENOMEM ; fmt_buffer =kmalloc (BUF_SIZE ,GFP_KERNEL );if (!fmt_buffer) {kfree (test_buffer); -return ; +return -ENOMEM ; }prandom_seed_state (&rnd_state,3141592653589793238ULL ); -test_numbers (test); - -test_simple_strtoull (test); -test_simple_strtoll (test); -test_simple_strtoul (test); -test_simple_strtol (test); +return 0 ; +} +static void scanf_suite_exit (struct kunit_suite *suite) +{kfree (fmt_buffer);kfree (test_buffer); } -static struct kunit_case scanf_test_cases[] = { -KUNIT_CASE (scanf_test), - {} -}; -static struct kunit_suite scanf_test_suite = { .name ="scanf" , + .suite_init = scanf_suite_init, + .suite_exit = scanf_suite_exit, .test_cases = scanf_test_cases, };
Signature · 1 line
2.48.1
Quoted 9 lines · Tamir Duberstein
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
Quoted 7 lines
Signed-off-by Tamir Duberstein <[email protected]>---
Changes in v7:
- Remove redundant debug logs. (Petr Mladek)
- Drop Petr's Acked-by.
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
It would be good if you put into cover letter, or even in the respectful patch the example of the error report for the old code and new code that it will be clear how it changes.
Quoted 18 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334
not ok 1 " "
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28
not ok 2 ":"
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614
not ok 3 ","
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381
not ok 4 "-"
# numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328
not ok 5 "/"
# numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5
not ok 4 numbers_list_field_width_val_width
# numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92
vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 9 lines · Tamir Duberstein
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 scanfQuoted 7 lines
Signed-off-by Tamir Duberstein <[email protected]>---
Changes in v7:
- Remove redundant debug logs. (Petr Mladek)
- Drop Petr's Acked-by.
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
Quoted 22 lines
It would be good if you put into cover letter, or even in the respectful patch the example of the error report for the old code and new code that it will be clear how it changes.
Quoted 18 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334 not ok 1 " " # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28 not ok 2 ":" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614 not ok 3 "," # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381 not ok 4 "-" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328 not ok 5 "/" # numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5 not ok 4 numbers_list_field_width_val_width # numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518
Makes sense. As you can see the error report for the new code is included here. I'll add the old code's error report if I have to respin v8.
Quoted 3 lines · Tamir Duberstein
Quoted 1 line · Andy Shevchenko
On Tue, Feb 11, 2025 at 10:13:36AM -0500, Tamir Duberstein wrote:
...
Quoted 26 lines
Quoted 25 lines
Quoted 2 lines
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
It would be good if you put into cover letter, or even in the respectful patch the example of the error report for the old code and new code that it will be clear how it changes.
Quoted 18 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334 not ok 1 " " # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28 not ok 2 ":" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614 not ok 3 "," # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381 not ok 4 "-" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328 not ok 5 "/" # numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5 not ok 4 numbers_list_field_width_val_width # numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518
Quoted 3 lines
Makes sense. As you can see the error report for the new code is included here. I'll add the old code's error report if I have to respin v8.
At a bare minimum. can you add in the reply to this email?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 34 lines · Andy Shevchenko
Quoted 3 lines · Tamir Duberstein
Quoted 1 line · Andy Shevchenko
On Tue, Feb 11, 2025 at 10:13:36AM -0500, Tamir Duberstein wrote:
...
Quoted 26 lines
Quoted 25 lines
Quoted 2 lines
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
It would be good if you put into cover letter, or even in the respectful patch the example of the error report for the old code and new code that it will be clear how it changes.
Quoted 18 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334 not ok 1 " " # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28 not ok 2 ":" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614 not ok 3 "," # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381 not ok 4 "-" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328 not ok 5 "/" # numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5 not ok 4 numbers_list_field_width_val_width # numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518
Quoted 5 lines
Quoted 3 lines
Makes sense. As you can see the error report for the new code is included here. I'll add the old code's error report if I have to respin v8.
At a bare minimum. can you add in the reply to this email?
Oh, sure:
Quoted 10 lines · Petr Mladek
[...]
[ 383.100048] test_scanf: vsscanf("1574 9 64ca 935b 7 142d ff58 0", "%4hx %1hx %4hx %4hx %1hx %4hx %4hx %1hx", ...) expected 2472240330 got 1690959881 [ 383.102843] test_scanf: vsscanf("f12:2:d:2:c166:1:36b:1906", "%3hx:%1hx:%1hx:%1hx:%4hx:%1hx:%3hx:%4hx", ...) expected 131085 got 851970 [ 383.105376] test_scanf: vsscanf("4,b2fe,3,593,6,0,3bde,0", "%1hx,%4hx,%1hx,%3hx,%1hx,%1hx,%4hx,%1hx", ...) expected 93519875 got 242430 [ 383.105659] test_scanf: vsscanf("6-1-2-1-d9e6-f-93e-e567", "%1hx-%1hx-%1hx-%1hx-%4hx-%1hx-%3hx-%4hx", ...) expected 65538 got 131073 [ 383.106127] test_scanf: vsscanf("72d6/35/e88d/1/0/6c8c/7/1", "%4hx/%2hx/%4hx/%1hx/%1hx/%4hx/%1hx/%1hx", ...) expected 125069 got 3901554741 [ 383.106235] test_scanf: vsscanf("c9bea1b8122113e9a168df573", "%4hx%4hx%1hx%4hx%4hx%1hx%4hx%3hx", ...) expected 571539457 got 106936 [ 383.106398] test_scanf: failed 6 out of 2545 tests
This is from https://lore.kernel.org/all/[email protected]/
(doesn't load for me, seems lore is having problems).
Quoted 6 lines · Tamir Duberstein
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Tamir Duberstein
Quoted 1 line · Andy Shevchenko
On Tue, Feb 11, 2025 at 10:13:36AM -0500, Tamir Duberstein wrote:
...
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 25 lines
Quoted 2 lines
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
It would be good if you put into cover letter, or even in the respectful patch the example of the error report for the old code and new code that it will be clear how it changes.
Quoted 18 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334 not ok 1 " " # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28 not ok 2 ":" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614 not ok 3 "," # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381 not ok 4 "-" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328 not ok 5 "/" # numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5 not ok 4 numbers_list_field_width_val_width # numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518Makes sense. As you can see the error report for the new code is included here. I'll add the old code's error report if I have to respin v8.
Quoted 16 lines
Quoted 1 line
At a bare minimum. can you add in the reply to this email?
Oh, sure:
Quoted 11 lines · Petr Mladek
[...]
[ 383.100048] test_scanf: vsscanf("1574 9 64ca 935b 7 142d ff58 0", "%4hx %1hx %4hx %4hx %1hx %4hx %4hx %1hx", ...) expected 2472240330 got 1690959881 [ 383.102843] test_scanf: vsscanf("f12:2:d:2:c166:1:36b:1906", "%3hx:%1hx:%1hx:%1hx:%4hx:%1hx:%3hx:%4hx", ...) expected 131085 got 851970 [ 383.105376] test_scanf: vsscanf("4,b2fe,3,593,6,0,3bde,0", "%1hx,%4hx,%1hx,%3hx,%1hx,%1hx,%4hx,%1hx", ...) expected 93519875 got 242430 [ 383.105659] test_scanf: vsscanf("6-1-2-1-d9e6-f-93e-e567", "%1hx-%1hx-%1hx-%1hx-%4hx-%1hx-%3hx-%4hx", ...) expected 65538 got 131073 [ 383.106127] test_scanf: vsscanf("72d6/35/e88d/1/0/6c8c/7/1", "%4hx/%2hx/%4hx/%1hx/%1hx/%4hx/%1hx/%1hx", ...) expected 125069 got 3901554741 [ 383.106235] test_scanf: vsscanf("c9bea1b8122113e9a168df573", "%4hx%4hx%1hx%4hx%4hx%1hx%4hx%3hx", ...) expected 571539457 got 106936[ 383.106398] test_scanf: failed 6 out of 2545 tests
Is it me who cut something or the above missing this information (total tests)? If the latter, how are we supposed to answer to the question if the failed test is from new bunch of cases I hypothetically added or regression of the existing ones? Without this it seems like I need to go through all failures. OTOH it may be needed anyway as failing test case needs an investigation.
Quoted 2 lines
This is from https://lore.kernel.org/all/[email protected]/
(doesn't load for me, seems lore is having problems).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 56 lines · Andy Shevchenko
Quoted 6 lines · Tamir Duberstein
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Tamir Duberstein
Quoted 1 line · Andy Shevchenko
On Tue, Feb 11, 2025 at 10:13:36AM -0500, Tamir Duberstein wrote:
...
Quoted 44 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 2 lines
- Use original test assertions as KUNIT_*_EQ_MSG produces hard-to-parse messages. The new failure output is:
It would be good if you put into cover letter, or even in the respectful patch the example of the error report for the old code and new code that it will be clear how it changes.
Quoted 18 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...) expected 837828163 got 1044578334 not ok 1 " " # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...) expected 892403712 got 28 not ok 2 ":" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...) expected 1892286475 got 757614 not ok 3 "," # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...) expected 50069505 got 99381 not ok 4 "-" # numbers_list_field_width_val_width: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...) expected 65559 got 1507328 not ok 5 "/" # numbers_list_field_width_val_width: pass:0 fail:5 skip:0 total:5 not ok 4 numbers_list_field_width_val_width # numbers_slice: ASSERTION FAILED at lib/scanf_kunit.c:92 vsscanf("3c87eac0f4afa1f9231da52", "%1hx%4hx%4hx%4hx%1hx%4hx%4hx%1hx", ...) expected 1257942031 got 2886715518Quoted 5 lines
Quoted 3 lines
Makes sense. As you can see the error report for the new code is included here. I'll add the old code's error report if I have to respin v8.
At a bare minimum. can you add in the reply to this email?
Oh, sure:
Quoted 9 lines · Petr Mladek
[...]
[ 383.100048] test_scanf: vsscanf("1574 9 64ca 935b 7 142d ff58 0", "%4hx %1hx %4hx %4hx %1hx %4hx %4hx %1hx", ...) expected 2472240330 got 1690959881 [ 383.102843] test_scanf: vsscanf("f12:2:d:2:c166:1:36b:1906", "%3hx:%1hx:%1hx:%1hx:%4hx:%1hx:%3hx:%4hx", ...) expected 131085 got 851970 [ 383.105376] test_scanf: vsscanf("4,b2fe,3,593,6,0,3bde,0", "%1hx,%4hx,%1hx,%3hx,%1hx,%1hx,%4hx,%1hx", ...) expected 93519875 got 242430 [ 383.105659] test_scanf: vsscanf("6-1-2-1-d9e6-f-93e-e567", "%1hx-%1hx-%1hx-%1hx-%4hx-%1hx-%3hx-%4hx", ...) expected 65538 got 131073 [ 383.106127] test_scanf: vsscanf("72d6/35/e88d/1/0/6c8c/7/1", "%4hx/%2hx/%4hx/%1hx/%1hx/%4hx/%1hx/%1hx", ...) expected 125069 got 3901554741 [ 383.106235] test_scanf: vsscanf("c9bea1b8122113e9a168df573", "%4hx%4hx%1hx%4hx%4hx%1hx%4hx%3hx", ...) expected 571539457 got 106936
Quoted 7 lines
Quoted 1 line
Quoted 1 line
[ 383.106398] test_scanf: failed 6 out of 2545 testsIs it me who cut something or the above missing this information (total tests)? If the latter, how are we supposed to answer to the question if the failed test is from new bunch of cases I hypothetically added or regression of the existing ones? Without this it seems like I need to go through all failures. OTOH it may be needed anyway as failing test case needs an investigation.
I assume you mean missing from the new output. Yeah, KUnit doesn't do this counting. Instead you get the test name in the failure message:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:92
I think maybe you're saying: what if I add a new assertion (rather than a new test case), and I start getting failure reports - how do I know if the reporter is running old or new test code?
In an ideal world the message above would give you all the information you need by including the line number from the test. This doesn't quite work out in this case because of the various test helper functions; you end up with a line number in the test helper rather than in the test itself. We could fix that by passing around __FILE__ and __LINE__ (probably by wrapping the test helpers in a macro). What do you think?
Quoted 18 lines · Tamir Duberstein
Quoted 6 lines
Is it me who cut something or the above missing this information (total tests)? If the latter, how are we supposed to answer to the question if the failed test is from new bunch of cases I hypothetically added or regression of the existing ones? Without this it seems like I need to go through all failures. OTOH it may be needed anyway as failing test case needs an investigation.
I assume you mean missing from the new output. Yeah, KUnit doesn't do this counting. Instead you get the test name in the failure message:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:92I think maybe you're saying: what if I add a new assertion (rather than a new test case), and I start getting failure reports - how do I know if the reporter is running old or new test code?
Quoted 7 lines
In an ideal world the message above would give you all the information you need by including the line number from the test. This doesn't quite work out in this case because of the various test helper functions; you end up with a line number in the test helper rather than in the test itself. We could fix that by passing around
__FILE__and__LINE__(probably by wrapping the test helpers in a macro). What do you think?
I gave this a try locally, and it produced this output:
Quoted 14 lines
#
numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...)expected 892403712 got 28
not ok 2 ":"
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...)expected 1892286475 got 757614
not ok 3 ","
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...)expected 50069505 got 99381
not ok 4 "-"
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...)expected 65559 got 1507328
Quoted 1 line
not ok 5 "/"
Andy, Petr: what do you think? I've added this (and the original output, as you requested) to the cover letter for when I reroll v8 (not before next week).
Quoted 19 lines · Tamir Duberstein
Quoted 18 lines · Tamir Duberstein
Quoted 6 lines
Is it me who cut something or the above missing this information (total tests)? If the latter, how are we supposed to answer to the question if the failed test is from new bunch of cases I hypothetically added or regression of the existing ones? Without this it seems like I need to go through all failures. OTOH it may be needed anyway as failing test case needs an investigation.
I assume you mean missing from the new output. Yeah, KUnit doesn't do this counting. Instead you get the test name in the failure message:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:92I think maybe you're saying: what if I add a new assertion (rather than a new test case), and I start getting failure reports - how do I know if the reporter is running old or new test code?
Quoted 7 lines
Quoted 7 lines
In an ideal world the message above would give you all the information you need by including the line number from the test. This doesn't quite work out in this case because of the various test helper functions; you end up with a line number in the test helper rather than in the test itself. We could fix that by passing around
__FILE__and__LINE__(probably by wrapping the test helpers in a macro). What do you think?
I am not sure how many changes are needed to wrap the test helpers in a macro.
Quoted 17 lines
I gave this a try locally, and it produced this output:
Quoted 15 lines
#
numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...)expected 892403712 got 28
not ok 2 ":"
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...)expected 1892286475 got 757614
not ok 3 ","
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...)expected 50069505 got 99381
not ok 4 "-"
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...)expected 65559 got 1507328not ok 5 "/"
But I really like that the error message shows the exact line of the caller. IMHO, it is very helpful in this module. I like it.
IMHO, it also justifies removing the pr_debug() messages (currently 1st patch).
Quoted 3 lines
Andy, Petr: what do you think? I've added this (and the original output, as you requested) to the cover letter for when I reroll v8 (not before next week).
I suggest, to do the switch into macros in the 1st patch. Remove the obsolete pr_debug() lines in 2nd patch. Plus two more patches switching the module to kunit test.
I am personally fine with this change.
Best Regards,
Petr
Quoted 59 lines · Petr Mladek
Quoted 19 lines · Tamir Duberstein
Quoted 18 lines · Tamir Duberstein
Quoted 6 lines
Is it me who cut something or the above missing this information (total tests)? If the latter, how are we supposed to answer to the question if the failed test is from new bunch of cases I hypothetically added or regression of the existing ones? Without this it seems like I need to go through all failures. OTOH it may be needed anyway as failing test case needs an investigation.
I assume you mean missing from the new output. Yeah, KUnit doesn't do this counting. Instead you get the test name in the failure message:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:92I think maybe you're saying: what if I add a new assertion (rather than a new test case), and I start getting failure reports - how do I know if the reporter is running old or new test code?
Quoted 7 lines
Quoted 7 lines
In an ideal world the message above would give you all the information you need by including the line number from the test. This doesn't quite work out in this case because of the various test helper functions; you end up with a line number in the test helper rather than in the test itself. We could fix that by passing around
__FILE__and__LINE__(probably by wrapping the test helpers in a macro). What do you think?I am not sure how many changes are needed to wrap the test helpers in a macro.
Quoted 17 lines
I gave this a try locally, and it produced this output:
Quoted 15 lines
#
numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("0 1e 3e43 31f0 0 0 5797 9c70", "%1hx %2hx %4hx %4hx %1hx %1hx %4hx %4hx", ...)expected 837828163 got 1044578334
not ok 1 " "
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("dc2:1c:0:3531:2621:5172:1:7", "%3hx:%2hx:%1hx:%4hx:%4hx:%4hx:%1hx:%1hx", ...)expected 892403712 got 28
not ok 2 ":"
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("e083,8f6e,b,70ca,1,1,aab1,10e4", "%4hx,%4hx,%1hx,%4hx,%1hx,%1hx,%4hx,%4hx", ...)expected 1892286475 got 757614
not ok 3 ","
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("2e72-8435-1-2fc-7cbd-c2f1-7158-2b41", "%4hx-%4hx-%1hx-%3hx-%4hx-%4hx-%4hx-%4hx", ...)expected 50069505 got 99381
not ok 4 "-"
#numbers_list_field_width_val_width: ASSERTION FAILED atlib/scanf_kunit.c:94lib/scanf_kunit.c:555:vsscanf("403/0/17/1/11e7/1/1fe8/34ba", "%3hx/%1hx/%2hx/%1hx/%4hx/%1hx/%4hx/%4hx", ...)expected 65559 got 1507328not ok 5 "/"But I really like that the error message shows the exact line of the caller. IMHO, it is very helpful in this module. I like it.
IMHO, it also justifies removing the
pr_debug()messages (currently 1st patch).Quoted 3 lines
Andy, Petr: what do you think? I've added this (and the original output, as you requested) to the cover letter for when I reroll v8 (not before next week).
Quoted 8 lines
I suggest, to do the switch into macros in the 1st patch. Remove the obsolete
pr_debug()lines in 2nd patch. Plus two more patches switching the module to kunit test.I am personally fine with this change.
Best Regards,
Petr
Thanks Petr. I'll send v8 now, then.