Skip to content

Commit b360644

Browse files
Harinder SinghJonathan Corbet
authored andcommitted
Documentation: KUnit: Restyled Frequently Asked Questions
Reword to align with other chapters. Signed-off-by: Harinder Singh <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Corbet <[email protected]>
1 parent 39150e8 commit b360644

File tree

1 file changed

+36
-37
lines changed
  • Documentation/dev-tools/kunit

1 file changed

+36
-37
lines changed

Documentation/dev-tools/kunit/faq.rst

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,55 @@
44
Frequently Asked Questions
55
==========================
66

7-
How is this different from Autotest, kselftest, etc?
8-
====================================================
7+
How is this different from Autotest, kselftest, and so on?
8+
==========================================================
99
KUnit is a unit testing framework. Autotest, kselftest (and some others) are
1010
not.
1111

1212
A `unit test <https://martinfowler.com/bliki/UnitTest.html>`_ is supposed to
13-
test a single unit of code in isolation, hence the name. A unit test should be
14-
the finest granularity of testing and as such should allow all possible code
15-
paths to be tested in the code under test; this is only possible if the code
16-
under test is very small and does not have any external dependencies outside of
13+
test a single unit of code in isolation and hence the name *unit test*. A unit
14+
test should be the finest granularity of testing and should allow all possible
15+
code paths to be tested in the code under test. This is only possible if the
16+
code under test is small and does not have any external dependencies outside of
1717
the test's control like hardware.
1818

1919
There are no testing frameworks currently available for the kernel that do not
20-
require installing the kernel on a test machine or in a VM and all require
21-
tests to be written in userspace and run on the kernel under test; this is true
22-
for Autotest, kselftest, and some others, disqualifying any of them from being
23-
considered unit testing frameworks.
20+
require installing the kernel on a test machine or in a virtual machine. All
21+
testing frameworks require tests to be written in userspace and run on the
22+
kernel under test. This is true for Autotest, kselftest, and some others,
23+
disqualifying any of them from being considered unit testing frameworks.
2424

2525
Does KUnit support running on architectures other than UML?
2626
===========================================================
2727

28-
Yes, well, mostly.
28+
Yes, mostly.
2929

30-
For the most part, the KUnit core framework (what you use to write the tests)
31-
can compile to any architecture; it compiles like just another part of the
30+
For the most part, the KUnit core framework (what we use to write the tests)
31+
can compile to any architecture. It compiles like just another part of the
3232
kernel and runs when the kernel boots, or when built as a module, when the
33-
module is loaded. However, there is some infrastructure,
34-
like the KUnit Wrapper (``tools/testing/kunit/kunit.py``) that does not support
35-
other architectures.
33+
module is loaded. However, there is infrastructure, like the KUnit Wrapper
34+
(``tools/testing/kunit/kunit.py``) that does not support other architectures.
3635

37-
In short, this means that, yes, you can run KUnit on other architectures, but
38-
it might require more work than using KUnit on UML.
36+
In short, yes, you can run KUnit on other architectures, but it might require
37+
more work than using KUnit on UML.
3938

4039
For more information, see :ref:`kunit-on-non-uml`.
4140

42-
What is the difference between a unit test and these other kinds of tests?
43-
==========================================================================
41+
What is the difference between a unit test and other kinds of tests?
42+
====================================================================
4443
Most existing tests for the Linux kernel would be categorized as an integration
4544
test, or an end-to-end test.
4645

47-
- A unit test is supposed to test a single unit of code in isolation, hence the
48-
name. A unit test should be the finest granularity of testing and as such
49-
should allow all possible code paths to be tested in the code under test; this
50-
is only possible if the code under test is very small and does not have any
51-
external dependencies outside of the test's control like hardware.
46+
- A unit test is supposed to test a single unit of code in isolation. A unit
47+
test should be the finest granularity of testing and, as such, allows all
48+
possible code paths to be tested in the code under test. This is only possible
49+
if the code under test is small and does not have any external dependencies
50+
outside of the test's control like hardware.
5251
- An integration test tests the interaction between a minimal set of components,
5352
usually just two or three. For example, someone might write an integration
5453
test to test the interaction between a driver and a piece of hardware, or to
5554
test the interaction between the userspace libraries the kernel provides and
56-
the kernel itself; however, one of these tests would probably not test the
55+
the kernel itself. However, one of these tests would probably not test the
5756
entire kernel along with hardware interactions and interactions with the
5857
userspace.
5958
- An end-to-end test usually tests the entire system from the perspective of the
@@ -62,26 +61,26 @@ test, or an end-to-end test.
6261
hardware with a production userspace and then trying to exercise some behavior
6362
that depends on interactions between the hardware, the kernel, and userspace.
6463

65-
KUnit isn't working, what should I do?
66-
======================================
64+
KUnit is not working, what should I do?
65+
=======================================
6766

6867
Unfortunately, there are a number of things which can break, but here are some
6968
things to try.
7069

71-
1. Try running ``./tools/testing/kunit/kunit.py run`` with the ``--raw_output``
70+
1. Run ``./tools/testing/kunit/kunit.py run`` with the ``--raw_output``
7271
parameter. This might show details or error messages hidden by the kunit_tool
7372
parser.
7473
2. Instead of running ``kunit.py run``, try running ``kunit.py config``,
7574
``kunit.py build``, and ``kunit.py exec`` independently. This can help track
7675
down where an issue is occurring. (If you think the parser is at fault, you
77-
can run it manually against stdin or a file with ``kunit.py parse``.)
78-
3. Running the UML kernel directly can often reveal issues or error messages
79-
kunit_tool ignores. This should be as simple as running ``./vmlinux`` after
80-
building the UML kernel (e.g., by using ``kunit.py build``). Note that UML
81-
has some unusual requirements (such as the host having a tmpfs filesystem
82-
mounted), and has had issues in the past when built statically and the host
83-
has KASLR enabled. (On older host kernels, you may need to run ``setarch
84-
`uname -m` -R ./vmlinux`` to disable KASLR.)
76+
can run it manually against ``stdin`` or a file with ``kunit.py parse``.)
77+
3. Running the UML kernel directly can often reveal issues or error messages,
78+
``kunit_tool`` ignores. This should be as simple as running ``./vmlinux``
79+
after building the UML kernel (for example, by using ``kunit.py build``).
80+
Note that UML has some unusual requirements (such as the host having a tmpfs
81+
filesystem mounted), and has had issues in the past when built statically and
82+
the host has KASLR enabled. (On older host kernels, you may need to run
83+
``setarch `uname -m` -R ./vmlinux`` to disable KASLR.)
8584
4. Make sure the kernel .config has ``CONFIG_KUNIT=y`` and at least one test
8685
(e.g. ``CONFIG_KUNIT_EXAMPLE_TEST=y``). kunit_tool will keep its .config
8786
around, so you can see what config was used after running ``kunit.py run``.

0 commit comments

Comments
 (0)