Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-kunit-5.17-rc1' of git://git.kernel.org/pu…
Browse files Browse the repository at this point in the history
…b/scm/linux/kernel/git/shuah/linux-kselftest

Pull KUnit updates from Shuah Khan:
 "This consists of several fixes and enhancements. A few highlights:

   - Option --kconfig_add option allows easily tweaking kunitconfigs

   - make build subcommand can reconfigure if needed

   - doesn't error on tests without test plans

   - doesn't crash if no parameters are generated

   - defaults --jobs to # of cups

   - reports test parameter results as (K)TAP subtests"

* tag 'linux-kselftest-kunit-5.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  kunit: tool: Default --jobs to number of CPUs
  kunit: tool: fix newly introduced typechecker errors
  kunit: tool: make `build` subcommand also reconfigure if needed
  kunit: tool: delete kunit_parser.TestResult type
  kunit: tool: use dataclass instead of collections.namedtuple
  kunit: tool: suggest using decode_stacktrace.sh on kernel crash
  kunit: tool: reconfigure when the used kunitconfig changes
  kunit: tool: revamp message for invalid kunitconfig
  kunit: tool: add --kconfig_add to allow easily tweaking kunitconfigs
  kunit: tool: move Kconfig read_from_file/parse_from_string to package-level
  kunit: tool: print parsed test results fully incrementally
  kunit: Report test parameter results as (K)TAP subtests
  kunit: Don't crash if no parameters are generated
  kunit: tool: Report an error if any test has no subtests
  kunit: tool: Do not error on tests without test plans
  kunit: add run_checks.py script to validate kunit changes
  Documentation: kunit: remove claims that kunit is a mocking framework
  kunit: tool: fix --json output for skipped tests
  • Loading branch information
Linus Torvalds committed Jan 10, 2022
2 parents 4369b3c + ad659cc commit bf4eebf
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 204 deletions.
3 changes: 1 addition & 2 deletions Documentation/dev-tools/kunit/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ following sections:

Documentation/dev-tools/kunit/api/test.rst

- documents all of the standard testing API excluding mocking
or mocking related features.
- documents all of the standard testing API
3 changes: 1 addition & 2 deletions Documentation/dev-tools/kunit/api/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
Test API
========

This file documents all of the standard testing API excluding mocking or mocking
related features.
This file documents all of the standard testing API.

.. kernel-doc:: include/kunit/test.h
:internal:
2 changes: 1 addition & 1 deletion Documentation/dev-tools/kunit/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ KUnit - Unit Testing for the Linux Kernel
What is KUnit?
==============

KUnit is a lightweight unit testing and mocking framework for the Linux kernel.
KUnit is a lightweight unit testing framework for the Linux kernel.

KUnit is heavily inspired by JUnit, Python's unittest.mock, and
Googletest/Googlemock for C++. KUnit provides facilities for defining unit test
Expand Down
8 changes: 4 additions & 4 deletions Documentation/dev-tools/kunit/start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ It'll warn you if you haven't included the dependencies of the options you're
using.

.. note::
Note that removing something from the ``.kunitconfig`` will not trigger a
rebuild of the ``.config`` file: the configuration is only updated if the
``.kunitconfig`` is not a subset of ``.config``. This means that you can use
other tools (such as make menuconfig) to adjust other config options.
If you change the ``.kunitconfig``, kunit.py will trigger a rebuild of the
``.config`` file. But you can edit the ``.config`` file directly or with
tools like ``make menuconfig O=.kunit``. As long as its a superset of
``.kunitconfig``, kunit.py won't overwrite your changes.


Running the tests (KUnit Wrapper)
Expand Down
25 changes: 14 additions & 11 deletions lib/kunit/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,37 +504,40 @@ int kunit_run_tests(struct kunit_suite *suite)
struct kunit_result_stats param_stats = { 0 };
test_case->status = KUNIT_SKIPPED;

if (test_case->generate_params) {
if (!test_case->generate_params) {
/* Non-parameterised test. */
kunit_run_case_catch_errors(suite, test_case, &test);
kunit_update_stats(&param_stats, test.status);
} else {
/* Get initial param. */
param_desc[0] = '\0';
test.param_value = test_case->generate_params(NULL, param_desc);
}
kunit_log(KERN_INFO, &test, KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT
"# Subtest: %s", test_case->name);

do {
kunit_run_case_catch_errors(suite, test_case, &test);
while (test.param_value) {
kunit_run_case_catch_errors(suite, test_case, &test);

if (test_case->generate_params) {
if (param_desc[0] == '\0') {
snprintf(param_desc, sizeof(param_desc),
"param-%d", test.param_index);
}

kunit_log(KERN_INFO, &test,
KUNIT_SUBTEST_INDENT
"# %s: %s %d - %s",
test_case->name,
KUNIT_SUBTEST_INDENT KUNIT_SUBTEST_INDENT
"%s %d - %s",
kunit_status_to_ok_not_ok(test.status),
test.param_index + 1, param_desc);

/* Get next param. */
param_desc[0] = '\0';
test.param_value = test_case->generate_params(test.param_value, param_desc);
test.param_index++;
}

kunit_update_stats(&param_stats, test.status);
kunit_update_stats(&param_stats, test.status);
}
}

} while (test.param_value);

kunit_print_test_stats(&test, param_stats);

Expand Down
Loading

0 comments on commit bf4eebf

Please sign in to comment.