KUnit update for Linux 5.19-rc1
Subsystems (14)
Shuah Khan
maintainerHi Linus,
Please pull the following KUnit update for Linux 5.19-rc1.
This KUnit update for Linux 5.19-rc1 consists of several fixes, cleanups, and enhancements to tests and framework:
- introduces _NULL and _NOT_NULL macros to pointer error checks
- reworks kunit_resource allocation policy to fix memory leaks when caller doesn't specify free() function to be used when allocating memory using kunit_add_resource() and kunit_alloc_resource() funcs.
- adds ability to specify suite-level init and exit functions
diff is attached.
thanks,
-- Shuah
----------------------------------------------------------------
The following changes since commit 3123109284176b1532874591f7c81f3837bbdc17:
Linux 5.18-rc1 (2022-04-03 14:08:21 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest tags/linux-kselftest-kunit-5.19-rc1
for you to fetch changes up to e7eaffce47b7db72b077630dbe836f0c4132496d:
kunit: tool: Use qemu-system-i386 for i386 runs (2022-05-18 17:03:54 -0600)
----------------------------------------------------------------
linux-kselftest-kunit-5.19-rc1
This KUnit update for Linux 5.19-rc1 consists of several fixes, cleanups, and enhancements to tests and framework:
- introduces _NULL and _NOT_NULL macros to pointer error checks
- reworks kunit_resource allocation policy to fix memory leaks when caller doesn't specify free() function to be used when allocating memory using kunit_add_resource() and kunit_alloc_resource() funcs.
- adds ability to specify suite-level init and exit functions
----------------------------------------------------------------
Brendan Higgins (2):
kunit: add support for kunit_suites that reference init code
kunit: tool: update riscv QEMU config with new serial dependency
Daniel Latypov (25):
kunit: tool: make --json handling a bit clearer
kunit: tool: drop unused KernelDirectoryPath var
kunit: tool: drop last uses of collections.namedtuple
kunit: tool: simplify code since build_dir can't be None
kunit: tool: readability tweaks in KernelCI json generation logic
kunit: tool: refactor how we plumb metadata into JSON
kunit: tool: properly report the used arch for --json, or '' if not known
kunit: tool: more descriptive metavars/--help output
kunit: split resource API from test.h into new resource.h
kunit: split resource API impl from test.c into new resource.c
Documentation: kunit: update kconfig options needed for UML coverage
kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite)
kunit: add ability to specify suite-level init and exit functions
kfence: test: use new suite_{init/exit} support, add .kunitconfig
kunit: fix debugfs code to use enum kunit_status, not bool lib/Kconfig.debug: change KUnit tests to default to KUNIT_ALL_TESTS
kunit: bail out of test filtering logic quicker if OOM
kunit: tool: update test counts summary line format
kunit: tool: stop using a shell to run kernel under QEMU
kunit: tool: print clearer error message when there's no TAP output
kunit: tool: remove dead parse_crash_in_log() logic
kunit: tool: make parser stop overwriting status of suites w/ no_tests
kunit: tool: minor cosmetic cleanups in kunit_parser.py
kunit: tool: misc cleanups
kunit: fix executor OOM error handling logic on non-UML
David Gow (5):
list: test: Test the hlist structure
kunit: Make kunit_remove_resource() idempotent
kunit: Rework kunit_resource allocation policy
kunit: tool: Add list of all valid test configs on UML
kunit: tool: Use qemu-system-i386 for i386 runs
Kees Cook (1):
kunit: tool: Do not colorize output when redirected
Marco Elver (1):
kcsan: test: use new suite_{init,exit} support
Miguel Ojeda (1):
kunit: take kunit_assert as const
Ricardo Ribalda (6):
kunit: Introduce _NULL and _NOT_NULL macros
kunit: use NULL macros
thunderbolt: test: use NULL macros
kasan: test: Use NULL macros
mctp: test: Use NULL macros
apparmor: test: Use NULL macros
Documentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/resource.rst | 13 + Documentation/dev-tools/kunit/running_tips.rst | 3 +- Documentation/dev-tools/kunit/usage.rst | 19 +- drivers/thunderbolt/test.c | 134 +++---- include/kunit/resource.h | 406 ++++++++++++++++++++ include/kunit/test.h | 418 ++++++--------------- kernel/kcsan/kcsan_test.c | 31 +- lib/Kconfig.debug | 15 +- lib/kunit/Makefile | 1 + lib/kunit/debugfs.c | 2 +- lib/kunit/executor.c | 32 +- lib/kunit/executor_test.c | 4 +- lib/kunit/kunit-example-test.c | 16 + lib/kunit/kunit-test.c | 37 +- lib/kunit/resource.c | 79 ++++ lib/kunit/test.c | 145 ++----- lib/list-test.c | 397 ++++++++++++++++++- lib/test_kasan.c | 2 +- mm/kfence/.kunitconfig | 6 + mm/kfence/kfence_test.c | 31 +- net/mctp/test/route-test.c | 4 +- security/apparmor/policy_unpack_test.c | 6 +- tools/testing/kunit/configs/all_tests_uml.config | 37 ++ tools/testing/kunit/kunit.py | 63 ++-- tools/testing/kunit/kunit_config.py | 21 +- tools/testing/kunit/kunit_json.py | 66 ++-- tools/testing/kunit/kunit_kernel.py | 81 ++-- tools/testing/kunit/kunit_parser.py | 154 +++----- tools/testing/kunit/kunit_tool_test.py | 44 +-- tools/testing/kunit/qemu_config.py | 17 +- tools/testing/kunit/qemu_configs/alpha.py | 2 +- tools/testing/kunit/qemu_configs/arm.py | 2 +- tools/testing/kunit/qemu_configs/arm64.py | 2 +- tools/testing/kunit/qemu_configs/i386.py | 4 +- tools/testing/kunit/qemu_configs/powerpc.py | 2 +- tools/testing/kunit/qemu_configs/riscv.py | 7 +- tools/testing/kunit/qemu_configs/s390.py | 4 +- tools/testing/kunit/qemu_configs/sparc.py | 2 +- tools/testing/kunit/qemu_configs/x86_64.py | 2 +- tools/testing/kunit/run_checks.py | 2 +- .../kunit/test_data/test_is_test_passed-crash.log | 70 ---- .../test_is_test_passed-no_tests_no_plan.log | 2 +- 43 files changed, 1499 insertions(+), 891 deletions(-) create mode 100644 Documentation/dev-tools/kunit/api/resource.rst create mode 100644 include/kunit/resource.h create mode 100644 lib/kunit/resource.c create mode 100644 mm/kfence/.kunitconfig create mode 100644 tools/testing/kunit/configs/all_tests_uml.config delete mode 100644 tools/testing/kunit/test_data/test_is_test_passed-crash.log
----------------------------------------------------------------
Documentation/dev-tools/kunit/api/index.rst +5 -0
@@ -6,6 +6,7 @@ API Reference .. toctree:: test + resource This section documents the KUnit kernel testing API. It is divided into the following sections:
@@ -13,3 +14,7 @@ following sections: Documentation/dev-tools/kunit/api/test.rst - documents all of the standard testing API + +Documentation/dev-tools/kunit/api/resource.rst + + - documents the KUnit resource API
Documentation/dev-tools/kunit/api/resource.rst new file +13 -0
@@ -0,0 +1,13 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============ +Resource API +============ + +This file documents the KUnit resource API. + +Most users won't need to use this API directly, power users can use it to store +state on a per-test basis, register custom cleanup actions, and more. + +.. kernel-doc:: include/kunit/resource.h + :internal:
Documentation/dev-tools/kunit/running_tips.rst +2 -1
@@ -114,6 +114,7 @@ Instead of enabling ``CONFIG_GCOV_KERNEL=y``, we can set these options: CONFIG_DEBUG_KERNEL=y CONFIG_DEBUG_INFO=y + CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y CONFIG_GCOV=y
@@ -122,7 +123,7 @@ Putting it together into a copy-pastable sequence of commands: .. code-block:: bash # Append coverage options to the current config - $ echo -e "CONFIG_DEBUG_KERNEL=y\nCONFIG_DEBUG_INFO=y\nCONFIG_GCOV=y" >> .kunit/.kunitconfig + $ echo -e "CONFIG_DEBUG_KERNEL=y\nCONFIG_DEBUG_INFO=y\nCONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=y\nCONFIG_GCOV=y" >> .kunit/.kunitconfig $ ./tools/testing/kunit/kunit.py run # Extract the coverage information from the build dir (.kunit/) $ lcov -t "my_kunit_tests" -o coverage.info -c -d .kunit/
Documentation/dev-tools/kunit/usage.rst +11 -8
@@ -125,8 +125,8 @@ We need many test cases covering all the unit's behaviors. It is common to have many similar tests. In order to reduce duplication in these closely related tests, most unit testing frameworks (including KUnit) provide the concept of a *test suite*. A test suite is a collection of test cases for a unit of code -with a setup function that gets invoked before every test case and then a tear -down function that gets invoked after every test case completes. For example: +with optional setup and teardown functions that run before/after the whole +suite and/or every test case. For example: .. code-block:: c
@@ -141,16 +141,19 @@ down function that gets invoked after every test case completes. For example: .name = "example", .init = example_test_init, .exit = example_test_exit, + .suite_init = example_suite_init, + .suite_exit = example_suite_exit, .test_cases = example_test_cases, }; kunit_test_suite(example_test_suite); -In the above example, the test suite ``example_test_suite`` would run the test -cases ``example_test_foo``, ``example_test_bar``, and ``example_test_baz``. Each -would have ``example_test_init`` called immediately before it and -``example_test_exit`` called immediately after it. -``kunit_test_suite(example_test_suite)`` registers the test suite with the -KUnit test framework. +In the above example, the test suite ``example_test_suite`` would first run +``example_suite_init``, then run the test cases ``example_test_foo``, +``example_test_bar``, and ``example_test_baz``. Each would have +``example_test_init`` called immediately before it and ``example_test_exit`` +called immediately after it. Finally, ``example_suite_exit`` would be called +after everything else. ``kunit_test_suite(example_test_suite)`` registers the +test suite with the KUnit test framework. .. note:: A test case will only run if it is associated with a test suite.
drivers/thunderbolt/test.c +67 -67
464 lines not on this page · raw message
include/kunit/resource.h new file +406 -0
406 lines not on this page · raw message
include/kunit/test.h +120 -298
476 lines not on this page · raw message
kernel/kcsan/kcsan_test.c +13 -18
@@ -1565,14 +1565,6 @@ static void test_exit(struct kunit *test)torture_cleanup_end (); } -static struct kunit_suite kcsan_test_suite = { - .name ="kcsan" , - .test_cases = kcsan_test_cases, - .init = test_init, - .exit = test_exit, -}; -static struct kunit_suite *kcsan_test_suites[] = { &kcsan_test_suite,NULL }; -__no_kcsan static void register_tracepoints(struct tracepoint *tp, void *ignore) {
@@ -1588,11 +1580,7 @@ static void unregister_tracepoints(struct tracepoint *tp, void *ignore)tracepoint_probe_unregister (tp, probe_console,NULL ); } -/* -* We only want to do tracepoints setup and teardown once, therefore we have to -* customize the init and exit functions and cannot rely on kunit_test_suite(). -*/ -static int __init kcsan_test_init (void ) +static int kcsan_suite_init (struct kunit_suite *suite) {/* * Because we want to be able to build the test as a module, we need to
@@ -1600,18 +1588,25 @@ static int __init kcsan_test_init(void)* won't work here. */ for_each_kernel_tracepoint (register_tracepoints,NULL ); -return __kunit_test_suites_init (kcsan_test_suites); +return 0 ; } -static void kcsan_test_exit (void ) +static void kcsan_suite_exit (struct kunit_suite *suite) { -__kunit_test_suites_exit (kcsan_test_suites);for_each_kernel_tracepoint (unregister_tracepoints,NULL );tracepoint_synchronize_unregister (); } -late_initcall_sync (kcsan_test_init); -module_exit (kcsan_test_exit); +static struct kunit_suite kcsan_test_suite = { + .name ="kcsan" , + .test_cases = kcsan_test_cases, + .init = test_init, + .exit = test_exit, + .suite_init = kcsan_suite_init, + .suite_exit = kcsan_suite_exit, +}; + +kunit_test_suites (&kcsan_test_suite);MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Marco Elver <[email protected]>" );
lib/Kconfig.debug +10 -5
@@ -2140,10 +2140,11 @@ config TEST_DIV64 If unsure, say N. config KPROBES_SANITY_TEST - tristate "Kprobes sanity tests" + tristate "Kprobes sanity tests" if !KUNIT_ALL_TESTS depends on DEBUG_KERNEL depends on KPROBES depends on KUNIT + default KUNIT_ALL_TESTS help This option provides for testing basic kprobes functionality on boot. Samples of kprobe and kretprobe are inserted and
@@ -2417,8 +2418,9 @@ config TEST_SYSCTL If unsure, say N. config BITFIELD_KUNIT - tristate "KUnit test bitfield functions at runtime" + tristate "KUnit test bitfield functions at runtime" if !KUNIT_ALL_TESTS depends on KUNIT + default KUNIT_ALL_TESTS help Enable this option to test the bitfield functions at boot.
@@ -2452,8 +2454,9 @@ config HASH_KUNIT_TEST optimized versions. If unsure, say N. config RESOURCE_KUNIT_TEST - tristate "KUnit test for resource API" + tristate "KUnit test for resource API" if !KUNIT_ALL_TESTS depends on KUNIT + default KUNIT_ALL_TESTS help This builds the resource API unit test. Tests the logic of API provided by resource.c and ioport.h.
@@ -2506,8 +2509,9 @@ config LINEAR_RANGES_TEST If unsure, say N. config CMDLINE_KUNIT_TEST - tristate "KUnit test for cmdline API" + tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS depends on KUNIT + default KUNIT_ALL_TESTS help This builds the cmdline API unit test. Tests the logic of API provided by cmdline.c.
@@ -2517,8 +2521,9 @@ config CMDLINE_KUNIT_TEST If unsure, say N. config BITS_TEST - tristate "KUnit test for bits.h" + tristate "KUnit test for bits.h" if !KUNIT_ALL_TESTS depends on KUNIT + default KUNIT_ALL_TESTS help This builds the bits unit test. Tests the logic of macros defined in bits.h.
lib/kunit/Makefile +1 -0
@@ -1,6 +1,7 @@ obj-$(CONFIG_KUNIT) += kunit.o kunit-objs += test.o \ + resource.o \ string-stream.o \ assert.o \ try-catch.o \
lib/kunit/debugfs.c +1 -1
@@ -52,7 +52,7 @@ static void debugfs_print_result(struct seq_file *seq,static int debugfs_print_results (struct seq_file *seq,void *v) {struct kunit_suite *suite = (struct kunit_suite *)seq->private; -bool success =kunit_suite_has_succeeded (suite); +enum kunit_status success =kunit_suite_has_succeeded (suite);struct kunit_case *test_case;if (!suite || !suite->log)
lib/kunit/executor.c +25 -7
@@ -71,9 +71,13 @@ kunit_filter_tests(struct kunit_suite *const suite, const char *test_glob)/* Use memcpy to workaround copy->name being const. */ copy =kmalloc (sizeof (*copy),GFP_KERNEL ); +if (!copy) +return ERR_PTR (-ENOMEM );memcpy (copy, suite,sizeof (*copy)); filtered =kcalloc (n +1 ,sizeof (*filtered),GFP_KERNEL ); +if (!filtered) +return ERR_PTR (-ENOMEM ); n =0 ;kunit_suite_for_each_test_case (suite, test_case) {
@@ -106,14 +110,16 @@ kunit_filter_subsuite(struct kunit_suite * const * const subsuite, filtered =kmalloc_array (n +1 ,sizeof (*filtered),GFP_KERNEL );if (!filtered) -return NULL ; +return ERR_PTR (-ENOMEM ); n =0 ;for (i =0 ; subsuite[i] !=NULL ; ++i) {if (!glob_match (filter->suite_glob, subsuite[i]->name))continue ; filtered_suite =kunit_filter_tests (subsuite[i], filter->test_glob); -if (filtered_suite) +if (IS_ERR (filtered_suite)) +return ERR_CAST (filtered_suite); +else if (filtered_suite) filtered[n++] = filtered_suite; } filtered[n] =NULL ;
@@ -146,7 +152,8 @@ static void kunit_free_suite_set(struct suite_set suite_set) }static struct suite_set kunit_filter_suites (const struct suite_set *suite_set, -const char *filter_glob) +const char *filter_glob, +int *err) {int i;struct kunit_suite *const **copy, *const *filtered_subsuite;
@@ -166,6 +173,10 @@ static struct suite_set kunit_filter_suites(const struct suite_set *suite_set,for (i =0 ; i < max; ++i) { filtered_subsuite =kunit_filter_subsuite (suite_set->start[i], &filter); +if (IS_ERR (filtered_subsuite)) { + *err =PTR_ERR (filtered_subsuite); +return filtered; + }if (filtered_subsuite) *copy++ = filtered_subsuite; }
@@ -236,9 +247,15 @@ int kunit_run_all_tests(void) .start = __kunit_suites_start, .end = __kunit_suites_end, }; +int err =0 ; -if (filter_glob_param) - suite_set =kunit_filter_suites (&suite_set, filter_glob_param); +if (filter_glob_param) { + suite_set =kunit_filter_suites (&suite_set, filter_glob_param, &err); +if (err) { +pr_err ("kunit executor: error filtering suites: %d\n" , err); + goto out; + } + }if (!action_param)kunit_exec_run_tests (&suite_set);
@@ -251,9 +268,10 @@ int kunit_run_all_tests(void)kunit_free_suite_set (suite_set); } -kunit_handle_shutdown (); -return 0 ; +out: +kunit_handle_shutdown (); +return err; }#if IS_BUILTIN (CONFIG_KUNIT_TEST )
lib/kunit/executor_test.c +3 -1
@@ -137,14 +137,16 @@ static void filter_suites_test(struct kunit *test) .end = suites + 2, };struct suite_set filtered = {.start =NULL , .end =NULL }; +int err =0 ;/* Emulate two files, each having one suite */ subsuites[0 ][0 ] =alloc_fake_suite (test,"suite0" , dummy_test_cases); subsuites[1 ][0 ] =alloc_fake_suite (test,"suite1" , dummy_test_cases);/* Filter out suite1 */ - filtered =kunit_filter_suites (&suite_set,"suite0" ); + filtered =kunit_filter_suites (&suite_set,"suite0" , &err);kfree_subsuites_at_end (test, &filtered);/* let us use ASSERTs without leaking */ +KUNIT_EXPECT_EQ (test, err,0 );KUNIT_ASSERT_EQ (test, filtered.end - filtered.start, (ptrdiff_t )1 );KUNIT_ASSERT_NOT_ERR_OR_NULL (test, filtered.start);
lib/kunit/kunit-example-test.c +16 -0
@@ -40,6 +40,17 @@ static int example_test_init(struct kunit *test)return 0 ; } +/* +* This is run once before all test cases in the suite. +* See the comment on example_test_suite for more information. +*/ +static int example_test_init_suite (struct kunit_suite *suite) +{ +kunit_info (suite,"initializing suite\n" ); + +return 0 ; +} +/* * This test should always be skipped. */
@@ -91,6 +102,8 @@ static void example_all_expect_macros_test(struct kunit *test)KUNIT_EXPECT_NOT_ERR_OR_NULL (test, test);KUNIT_EXPECT_PTR_EQ (test,NULL ,NULL );KUNIT_EXPECT_PTR_NE (test, test,NULL ); +KUNIT_EXPECT_NULL (test,NULL ); +KUNIT_EXPECT_NOT_NULL (test, test);/* String assertions */ KUNIT_EXPECT_STREQ (test,"hi" ,"hi" );
@@ -140,17 +153,20 @@ static struct kunit_case example_test_cases[] = {* may be specified which runs after every test case and can be used to for * cleanup. For clarity, running tests in a test suite would behave as follows: * +* suite.suite_init(suite); * suite.init(test); * suite.test_case[0](test); * suite.exit(test); * suite.init(test); * suite.test_case[1](test); * suite.exit(test); +* suite.suite_exit(suite); * ...; */ static struct kunit_suite example_test_suite = { .name ="example" , .init = example_test_init, + .suite_init = example_test_init_suite, .test_cases = example_test_cases, };
lib/kunit/kunit-test.c +36 -1
@@ -190,6 +190,40 @@ static void kunit_resource_test_destroy_resource(struct kunit *test)KUNIT_EXPECT_TRUE (test,list_empty (&ctx->test.resources)); } +static void kunit_resource_test_remove_resource (struct kunit *test) +{ +struct kunit_test_resource_context *ctx = test->priv; +struct kunit_resource *res =kunit_alloc_and_get_resource ( + &ctx->test, + fake_resource_init, + fake_resource_free, +GFP_KERNEL , + ctx); + +/* The resource is in the list */ +KUNIT_EXPECT_FALSE (test,list_empty (&ctx->test.resources)); + +/* Remove the resource. The pointer is still valid, but it can't be +* found. +*/ +kunit_remove_resource (test, res); +KUNIT_EXPECT_TRUE (test,list_empty (&ctx->test.resources)); +/* We haven't been freed yet. */ +KUNIT_EXPECT_TRUE (test, ctx->is_resource_initialized); + +/* Removing the resource multiple times is valid. */ +kunit_remove_resource (test, res); +KUNIT_EXPECT_TRUE (test,list_empty (&ctx->test.resources)); +/* Despite having been removed twice (from only one reference), the +* resource still has not been freed. +*/ +KUNIT_EXPECT_TRUE (test, ctx->is_resource_initialized); + +/* Free the resource. */ +kunit_put_resource (res); +KUNIT_EXPECT_FALSE (test, ctx->is_resource_initialized); +} +static void kunit_resource_test_cleanup_resources (struct kunit *test) {int i;
@@ -387,6 +421,7 @@ static struct kunit_case kunit_resource_test_cases[] = {KUNIT_CASE (kunit_resource_test_init_resources),KUNIT_CASE (kunit_resource_test_alloc_resource),KUNIT_CASE (kunit_resource_test_destroy_resource), +KUNIT_CASE (kunit_resource_test_remove_resource),KUNIT_CASE (kunit_resource_test_cleanup_resources),KUNIT_CASE (kunit_resource_test_proper_free_ordering), KUNIT_CASE(kunit_resource_test_static),
@@ -435,7 +470,7 @@ static void kunit_log_test(struct kunit *test)KUNIT_EXPECT_NOT_ERR_OR_NULL (test,strstr (suite.log,"along with this." ));#else -KUNIT_EXPECT_PTR_EQ (test, test->log, (char *)NULL ); +KUNIT_EXPECT_NULL (test, test->log);#endif }
lib/kunit/resource.c new file +79 -0
79 lines not on this page · raw message
lib/kunit/test.c +24 -121
209 lines not on this page · raw message
lib/list-test.c +396 -1
402 lines not on this page · raw message
lib/test_kasan.c +1 -1
@@ -391,7 +391,7 @@ static void krealloc_uaf(struct kunit *test)kfree (ptr1);KUNIT_EXPECT_KASAN_FAIL (test, ptr2 =krealloc (ptr1, size2,GFP_KERNEL )); -KUNIT_ASSERT_PTR_EQ (test, (void *)ptr2,NULL ); +KUNIT_ASSERT_NULL (test, ptr2);KUNIT_EXPECT_KASAN_FAIL (test, *(volatile char *)ptr1); }
mm/kfence/.kunitconfig new file +6 -0
@@ -0,0 +1,6 @@ +CONFIG_KUNIT=y +CONFIG_KFENCE=y +CONFIG_KFENCE_KUNIT_TEST=y + +# Additional dependencies. +CONFIG_FTRACE=y
mm/kfence/kfence_test.c +13 -18
@@ -826,14 +826,6 @@ static void test_exit(struct kunit *test)test_cache_destroy (); } -static struct kunit_suite kfence_test_suite = { - .name ="kfence" , - .test_cases = kfence_test_cases, - .init = test_init, - .exit = test_exit, -}; -static struct kunit_suite *kfence_test_suites[] = { &kfence_test_suite,NULL }; -static void register_tracepoints (struct tracepoint *tp,void *ignore) {check_trace_callback_type_console (probe_console);
@@ -847,11 +839,7 @@ static void unregister_tracepoints(struct tracepoint *tp, void *ignore)tracepoint_probe_unregister (tp, probe_console,NULL ); } -/* -* We only want to do tracepoints setup and teardown once, therefore we have to -* customize the init and exit functions and cannot rely on kunit_test_suite(). -*/ -static int __init kfence_test_init (void ) +static int kfence_suite_init (struct kunit_suite *suite) {/* * Because we want to be able to build the test as a module, we need to
@@ -859,18 +847,25 @@ static int __init kfence_test_init(void)* won't work here. */ for_each_kernel_tracepoint (register_tracepoints,NULL ); -return __kunit_test_suites_init (kfence_test_suites); +return 0 ; } -static void kfence_test_exit (void ) +static void kfence_suite_exit (struct kunit_suite *suite) { -__kunit_test_suites_exit (kfence_test_suites);for_each_kernel_tracepoint (unregister_tracepoints,NULL );tracepoint_synchronize_unregister (); } -late_initcall_sync (kfence_test_init); -module_exit (kfence_test_exit); +static struct kunit_suite kfence_test_suite = { + .name ="kfence" , + .test_cases = kfence_test_cases, + .init = test_init, + .exit = test_exit, + .suite_init = kfence_suite_init, + .suite_exit = kfence_suite_exit, +}; + +kunit_test_suites (&kfence_test_suite);MODULE_LICENSE ("GPL v2" );MODULE_AUTHOR ("Alexander Potapenko <[email protected]>, Marco Elver <[email protected]>" );
net/mctp/test/route-test.c +2 -2
@@ -361,7 +361,7 @@ static void mctp_test_route_input_sk(struct kunit *test) }else {KUNIT_EXPECT_NE (test, rc,0 ); skb2 =skb_recv_datagram (sock->sk,0 ,1 , &rc); -KUNIT_EXPECT_PTR_EQ (test, skb2,NULL ); +KUNIT_EXPECT_NULL (test, skb2); }__mctp_route_test_fini (test, dev, rt, sock);
@@ -431,7 +431,7 @@ static void mctp_test_route_input_sk_reasm(struct kunit *test)skb_free_datagram (sock->sk, skb2); }else { -KUNIT_EXPECT_PTR_EQ (test, skb2,NULL ); +KUNIT_EXPECT_NULL (test, skb2); }__mctp_route_test_fini (test, dev, rt, sock);
security/apparmor/policy_unpack_test.c +3 -3
@@ -313,7 +313,7 @@ static void policy_unpack_test_unpack_strdup_out_of_bounds(struct kunit *test) size =unpack_strdup (puf->e, &string,TEST_STRING_NAME );KUNIT_EXPECT_EQ (test, size,0 ); -KUNIT_EXPECT_PTR_EQ (test, string, (char *)NULL ); +KUNIT_EXPECT_NULL (test, string);KUNIT_EXPECT_PTR_EQ (test, puf->e->pos, start); }
@@ -409,7 +409,7 @@ static void policy_unpack_test_unpack_u16_chunk_out_of_bounds_1( size =unpack_u16_chunk (puf->e, &chunk);KUNIT_EXPECT_EQ (test, size, (size_t )0 ); -KUNIT_EXPECT_PTR_EQ (test, chunk, (char *)NULL ); +KUNIT_EXPECT_NULL (test, chunk);KUNIT_EXPECT_PTR_EQ (test, puf->e->pos, puf->e->end -1 ); }
@@ -431,7 +431,7 @@ static void policy_unpack_test_unpack_u16_chunk_out_of_bounds_2( size =unpack_u16_chunk (puf->e, &chunk);KUNIT_EXPECT_EQ (test, size, (size_t )0 ); -KUNIT_EXPECT_PTR_EQ (test, chunk, (char *)NULL ); +KUNIT_EXPECT_NULL (test, chunk);KUNIT_EXPECT_PTR_EQ (test, puf->e->pos, puf->e->start +TEST_U16_OFFSET ); }
tools/testing/kunit/configs/all_tests_uml.config new file +37 -0
@@ -0,0 +1,37 @@ +# This config enables as many tests as possible under UML. +# It is intended for use in continuous integration systems and similar for +# automated testing of as much as possible. +# The config is manually maintained, though it uses KUNIT_ALL_TESTS=y to enable +# any tests whose dependencies are already satisfied. Please feel free to add +# more options if they any new tests. + +CONFIG_KUNIT=y +CONFIG_KUNIT_EXAMPLE_TEST=y +CONFIG_KUNIT_ALL_TESTS=y + +CONFIG_IIO=y + +CONFIG_EXT4_FS=y + +CONFIG_MSDOS_FS=y +CONFIG_VFAT_FS=y + +CONFIG_VIRTIO_UML=y +CONFIG_UML_PCI_OVER_VIRTIO=y +CONFIG_PCI=y +CONFIG_USB4=y + +CONFIG_NET=y +CONFIG_MCTP=y + +CONFIG_INET=y +CONFIG_MPTCP=y + +CONFIG_DAMON=y +CONFIG_DAMON_VADDR=y +CONFIG_DAMON_PADDR=y +CONFIG_DEBUG_FS=y +CONFIG_DAMON_DBGFS=y + +CONFIG_SECURITY=y +CONFIG_SECURITY_APPARMOR=y
tools/testing/kunit/kunit.py +32 -31
195 lines not on this page · raw message
tools/testing/kunit/kunit_config.py +10 -11
@@ -6,29 +6,29 @@ # Author: Felix Guo <[email protected]> # Author: Brendan Higgins <[email protected]> -import collections +from dataclasses import dataclass import re from typing import List, Set CONFIG_IS_NOT_SET_PATTERN = r'^# CONFIG_(\w+) is not set$' CONFIG_PATTERN = r'^CONFIG_(\w+)=(\S+|".*")$' -KconfigEntryBase = collections.namedtuple('KconfigEntryBase', ['name', 'value']) - -class KconfigEntry(KconfigEntryBase): +@dataclass(frozen=True) +class KconfigEntry: + name: str + value: str def __str__(self) -> str: if self.value == 'n': - return r'# CONFIG_%s is not set' % (self.name) - else: - return r'CONFIG_%s=%s' % (self.name, self.value) + return f'# CONFIG_{self.name} is not set' + return f'CONFIG_{self.name}={self.value}' class KconfigParseError(Exception): """Error parsing Kconfig defconfig or .config.""" -class Kconfig(object): +class Kconfig: """Represents defconfig or .config specified using the Kconfig language.""" def __init__(self) -> None:
@@ -48,7 +48,7 @@ class Kconfig(object): if a.value == 'n': continue return False - elif a.value != b: + if a.value != b: return False return True
@@ -90,6 +90,5 @@ def parse_from_string(blob: str) -> Kconfig: if line[0] == '#': continue - else: - raise KconfigParseError('Failed to parse: ' + line) + raise KconfigParseError('Failed to parse: ' + line) return kconfig
tools/testing/kunit/kunit_json.py +32 -34
92 lines not on this page · raw message
tools/testing/kunit/kunit_kernel.py +37 -44
82 lines not on this page · raw message
tools/testing/kunit/kunit_parser.py +52 -102
154 lines not on this page · raw message
tools/testing/kunit/kunit_tool_test.py +20 -24
44 lines not on this page · raw message
tools/testing/kunit/qemu_configs/alpha.py +1 -1
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/arm.py +1 -1
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/arm64.py +1 -1
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/i386.py +2 -2
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/powerpc.py +1 -1
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/riscv.py +4 -3
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/s390.py +2 -2
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/sparc.py +1 -1
Lines of this file are not shown. View the raw message.
tools/testing/kunit/qemu_configs/x86_64.py +1 -1
Lines of this file are not shown. View the raw message.
tools/testing/kunit/test_data/test_is_test_passed-crash.log deleted +0 -70
70 lines not on this page · raw message
tools/testing/kunit/test_data/test_is_test_passed-no_tests_no_plan.log +1 -1
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Shuah Khan
maintainerQuoted 13 lines · Shuah Khan
Hi Linus,
Please pull the following KUnit update for Linux 5.19-rc1.
This KUnit update for Linux 5.19-rc1 consists of several fixes, cleanups, and enhancements to tests and framework:
- introduces
_NULLand_NOT_NULLmacros to pointer error checks- reworks
kunit_resourceallocation policy to fix memory leaks when caller doesn't specifyfree()function to be used when allocating memory usingkunit_add_resource()andkunit_alloc_resource()funcs.
Quoted 7 lines
- adds ability to specify suite-level init and exit functions
diff is attached.
thanks,
-- Shuah
This bounced from linux-kselftest list as the diff exceeded the message size. Sorry for the noise for others that are seeing this twice (minus the diff).
FYI that the following KUnit pull request has been sent for Linux 5.19-rc1
thanks,
-- Shuah
Quoted 135 lines
----------------------------------------------------------------
The following changes since commit3123109284176b1532874591f7c81f3837bbdc17:Linux 5.18-rc1 (2022-04-03 14:08:21 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftesttags/linux-kselftest-kunit-5.19-rc1for you to fetch changes up to
e7eaffce47b7db72b077630dbe836f0c4132496d:kunit: tool: Use qemu-system-i386 for i386 runs (2022-05-18 17:03:54 -0600)
----------------------------------------------------------------
linux-kselftest-kunit-5.19-rc1This KUnit update for Linux 5.19-rc1 consists of several fixes, cleanups, and enhancements to tests and framework:
- introduces
_NULLand_NOT_NULLmacros to pointer error checks- reworks
kunit_resourceallocation policy to fix memory leaks when caller doesn't specifyfree()function to be used when allocating memory usingkunit_add_resource()andkunit_alloc_resource()funcs.- adds ability to specify suite-level init and exit functions
----------------------------------------------------------------
Brendan Higgins (2):
kunit: add support forkunit_suitesthat reference init code
kunit: tool: update riscv QEMU config with new serial dependencyDaniel Latypov (25):
kunit: tool: make --json handling a bit clearer
kunit: tool: drop unused KernelDirectoryPath var
kunit: tool: drop last uses of collections.namedtuple
kunit: tool: simplify code sincebuild_dircan't be None
kunit: tool: readability tweaks in KernelCI json generation logic
kunit: tool: refactor how we plumb metadata into JSON
kunit: tool: properly report the used arch for --json, or '' if not known
kunit: tool: more descriptive metavars/--help output
kunit: split resource API fromtest.hinto newresource.h
kunit: split resource API impl fromtest.cinto newresource.c
Documentation: kunit: update kconfig options needed for UML coverage
kunit: rename print_subtest_{start,end} for clarity (s/subtest/suite)
kunit: add ability to specify suite-level init and exit functions
kfence: test: use new suite_{init/exit} support, add .kunitconfig
kunit: fix debugfs code to use enumkunit_status, not boollib/Kconfig.debug: change KUnit tests to default toKUNIT_ALL_TESTS
kunit: bail out of test filtering logic quicker if OOM
kunit: tool: update test counts summary line format
kunit: tool: stop using a shell to run kernel under QEMU
kunit: tool: print clearer error message when there's no TAP output
kunit: tool: remove deadparse_crash_in_log()logic
kunit: tool: make parser stop overwriting status of suites w/no_tests
kunit: tool: minor cosmetic cleanups inkunit_parser.py
kunit: tool: misc cleanups
kunit: fix executor OOM error handling logic on non-UMLDavid Gow (5):
list: test: Test the hlist structure
kunit: Makekunit_remove_resource()idempotent
kunit: Reworkkunit_resourceallocation policy
kunit: tool: Add list of all valid test configs on UML
kunit: tool: Use qemu-system-i386 for i386 runsKees Cook (1):
kunit: tool: Do not colorize output when redirectedMarco Elver (1):
kcsan: test: use new suite_{init,exit} supportMiguel Ojeda (1):
kunit: takekunit_assertasconstRicardo Ribalda (6):
kunit: Introduce_NULLand_NOT_NULLmacros
kunit: use NULL macros
thunderbolt: test: use NULL macros
kasan: test: Use NULL macros
mctp: test: Use NULL macros
apparmor: test: Use NULL macrosDocumentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/resource.rst | 13 + Documentation/dev-tools/kunit/running_tips.rst | 3 +- Documentation/dev-tools/kunit/usage.rst | 19 +- drivers/thunderbolt/test.c | 134 +++---- include/kunit/resource.h | 406 ++++++++++++++++++++ include/kunit/test.h | 418 ++++++--------------- kernel/kcsan/kcsan_test.c | 31 +- lib/Kconfig.debug | 15 +- lib/kunit/Makefile | 1 + lib/kunit/debugfs.c | 2 +- lib/kunit/executor.c | 32 +- lib/kunit/executor_test.c | 4 +- lib/kunit/kunit-example-test.c | 16 + lib/kunit/kunit-test.c | 37 +- lib/kunit/resource.c | 79 ++++ lib/kunit/test.c | 145 ++----- lib/list-test.c | 397 ++++++++++++++++++- lib/test_kasan.c | 2 +- mm/kfence/.kunitconfig | 6 + mm/kfence/kfence_test.c | 31 +- net/mctp/test/route-test.c | 4 +- security/apparmor/policy_unpack_test.c | 6 +- tools/testing/kunit/configs/all_tests_uml.config | 37 ++ tools/testing/kunit/kunit.py | 63 ++-- tools/testing/kunit/kunit_config.py | 21 +- tools/testing/kunit/kunit_json.py | 66 ++-- tools/testing/kunit/kunit_kernel.py | 81 ++-- tools/testing/kunit/kunit_parser.py | 154 +++----- tools/testing/kunit/kunit_tool_test.py | 44 +-- tools/testing/kunit/qemu_config.py | 17 +- tools/testing/kunit/qemu_configs/alpha.py | 2 +- tools/testing/kunit/qemu_configs/arm.py | 2 +- tools/testing/kunit/qemu_configs/arm64.py | 2 +- tools/testing/kunit/qemu_configs/i386.py | 4 +- tools/testing/kunit/qemu_configs/powerpc.py | 2 +- tools/testing/kunit/qemu_configs/riscv.py | 7 +- tools/testing/kunit/qemu_configs/s390.py | 4 +- tools/testing/kunit/qemu_configs/sparc.py | 2 +- tools/testing/kunit/qemu_configs/x86_64.py | 2 +- tools/testing/kunit/run_checks.py | 2 +- .../kunit/test_data/test_is_test_passed-crash.log | 70 ---- .../test_is_test_passed-no_tests_no_plan.log | 2 +- 43 files changed, 1499 insertions(+), 891 deletions(-)create mode 100644
Documentation/dev-tools/kunit/api/resource.rstcreate mode 100644include/kunit/resource.h
create mode 100644lib/kunit/resource.c
create mode 100644mm/kfence/.kunitconfig
create mode 100644tools/testing/kunit/configs/all_tests_uml.configdelete mode 100644tools/testing/kunit/test_data/test_is_test_passed-crash.log
----------------------------------------------------------------
The pull request you sent on Mon, 23 May 2022 12:21:27 -0600:
The pull request you sent on Mon, 23 May 2022 12:21:27 -0600:
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftesttags/linux-kselftest-kunit-5.19-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/64e34b50d7aeee7082287ec39f9d34d4e60f3a04
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html