lib/test: convert lib/test_list_sort.c to use KUnit
Subsystems (2)
PATCH 2/2 lib/test: convert lib/test_list_sort.c to use KUnit
Functionally, this just means that the test output will be slightly changed and it'll now depend on CONFIG_KUNIT=y/m.
It'll still run at boot time and can still be built as a loadable module.
There was a pre-existing patch to convert this test that I found later, here [1]. Compared to [1], this patch doesn't rename files and uses KUnit features more heavily (i.e. does more than converting pr_err() calls to KUNIT_FAIL()).
What this conversion gives us:
* a shorter test thanks to KUnit's macros
* a way to run this a bit more easily via kunit.py (and CONFIG_KUNIT_ALL_TESTS=y) [2]
* a structured way of reporting pass/fail
* uses kunit-managed allocations to avoid the risk of memory leaks
* more descriptive error messages:
* i.e. it prints out which fields are invalid, what the expected values are, etc.
What this conversion does not do:
* change the name of the file (and thus the name of the module)
* change the name of the config option
Leaving these as-is for now to minimize the impact to people wanting to run this test. IMO, that concern trumps following KUnit's style guide for both names, at least for now.
[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] Can be run via
$ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF CONFIG_KUNIT=y CONFIG_TEST_LIST_SORT=y EOF
[16:55:56] Configuring KUnit Kernel ...
[16:55:56] Building KUnit Kernel ...
[16:56:29] Starting KUnit Kernel ...
[16:56:32] ============================================================ [16:56:32] ======== [PASSED] list_sort ========
[16:56:32] [PASSED] list_sort_test
[16:56:32] ============================================================ [16:56:32] Testing complete. 1 tests run. 0 failed. 0 crashed.
[16:56:32] Elapsed time: 35.668s total, 0.001s configuring, 32.725s building, 0.000s running
Note: the build time is as after a make mrproper.
--- lib/Kconfig.debug | 5 +- lib/test_list_sort.c | 128 +++++++++++++++++-------------------------- 2 files changed, 54 insertions(+), 79 deletions(-)
lib/Kconfig.debug +3 -2
@@ -1999,8 +1999,9 @@ config LKDTM Documentation/fault-injection/provoke-crashes.rst config TEST_LIST_SORT - tristate "Linked list sorting test" - depends on DEBUG_KERNEL || m + tristate "Linked list sorting test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS help Enable this to turn on 'list_sort()' function test. This test is executed only once during system boot (so affects only boot time),
lib/test_list_sort.c +51 -77
178 lines not on this page · raw message
Signature · 1 line
2.31.1.498.g6c1eba8ee3d-goog
Quoted 47 lines · Daniel Latypov
Functionally, this just means that the test output will be slightly changed and it'll now depend on
CONFIG_KUNIT=y/m.It'll still run at boot time and can still be built as a loadable module.
There was a pre-existing patch to convert this test that I found later, here [1]. Compared to [1], this patch doesn't rename files and uses KUnit features more heavily (i.e. does more than converting
pr_err()calls toKUNIT_FAIL()).What this conversion gives us:
* a shorter test thanks to KUnit's macros
* a way to run this a bit more easily viakunit.py(andCONFIG_KUNIT_ALL_TESTS=y) [2]
* a structured way of reporting pass/fail
* uses kunit-managed allocations to avoid the risk of memory leaks
* more descriptive error messages:
* i.e. it prints out which fields are invalid, what the expected values are, etc.What this conversion does not do:
* change the name of the file (and thus the name of the module)
* change the name of the config optionLeaving these as-is for now to minimize the impact to people wanting to run this test. IMO, that concern trumps following KUnit's style guide for both names, at least for now.
[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] Can be run via$ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF CONFIG_KUNIT=y CONFIG_TEST_LIST_SORT=y EOF[16:55:56] Configuring KUnit Kernel ...
[16:55:56] Building KUnit Kernel ...
[16:56:29] Starting KUnit Kernel ...
[16:56:32] ============================================================ [16:56:32] ======== [PASSED]list_sort========
[16:56:32] [PASSED]list_sort_test
[16:56:32] ============================================================ [16:56:32] Testing complete. 1 tests run. 0 failed. 0 crashed.
[16:56:32] Elapsed time: 35.668s total, 0.001s configuring, 32.725s building, 0.000s running
Quoted 4 lines
Note: the build time is as after a
make mrproper.Signed-off-by Daniel Latypov <[email protected]>---
This looks good to me: I'm not an expert in the test, though, so I may have missed something. I did run it, though, and it seemed to work fine.
It's a shame the functions can no-longer be marked __init, but I think the advantages of KUnit outweigh it, particularly since this is unlikely to be being used in production.
(BTW: This doesn't appear to be posted as a reply to Patch 1/2, which made it a bit trickier to find.)
This is
-- David
Quoted 47 lines · Daniel Latypov
Functionally, this just means that the test output will be slightly changed and it'll now depend on
CONFIG_KUNIT=y/m.It'll still run at boot time and can still be built as a loadable module.
There was a pre-existing patch to convert this test that I found later, here [1]. Compared to [1], this patch doesn't rename files and uses KUnit features more heavily (i.e. does more than converting
pr_err()calls toKUNIT_FAIL()).What this conversion gives us:
* a shorter test thanks to KUnit's macros
* a way to run this a bit more easily viakunit.py(andCONFIG_KUNIT_ALL_TESTS=y) [2]
* a structured way of reporting pass/fail
* uses kunit-managed allocations to avoid the risk of memory leaks
* more descriptive error messages:
* i.e. it prints out which fields are invalid, what the expected values are, etc.What this conversion does not do:
* change the name of the file (and thus the name of the module)
* change the name of the config optionLeaving these as-is for now to minimize the impact to people wanting to run this test. IMO, that concern trumps following KUnit's style guide for both names, at least for now.
[1] https://lore.kernel.org/linux-kselftest/[email protected]/
[2] Can be run via$ ./tools/testing/kunit/kunit.py run --kunitconfig /dev/stdin <<EOF CONFIG_KUNIT=y CONFIG_TEST_LIST_SORT=y EOF[16:55:56] Configuring KUnit Kernel ...
[16:55:56] Building KUnit Kernel ...
[16:56:29] Starting KUnit Kernel ...
[16:56:32] ============================================================ [16:56:32] ======== [PASSED]list_sort========
[16:56:32] [PASSED]list_sort_test
[16:56:32] ============================================================ [16:56:32] Testing complete. 1 tests run. 0 failed. 0 crashed.
[16:56:32] Elapsed time: 35.668s total, 0.001s configuring, 32.725s building, 0.000s running
Quoted 3 lines
Note: the build time is as after a
make mrproper.Signed-off-by Daniel Latypov <[email protected]>
Hi,
Can we change this to CONFIG_LIST_SORT_KUNIT_TEST to follow the convention used by other KUNIT tests?
Maintainers? thoughts? I recently posted patches to convert some of the other tests that break this format [1].
Cheers,
-- Nico
[1] - https://lkml.org/lkml/2021/4/14/310
Quoted 8 lines · Daniel Latypov
[SNIP...]
configTEST_LIST_SORTlib/Kconfig.debug +3
-2- tristate "Linked list sorting test" - depends on DEBUG_KERNEL || m + tristate "Linked list sorting test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS[SNAP...]
Quoted 4 lines · Nico Pache
Hi,
Can we change this to
CONFIG_LIST_SORT_KUNIT_TESTto follow the convention used by other KUNIT tests?
I mentioned this in the commit description briefly, but I don't know who is using this test. Nor do I really know who to ask.
So I didn't want to risk breaking anyone's workflow for now (more than now requiring them to set CONFIG_KUNIT=y/m).
Side note: maybe CONFIG_KUNIT can default to =y when DEBUG_KERNEL is set? Then there'd be even less change than how this worked before...
If it's not a concern, I'll happily update the file name and config option to follow the conventions.
Quoted 23 lines
Maintainers? thoughts? I recently posted patches to convert some of the other tests that break this format [1].
Cheers,
-- Nico
[1] - https://lkml.org/lkml/2021/4/14/310
Quoted 8 lines · Daniel Latypov
[SNIP...]
configTEST_LIST_SORTlib/Kconfig.debug +3
-2- tristate "Linked list sorting test" - depends on DEBUG_KERNEL || m + tristate "Linked list sorting test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS[SNAP...]
--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/d7b2b598-7087-0445-4647-8521f3238dc2%40redhat.com.
I've left the names as-is for now in v2,
https://lore.kernel.org/linux-kselftest/[email protected]
I could send a v3 w/ the rename and see if anyone complains, but I'm tempted to push that off.
Quoted 41 lines · Daniel Latypov
Quoted 4 lines · Nico Pache
Hi,
Can we change this to
CONFIG_LIST_SORT_KUNIT_TESTto follow the convention used by other KUNIT tests?I mentioned this in the commit description briefly, but I don't know who is using this test. Nor do I really know who to ask.
So I didn't want to risk breaking anyone's workflow for now (more than now requiring them to setCONFIG_KUNIT=y/m).Side note: maybe
CONFIG_KUNITcan default to =y whenDEBUG_KERNELis set? Then there'd be even less change than how this worked before...If it's not a concern, I'll happily update the file name and config option to follow the conventions.
Quoted 23 lines
Maintainers? thoughts? I recently posted patches to convert some of the other tests that break this format [1].
Cheers,
-- Nico
[1] - https://lkml.org/lkml/2021/4/14/310
Quoted 8 lines · Daniel Latypov
[SNIP...]
configTEST_LIST_SORTlib/Kconfig.debug +3
-2- tristate "Linked list sorting test" - depends on DEBUG_KERNEL || m + tristate "Linked list sorting test" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS[SNAP...]
--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/d7b2b598-7087-0445-4647-8521f3238dc2%40redhat.com.