## TL;DR
This patchset adds a centralized executor to dispatch tests rather than
relying on late_initcall to schedule each test suite separately along
with a couple of new features that depend on it.
## What am I trying to do?
Conceptually, I am trying to provide a mechanism by which test suites
can be grouped together so that they can be reasoned about collectively.
The last two of three patches in this series add features which depend
on this:
PATCH 09/12 Prints out a test plan[1] right before KUnit tests are run;
this is valuable because it makes it possible for a test
harness to detect whether the number of tests run matches
the number of tests expected to be run, ensuring that no
tests silently failed. The test plan includes a count of
tests that will run. With the centralized executor, the
tests are located in a single data structure and thus can be
counted.
PATCH 10/12 Add a new kernel command-line option 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. The centralized executor provides a
definitive point when all tests have completed and the
poweroff, halt, or reboot could occur.
In addition, by dispatching tests from a single location, we can
guarantee that all KUnit tests run after late_init is complete, which
was a concern during the initial KUnit patchset review (this has not
been a problem in practice, but resolving with certainty is nevertheless
desirable).
Other use cases for this exist, but the above features should provide an
idea of the value that this could provide.
## Changes since last revision:
- Fixed a compilation error in the centralized executor patch (07/12).
I had forgotten to test the patches when building as modules. I
verified that works now.
- I accidentally merged patches 09/12 and 10/12 in the previous
revision (v4), and made them separate patches again.
## Changes since v3:
- On the last revision I got some messages from 0day that showed that
this patchset didn't work on several architectures, one issue that
this patchset addresses is that we were aligning both memory segments
as well as structures in the segments to specific byte boundaries
which was incorrect.
- The issue mentioned above also caused me to test on additional
architectures which revealed that some architectures other than UML
do not use the default init linker section macro that most
architectures use. There are now several new patches (2, 3, 4, and
6).
- Fixed a formatting consistency issue in the kernel params
documentation patch (11/12).
- Add a brief blurb on how and when the kunit_test_suite macro works.
## Remaining work to be done:
The only architecture for which I was able to get a compiler, but was
apparently unable to get KUnit into a section that the executor to see
was m68k - not sure why.
Alan Maguire (1):
kunit: test: create a single centralized executor for all tests
Brendan Higgins (10):
vmlinux.lds.h: add linker section for KUnit test suites
arch: arm64: add linker section for KUnit test suites
arch: microblaze: add linker section for KUnit test suites
arch: powerpc: add linker section for KUnit test suites
arch: um: add linker section for KUnit test suites
arch: xtensa: add linker section for KUnit test suites
init: main: add KUnit to kernel init
kunit: test: add test plan to KUnit TAP format
Documentation: Add kunit_shutdown to kernel-parameters.txt
Documentation: kunit: add a brief blurb about kunit_test_suite
David Gow (1):
kunit: Add 'kunit_shutdown' option
.../admin-guide/kernel-parameters.txt | 8 ++
Documentation/dev-tools/kunit/usage.rst | 5 ++
arch/arm64/kernel/vmlinux.lds.S | 3 +
arch/microblaze/kernel/vmlinux.lds.S | 4 +
arch/powerpc/kernel/vmlinux.lds.S | 4 +
arch/um/include/asm/common.lds.S | 4 +
arch/xtensa/kernel/vmlinux.lds.S | 4 +
include/asm-generic/vmlinux.lds.h | 8 ++
include/kunit/test.h | 76 +++++++++++++-----
init/main.c | 4 +
lib/kunit/Makefile | 3 +-
lib/kunit/executor.c | 63 +++++++++++++++
lib/kunit/test.c | 13 +--
tools/testing/kunit/kunit_kernel.py | 2 +-
tools/testing/kunit/kunit_parser.py | 74 ++++++++++++++---
.../test_is_test_passed-all_passed.log | Bin 1562 -> 1567 bytes
.../test_data/test_is_test_passed-crash.log | Bin 3016 -> 3021 bytes
.../test_data/test_is_test_passed-failure.log | Bin 1700 -> 1705 bytes
18 files changed, 227 insertions(+), 48 deletions(-)
create mode 100644 lib/kunit/executor.c
These patches are available for download with dependencies here:
https://kunit-review.googlesource.com/c/linux/+/3829
[1] https://github.com/isaacs/testanything.github.io/blob/tap14/tap-version-14-specification.md#the-plan
[2] https://patchwork.kernel.org/patch/11383635/
base-commit: 4333a9b0b67bb4e8bcd91bdd80da80b0ec151162
prerequisite-patch-id: 2d4b5aa9fa8ada9ae04c8584b47c299a822b9455
prerequisite-patch-id: 582b6d9d28ce4b71628890ec832df6522ca68de0
--
2.27.0.212.ge8ba1cc988-goog
Add a linker section where KUnit can put references to its test suites.
This patch is the first step in transitioning to dispatching all KUnit
tests from a centralized executor rather than having each as its own
separate late_initcall.
Co-developed-by: Iurii Zaikin <redacted>
Signed-off-by: Iurii Zaikin <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
include/asm-generic/vmlinux.lds.h | 8 ++++++++
1 file changed, 8 insertions(+)
@@ -881,6 +881,13 @@KEEP(*(.con_initcall.init))\__con_initcall_end=.;+/* Alignment must be consistent with (kunit_suite *) in include/kunit/test.h */+#define KUNIT_TEST_SUITES \+.=ALIGN(8);\+__kunit_suites_start=.;\+KEEP(*(.kunit_test_suites))\+__kunit_suites_end=.;+#ifdef CONFIG_BLK_DEV_INITRD#define INIT_RAM_FS \.=ALIGN(4);\
Add a linker section to arm64 where KUnit can put references to its test
suites. This patch is an early step in transitioning to dispatching all
KUnit tests from a centralized executor rather than having each as its
own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/arm64/kernel/vmlinux.lds.S | 3 +++
1 file changed, 3 insertions(+)
Add a linker section to powerpc where KUnit can put references to its test
suites. This patch is an early step in transitioning to dispatching all
KUnit tests from a centralized executor rather than having each as its
own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/powerpc/kernel/vmlinux.lds.S | 4 ++++
1 file changed, 4 insertions(+)
Add kunit_shutdown, an option to specify that the kernel shutsdown after
running KUnit tests, to the kernel-parameters.txt documentation.
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
Documentation/admin-guide/kernel-parameters.txt | 8 ++++++++
1 file changed, 8 insertions(+)
@@ -2183,6 +2183,14 @@ 0: force disabled 1: force enabled+ kunit_shutdown=[KERNEL UNIT TESTING FRAMEWORK] Shutdown kernel after+ running built-in tests. Tests configured as modules will+ not be run.+ Default: (flag not present) don't shutdown+ poweroff: poweroff the kernel after running tests+ halt: halt the kernel after running tests+ reboot: reboot the kernel after running tests+ kvm.ignore_msrs=[KVM] Ignore guest accesses to unhandled MSRs. Default is 0 (don't ignore, but inject #GP)
From: David Gow <redacted>
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 <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
lib/kunit/executor.c | 20 ++++++++++++++++++++
tools/testing/kunit/kunit_kernel.py | 2 +-
tools/testing/kunit/kunit_parser.py | 2 +-
3 files changed, 22 insertions(+), 2 deletions(-)
@@ -49,7 +49,7 @@ class TestStatus(Enum):kunit_start_re=re.compile(r'TAP version [0-9]+$')kunit_end_re=re.compile('(List of all partitions:|'-'Kernel panic - not syncing: VFS:)')+'Kernel panic - not syncing: VFS:|reboot: System halted)')defisolate_kunit_output(kernel_output):started=False
Add a brief blurb saying how and when the kunit_test_suite() macro
works to the usage documentation.
Signed-off-by: Brendan Higgins <redacted>
---
Documentation/dev-tools/kunit/usage.rst | 5 +++++
1 file changed, 5 insertions(+)
@@ -211,6 +211,11 @@ KUnit test framework...note:: A test case will only be run if it is associated with a test suite.+``kunit_test_suite(...)`` is a macro which tells the linker to put the specified+test suite in a special linker section so that it can be run by KUnit either+after late_init, or when the test module is loaded (depending on whether the+test was built in or not).+ For more information on these types of things see the :doc:`api/test`. Isolating Behavior
TAP 14 allows an optional test plan to be emitted before the start of
the start of testing[1]; this is valuable because it makes it possible
for a test harness to detect whether the number of tests run matches the
number of tests expected to be run, ensuring that no tests silently
failed.
Link[1]: https://github.com/isaacs/testanything.github.io/blob/tap14/tap-version-14-specification.md#the-plan
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
lib/kunit/executor.c | 17 ++++
lib/kunit/test.c | 11 ---
tools/testing/kunit/kunit_parser.py | 76 +++++++++++++++---
.../test_is_test_passed-all_passed.log | Bin 1562 -> 1567 bytes
.../test_data/test_is_test_passed-crash.log | Bin 3016 -> 3021 bytes
.../test_data/test_is_test_passed-failure.log | Bin 1700 -> 1705 bytes
6 files changed, 80 insertions(+), 24 deletions(-)
@@ -45,10 +45,11 @@ class TestStatus(Enum):FAILURE=auto()TEST_CRASHED=auto()NO_TESTS=auto()+FAILURE_TO_PARSE_TESTS=auto()kunit_start_re=re.compile(r'TAP version [0-9]+$')kunit_end_re=re.compile('(List of all partitions:|'-'Kernel panic - not syncing: VFS:|reboot: System halted)')+'Kernel panic - not syncing: VFS:)')defisolate_kunit_output(kernel_output):started=False
Add a linker section to xtensa where KUnit can put references to its
test suites. This patch is an early step in transitioning to dispatching
all KUnit tests from a centralized executor rather than having each as
its own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/xtensa/kernel/vmlinux.lds.S | 4 ++++
1 file changed, 4 insertions(+)
Add a linker section to UML where KUnit can put references to its test
suites. This patch is an early step in transitioning to dispatching all
KUnit tests from a centralized executor rather than having each as its
own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
arch/um/include/asm/common.lds.S | 4 ++++
1 file changed, 4 insertions(+)
Add a linker section to microblaze where KUnit can put references to its
test suites. This patch is an early step in transitioning to dispatching
all KUnit tests from a centralized executor rather than having each as
its own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/microblaze/kernel/vmlinux.lds.S | 4 ++++
1 file changed, 4 insertions(+)
On Fri, Jun 26, 2020 at 02:09:06PM -0700, Brendan Higgins wrote:
quoted hunk
Add a linker section where KUnit can put references to its test suites.
This patch is the first step in transitioning to dispatching all KUnit
tests from a centralized executor rather than having each as its own
separate late_initcall.
Co-developed-by: Iurii Zaikin <redacted>
Signed-off-by: Iurii Zaikin <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
include/asm-generic/vmlinux.lds.h | 8 ++++++++
1 file changed, 8 insertions(+)
Nack: this must be in INIT_DATA, not in INIT_DATA_SECTION. Not all
architectures use the INIT_DATA_SECTION macro (e.g. arm64), but everything
uses INIT_DATA.
--
Kees Cook
On Fri, Jun 26, 2020 at 02:09:07PM -0700, Brendan Higgins wrote:
quoted hunk
Add a linker section to arm64 where KUnit can put references to its test
suites. This patch is an early step in transitioning to dispatching all
KUnit tests from a centralized executor rather than having each as its
own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/arm64/kernel/vmlinux.lds.S | 3 +++
1 file changed, 3 insertions(+)
On Fri, Jun 26, 2020 at 2:20 PM Kees Cook [off-list ref] wrote:
On Fri, Jun 26, 2020 at 02:09:06PM -0700, Brendan Higgins wrote:
quoted
Add a linker section where KUnit can put references to its test suites.
This patch is the first step in transitioning to dispatching all KUnit
tests from a centralized executor rather than having each as its own
separate late_initcall.
Co-developed-by: Iurii Zaikin <redacted>
Signed-off-by: Iurii Zaikin <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
include/asm-generic/vmlinux.lds.h | 8 ++++++++
1 file changed, 8 insertions(+)
Nack: this must be in INIT_DATA, not in INIT_DATA_SECTION. Not all
architectures use the INIT_DATA_SECTION macro (e.g. arm64), but everything
uses INIT_DATA.
Oh, maybe that would eliminate the need for the other linkerscript
patches? That would be nice.
Alright, will fix.
On Fri, Jun 26, 2020 at 2:20 PM Kees Cook [off-list ref] wrote:
On Fri, Jun 26, 2020 at 02:09:07PM -0700, Brendan Higgins wrote:
quoted
Add a linker section to arm64 where KUnit can put references to its test
suites. This patch is an early step in transitioning to dispatching all
KUnit tests from a centralized executor rather than having each as its
own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/arm64/kernel/vmlinux.lds.S | 3 +++
1 file changed, 3 insertions(+)
On Fri, Jun 26, 2020 at 02:09:11PM -0700, Brendan Higgins wrote:
Add a linker section to xtensa where KUnit can put references to its
test suites. This patch is an early step in transitioning to dispatching
all KUnit tests from a centralized executor rather than having each as
its own separate late_initcall.
Signed-off-by: Brendan Higgins <redacted>
---
arch/xtensa/kernel/vmlinux.lds.S | 4 ++++
If you ever find yourself modifying multiple arch linker scripts for a
series, something has gone wrong. ;)
--
Kees Cook
On Fri, Jun 26, 2020 at 02:09:14PM -0700, Brendan Higgins wrote:
TAP 14 allows an optional test plan to be emitted before the start of
the start of testing[1]; this is valuable because it makes it possible
for a test harness to detect whether the number of tests run matches the
number of tests expected to be run, ensuring that no tests silently
failed.
Link[1]: https://github.com/isaacs/testanything.github.io/blob/tap14/tap-version-14-specification.md#the-plan
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
On Fri, Jun 26, 2020 at 02:09:15PM -0700, Brendan Higgins wrote:
quoted hunk
From: David Gow <redacted>
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 <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
lib/kunit/executor.c | 20 ++++++++++++++++++++
tools/testing/kunit/kunit_kernel.py | 2 +-
tools/testing/kunit/kunit_parser.py | 2 +-
3 files changed, 22 insertions(+), 2 deletions(-)
If you have patches that do something just before the initrd, and then
you add more patches to shut down immediately after an initrd, people
may ask you to just use an initrd instead of filling the kernel with
these changes...
I mean, I get it, but it's not hard to make an initrd that poke a sysctl
to start the tests...
In fact, you don't even need a initrd to poke sysctls these days.
--
Kees Cook
On Fri, Jun 26, 2020 at 02:09:05PM -0700, Brendan Higgins wrote:
This patchset adds a centralized executor to dispatch tests rather than
relying on late_initcall to schedule each test suite separately along
with a couple of new features that depend on it.
So, the new section looks fine to me (modulo the INIT_DATA change). The
plumbing to start the tests, though, I think is redundant. Why not just
add a sysctl that starts all known tests?
That way you don't need the plumbing into init/main.c, and you can have
a mode where builtin tests can be started on a fully booted system too.
i.e. boot with "sysctl.kernel.kunit=start" or when fully booted with
"echo start > /proc/sys/kernel/kunit"
And instead of the kunit-specific halt/reboot stuff, how about moving
/proc/sysrq-trigger into /proc/sys instead? Then you (or anything) could
do:
sysctl.kernel.kunit=start sysctl.kernel.sysrq-trigger=b
--
Kees Cook
From: Luis Chamberlain <mcgrof@kernel.org> Date: 2020-07-08 04:31:33
On Fri, Jun 26, 2020 at 02:22:11PM -0700, Brendan Higgins wrote:
On Fri, Jun 26, 2020 at 2:20 PM Kees Cook [off-list ref] wrote:
quoted
On Fri, Jun 26, 2020 at 02:09:06PM -0700, Brendan Higgins wrote:
quoted
Add a linker section where KUnit can put references to its test suites.
This patch is the first step in transitioning to dispatching all KUnit
tests from a centralized executor rather than having each as its own
separate late_initcall.
Co-developed-by: Iurii Zaikin <redacted>
Signed-off-by: Iurii Zaikin <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
include/asm-generic/vmlinux.lds.h | 8 ++++++++
1 file changed, 8 insertions(+)
Nack: this must be in INIT_DATA, not in INIT_DATA_SECTION. Not all
architectures use the INIT_DATA_SECTION macro (e.g. arm64), but everything
uses INIT_DATA.
Oh, maybe that would eliminate the need for the other linkerscript
patches? That would be nice.
Curious, did changing it as Kees suggest fix it for m68k?
Luis
On Fri, Jun 26, 2020 at 2:52 PM Kees Cook [off-list ref] wrote:
On Fri, Jun 26, 2020 at 02:09:05PM -0700, Brendan Higgins wrote:
quoted
This patchset adds a centralized executor to dispatch tests rather than
relying on late_initcall to schedule each test suite separately along
with a couple of new features that depend on it.
Sorry it took so long to reply. I got sucked into some other stuff again.
So, the new section looks fine to me (modulo the INIT_DATA change). The
plumbing to start the tests, though, I think is redundant. Why not just
add a sysctl that starts all known tests?
We already have that; however, we use debugfs to start the tests -
same difference. I just find it convenient to not have to build and
then maintain a userland for each architecture. It's also really nice
that KUnit "just works out of the box" - you don't have to download
anything other than the kernel source, and you don't need to do any
steps outside of just run "kuit.py run". That seems like a big
advantage to me.
That way you don't need the plumbing into init/main.c, and you can have
a mode where builtin tests can be started on a fully booted system too.
i.e. boot with "sysctl.kernel.kunit=start" or when fully booted with
"echo start > /proc/sys/kernel/kunit"
And instead of the kunit-specific halt/reboot stuff, how about moving
/proc/sysrq-trigger into /proc/sys instead? Then you (or anything) could
do:
sysctl.kernel.kunit=start sysctl.kernel.sysrq-trigger=b
I think it might be harder to make a case for the reboot stuff without
the stuff I am working on outside of this patchset. I think I will
probably drop that patch from this patchset and reintroduce it later.
On Tue, Jul 7, 2020 at 9:31 PM Luis Chamberlain [off-list ref] wrote:
On Fri, Jun 26, 2020 at 02:22:11PM -0700, Brendan Higgins wrote:
quoted
On Fri, Jun 26, 2020 at 2:20 PM Kees Cook [off-list ref] wrote:
quoted
On Fri, Jun 26, 2020 at 02:09:06PM -0700, Brendan Higgins wrote:
quoted
Add a linker section where KUnit can put references to its test suites.
This patch is the first step in transitioning to dispatching all KUnit
tests from a centralized executor rather than having each as its own
separate late_initcall.
Co-developed-by: Iurii Zaikin <redacted>
Signed-off-by: Iurii Zaikin <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
include/asm-generic/vmlinux.lds.h | 8 ++++++++
1 file changed, 8 insertions(+)
Nack: this must be in INIT_DATA, not in INIT_DATA_SECTION. Not all
architectures use the INIT_DATA_SECTION macro (e.g. arm64), but everything
uses INIT_DATA.
Oh, maybe that would eliminate the need for the other linkerscript
patches? That would be nice.
Sorry for the delayed response. I got pulled into some other things.
Curious, did changing it as Kees suggest fix it for m68k?
It did! There are still some architectures I cannot test due to a lack
of GCC or QEMU support, but it seems to work on everything else now.
On Fri, Jun 26, 2020 at 2:35 PM Kees Cook [off-list ref] wrote:
On Fri, Jun 26, 2020 at 02:09:14PM -0700, Brendan Higgins wrote:
quoted
TAP 14 allows an optional test plan to be emitted before the start of
the start of testing[1]; this is valuable because it makes it possible
for a test harness to detect whether the number of tests run matches the
number of tests expected to be run, ensuring that no tests silently
failed.
Link[1]: https://github.com/isaacs/testanything.github.io/blob/tap14/tap-version-14-specification.md#the-plan
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
What is happening here?? Those logs appear as text to me. Why did git
freak out?
That's because this is all test data; it's all plaintext, but out of
necessity some of the test data is kind of munged up and causes
checkpatch to complain, so Shuah asked us to mark it as binary since
it isn't actually code and so checkpatch will stop flagging it.
On Fri, Jun 26, 2020 at 2:40 PM Kees Cook [off-list ref] wrote:
On Fri, Jun 26, 2020 at 02:09:15PM -0700, Brendan Higgins wrote:
quoted
From: David Gow <redacted>
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 <redacted>
Signed-off-by: Brendan Higgins <redacted>
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
---
lib/kunit/executor.c | 20 ++++++++++++++++++++
tools/testing/kunit/kunit_kernel.py | 2 +-
tools/testing/kunit/kunit_parser.py | 2 +-
3 files changed, 22 insertions(+), 2 deletions(-)
If you have patches that do something just before the initrd, and then
you add more patches to shut down immediately after an initrd, people
may ask you to just use an initrd instead of filling the kernel with
these changes...
I mean, I get it, but it's not hard to make an initrd that poke a sysctl
to start the tests...
In fact, you don't even need a initrd to poke sysctls these days.
True, but it is nice to not have to maintain an initramfs for each
architecture that you want to test. Still, I see your point. If we can
find a convenient way to distribute the needed dependencies for
running KUnit on each non-UML architecture then I think I can abandon
this change.
So how about this: I will drop this patch from this patchset and move
it up to the follow up patchset that adds multiarchitecture support to
kunit_tool. There we can address the problem of how to best track the
necessary dependencies including possibly intitramfss.