1d71307a | 20-Apr-2021 |
Daniel Latypov <dlatypov@google.com> |
kunit: add unit test for filtering suites by names
This adds unit tests for kunit_filter_subsuite() and kunit_filter_suites().
Note: what the executor means by "subsuite" is the array of suites cor
kunit: add unit test for filtering suites by names
This adds unit tests for kunit_filter_subsuite() and kunit_filter_suites().
Note: what the executor means by "subsuite" is the array of suites corresponding to each test file.
This patch lightly refactors executor.c to avoid the use of global variables to make it testable. It also includes a clever `kfree_at_end()` helper that makes this test easier to write than it otherwise would have been.
Tested by running just the new tests using itself $ ./tools/testing/kunit/kunit.py run '*exec*'
Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Acked-by: Brendan Higgins <brendanhiggins@google.com> Tested-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
d99ea675 | 25-Jun-2021 |
David Gow <davidgow@google.com> |
kunit: test: Add example tests which are always skipped
Add two new tests to the example test suite, both of which are always skipped. This is used as an example for how to write tests which are ski
kunit: test: Add example tests which are always skipped
Add two new tests to the example test suite, both of which are always skipped. This is used as an example for how to write tests which are skipped, and to demonstrate the difference between kunit_skip() and kunit_mark_skipped().
Note that these tests are enabled by default, so a default run of KUnit will have two skipped tests.
Signed-off-by: David Gow <davidgow@google.com> Reviewed-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Marco Elver <elver@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
6d2426b2 | 25-Jun-2021 |
David Gow <davidgow@google.com> |
kunit: Support skipped tests
The kunit_mark_skipped() macro marks the current test as "skipped", with the provided reason. The kunit_skip() macro will mark the test as skipped, and abort the test.
kunit: Support skipped tests
The kunit_mark_skipped() macro marks the current test as "skipped", with the provided reason. The kunit_skip() macro will mark the test as skipped, and abort the test.
The TAP specification supports this "SKIP directive" as a comment after the "ok" / "not ok" for a test. See the "Directives" section of the TAP spec for details: https://testanything.org/tap-specification.html#directives
The 'success' field for KUnit tests is replaced with a kunit_status enum, which can be SUCCESS, FAILURE, or SKIPPED, combined with a 'status_comment' containing information on why a test was skipped.
A new 'kunit_status' test suite is added to test this.
Signed-off-by: David Gow <davidgow@google.com> Tested-by: Marco Elver <elver@google.com> Reviewed-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
7122debb | 03-May-2021 |
Daniel Latypov <dlatypov@google.com> |
kunit: introduce kunit_kmalloc_array/kunit_kcalloc() helpers
Add in: * kunit_kmalloc_array() and wire up kunit_kmalloc() to be a special case of it. * kunit_kcalloc() for symmetry with kunit_kzalloc
kunit: introduce kunit_kmalloc_array/kunit_kcalloc() helpers
Add in: * kunit_kmalloc_array() and wire up kunit_kmalloc() to be a special case of it. * kunit_kcalloc() for symmetry with kunit_kzalloc()
This should using KUnit more natural by making it more similar to the existing *alloc() APIs.
And while we shouldn't necessarily be writing unit tests where overflow should be a concern, it can't hurt to be safe.
Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
b6d5799b | 26-May-2021 |
David Gow <davidgow@google.com> |
kunit: Add 'kunit_shutdown' option
Add a new kernel command-line option, 'kunit_shutdown', which allows the user to specify that the kernel poweroff, halt, or reboot after completing all KUnit tests
kunit: Add 'kunit_shutdown' option
Add a new kernel command-line option, 'kunit_shutdown', which allows the user to specify that the kernel poweroff, halt, or reboot after completing all KUnit tests; this is very handy for running KUnit tests on UML or a VM so that the UML/VM process exits cleanly immediately after running all tests without needing a special initramfs.
Signed-off-by: David Gow <davidgow@google.com> Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Stephen Boyd <sboyd@kernel.org> Tested-By: Daniel Latypov <dlatypov@google.com> Reviewed-by: Daniel Latypov <dlatypov@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
359a3760 | 11-Mar-2021 |
Uriel Guajardo <urielguajardo@google.com> |
kunit: support failure from dynamic analysis tools
Add a kunit_fail_current_test() function to fail the currently running test, if any, with an error message.
This is largely intended for dynamic a
kunit: support failure from dynamic analysis tools
Add a kunit_fail_current_test() function to fail the currently running test, if any, with an error message.
This is largely intended for dynamic analysis tools like UBSAN and for fakes. E.g. say I had a fake ops struct for testing and I wanted my `free` function to complain if it was called with an invalid argument, or caught a double-free. Most return void and have no normal means of signalling failure (e.g. super_operations, iommu_ops, etc.).
Key points: * Always update current->kunit_test so anyone can use it. * commit 83c4e7a0363b ("KUnit: KASAN Integration") only updated it for CONFIG_KASAN=y
* Create a new header <kunit/test-bug.h> so non-test code doesn't have to include all of <kunit/test.h> (e.g. lib/ubsan.c)
* Forward the file and line number to make it easier to track down failures
* Declare the helper function for nice __printf() warnings about mismatched format strings even when KUnit is not enabled.
Example output from kunit_fail_current_test("message"): [15:19:34] [FAILED] example_simple_test [15:19:34] # example_simple_test: initializing [15:19:34] # example_simple_test: lib/kunit/kunit-example-test.c:24: message [15:19:34] not ok 1 - example_simple_test
Fixed minor check patch with checkpatch --fix option: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Daniel Latypov <dlatypov@google.com> Signed-off-by: Uriel Guajardo <urielguajardo@google.com> Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
9854781d | 22-Feb-2021 |
Daniel Latypov <dlatypov@google.com> |
kunit: tool: make --kunitconfig accept dirs, add lib/kunit fragment
TL;DR $ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunit
Per suggestion from Ted [1], we can reduce the amount of typin
kunit: tool: make --kunitconfig accept dirs, add lib/kunit fragment
TL;DR $ ./tools/testing/kunit/kunit.py run --kunitconfig=lib/kunit
Per suggestion from Ted [1], we can reduce the amount of typing by assuming a convention that these files are named '.kunitconfig'.
In the case of [1], we now have $ ./tools/testing/kunit/kunit.py run --kunitconfig=fs/ext4
Also add in such a fragment for kunit itself so we can give that as an example more close to home (and thus less likely to be accidentally broken).
[1] https://lore.kernel.org/linux-ext4/YCNF4yP1dB97zzwD@mit.edu/
Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: David Gow <davidgow@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
acd97625 | 02-Apr-2021 |
Daniel Latypov <dlatypov@google.com> |
kunit: make KUNIT_EXPECT_STREQ() quote values, don't print literals
Before: > Expected str == "world", but > str == hello > "world" == world
After: > Expected str == "world", but >
kunit: make KUNIT_EXPECT_STREQ() quote values, don't print literals
Before: > Expected str == "world", but > str == hello > "world" == world
After: > Expected str == "world", but > str == "hello" <we don't need to tell the user that "world" == "world">
Note: like the literal ellision for integers, this doesn't handle the case of KUNIT_EXPECT_STREQ(test, "hello", "world") since we don't expect it to realistically happen in checked in tests. (If you really wanted a test to fail, KUNIT_FAIL("msg") exists)
In that case, you'd get: > Expected "hello" == "world", but <output for next failure>
Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
5d31f71e | 05-Feb-2021 |
Daniel Latypov <dlatypov@google.com> |
kunit: add kunit.filter_glob cmdline option to filter suites
E.g. specifying this would run suites with "list" in their name. kunit.filter_glob=list*
Note: the executor prints out a TAP header th
kunit: add kunit.filter_glob cmdline option to filter suites
E.g. specifying this would run suites with "list" in their name. kunit.filter_glob=list*
Note: the executor prints out a TAP header that includes the number of suites we intend to run. So unless we want to report empty results for filtered-out suites, we need to do the filtering here in the executor. It's also probably better in the executor since we most likely don't want any filtering to apply to tests built as modules.
This code does add a CONFIG_GLOB=y dependency for CONFIG_KUNIT=y. But the code seems light enough that it shouldn't be an issue.
For now, we only filter on suite names so we don't have to create copies of the suites themselves, just the array (of arrays) holding them.
The name is rather generic since in the future, we could consider extending it to a syntax like: kunit.filter_glob=<suite_glob>.<test_glob> E.g. to run all the del list tests kunit.filter_glob=list-kunit-test.*del*
But at the moment, it's far easier to manually comment out test cases in test files as opposed to messing with sets of Kconfig entries to select specific suites. So even just doing this makes using kunit far less annoying.
Signed-off-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
8c0d8849 | 04-Aug-2020 |
Brendan Higgins <brendanhiggins@google.com> |
init: main: add KUnit to kernel init
Although we have not seen any actual examples where KUnit doesn't work because it runs in the late init phase of the kernel, it has been a concern for some time
init: main: add KUnit to kernel init
Although we have not seen any actual examples where KUnit doesn't work because it runs in the late init phase of the kernel, it has been a concern for some time that this could potentially be an issue in the future. So, remove KUnit from init calls entirely, instead call directly from kernel_init() so that KUnit runs after late init.
Co-developed-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Signed-off-by: Brendan Higgins <brendanhiggins@google.com> Reviewed-by: Stephen Boyd <sboyd@kernel.org> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|
725aca95 | 29-May-2020 |
Alan Maguire <alan.maguire@oracle.com> |
kunit: add support for named resources
The kunit resources API allows for custom initialization and cleanup code (init/fini); here a new resource add function sets the "struct kunit_resource" "name"
kunit: add support for named resources
The kunit resources API allows for custom initialization and cleanup code (init/fini); here a new resource add function sets the "struct kunit_resource" "name" field, and calls the standard add function. Having a simple way to name resources is useful in cases such as multithreaded tests where a set of resources are shared among threads; a pointer to the "struct kunit *" test state then is all that is needed to retrieve and use named resources. Support is provided to add, find and destroy named resources; the latter two are simply wrappers that use a "match-by-name" callback.
If an attempt to add a resource with a name that already exists is made kunit_add_named_resource() will return -EEXIST.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
show more ...
|