~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/dev-tools/kunit/faq.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/dev-tools/kunit/faq.rst (Version linux-6.12-rc7) and /Documentation/dev-tools/kunit/faq.rst (Version linux-5.8.18)


  1 .. SPDX-License-Identifier: GPL-2.0                 1 .. SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 ==========================                          3 ==========================
  4 Frequently Asked Questions                          4 Frequently Asked Questions
  5 ==========================                          5 ==========================
  6                                                     6 
  7 How is this different from Autotest, kselftest !!   7 How is this different from Autotest, kselftest, etc?
  8 ============================================== !!   8 ====================================================
  9 KUnit is a unit testing framework. Autotest, k      9 KUnit is a unit testing framework. Autotest, kselftest (and some others) are
 10 not.                                               10 not.
 11                                                    11 
 12 A `unit test <https://martinfowler.com/bliki/U     12 A `unit test <https://martinfowler.com/bliki/UnitTest.html>`_ is supposed to
 13 test a single unit of code in isolation and he !!  13 test a single unit of code in isolation, hence the name. A unit test should be
 14 test should be the finest granularity of testi !!  14 the finest granularity of testing and as such should allow all possible code
 15 code paths to be tested in the code under test !!  15 paths to be tested in the code under test; this is only possible if the code
 16 code under test is small and does not have any !!  16 under test is very small and does not have any external dependencies outside of
 17 the test's control like hardware.                  17 the test's control like hardware.
 18                                                    18 
 19 There are no testing frameworks currently avai     19 There are no testing frameworks currently available for the kernel that do not
 20 require installing the kernel on a test machin !!  20 require installing the kernel on a test machine or in a VM and all require
 21 testing frameworks require tests to be written !!  21 tests to be written in userspace and run on the kernel under test; this is true
 22 kernel under test. This is true for Autotest,  !!  22 for Autotest, kselftest, and some others, disqualifying any of them from being
 23 disqualifying any of them from being considere !!  23 considered unit testing frameworks.
 24                                                    24 
 25 Does KUnit support running on architectures ot     25 Does KUnit support running on architectures other than UML?
 26 ==============================================     26 ===========================================================
 27                                                    27 
 28 Yes, mostly.                                   !!  28 Yes, well, mostly.
 29                                                    29 
 30 For the most part, the KUnit core framework (w !!  30 For the most part, the KUnit core framework (what you use to write the tests)
 31 can compile to any architecture. It compiles l !!  31 can compile to any architecture; it compiles like just another part of the
 32 kernel and runs when the kernel boots, or when     32 kernel and runs when the kernel boots, or when built as a module, when the
 33 module is loaded.  However, there is infrastru !!  33 module is loaded.  However, there is some infrastructure,
 34 (``tools/testing/kunit/kunit.py``) that might  !!  34 like the KUnit Wrapper (``tools/testing/kunit/kunit.py``) that does not support
 35 (see :ref:`kunit-on-qemu`).                    !!  35 other architectures.
 36                                                    36 
 37 In short, yes, you can run KUnit on other arch !!  37 In short, this means that, yes, you can run KUnit on other architectures, but
 38 more work than using KUnit on UML.             !!  38 it might require more work than using KUnit on UML.
 39                                                    39 
 40 For more information, see :ref:`kunit-on-non-u     40 For more information, see :ref:`kunit-on-non-uml`.
 41                                                    41 
 42 .. _kinds-of-tests:                            !!  42 What is the difference between a unit test and these other kinds of tests?
 43                                                !!  43 ==========================================================================
 44 What is the difference between a unit test and << 
 45 ============================================== << 
 46 Most existing tests for the Linux kernel would     44 Most existing tests for the Linux kernel would be categorized as an integration
 47 test, or an end-to-end test.                       45 test, or an end-to-end test.
 48                                                    46 
 49 - A unit test is supposed to test a single uni !!  47 - A unit test is supposed to test a single unit of code in isolation, hence the
 50   test should be the finest granularity of tes !!  48   name. A unit test should be the finest granularity of testing and as such
 51   possible code paths to be tested in the code !!  49   should allow all possible code paths to be tested in the code under test; this
 52   if the code under test is small and does not !!  50   is only possible if the code under test is very small and does not have any
 53   outside of the test's control like hardware. !!  51   external dependencies outside of the test's control like hardware.
 54 - An integration test tests the interaction be     52 - An integration test tests the interaction between a minimal set of components,
 55   usually just two or three. For example, some     53   usually just two or three. For example, someone might write an integration
 56   test to test the interaction between a drive     54   test to test the interaction between a driver and a piece of hardware, or to
 57   test the interaction between the userspace l     55   test the interaction between the userspace libraries the kernel provides and
 58   the kernel itself. However, one of these tes !!  56   the kernel itself; however, one of these tests would probably not test the
 59   entire kernel along with hardware interactio     57   entire kernel along with hardware interactions and interactions with the
 60   userspace.                                       58   userspace.
 61 - An end-to-end test usually tests the entire      59 - An end-to-end test usually tests the entire system from the perspective of the
 62   code under test. For example, someone might      60   code under test. For example, someone might write an end-to-end test for the
 63   kernel by installing a production configurat     61   kernel by installing a production configuration of the kernel on production
 64   hardware with a production userspace and the     62   hardware with a production userspace and then trying to exercise some behavior
 65   that depends on interactions between the har     63   that depends on interactions between the hardware, the kernel, and userspace.
 66                                                    64 
 67 KUnit is not working, what should I do?        !!  65 KUnit isn't working, what should I do?
 68 =======================================        !!  66 ======================================
 69                                                    67 
 70 Unfortunately, there are a number of things wh     68 Unfortunately, there are a number of things which can break, but here are some
 71 things to try.                                     69 things to try.
 72                                                    70 
 73 1. Run ``./tools/testing/kunit/kunit.py run``  !!  71 1. Try running ``./tools/testing/kunit/kunit.py run`` with the ``--raw_output``
 74    parameter. This might show details or error     72    parameter. This might show details or error messages hidden by the kunit_tool
 75    parser.                                         73    parser.
 76 2. Instead of running ``kunit.py run``, try ru     74 2. Instead of running ``kunit.py run``, try running ``kunit.py config``,
 77    ``kunit.py build``, and ``kunit.py exec`` i     75    ``kunit.py build``, and ``kunit.py exec`` independently. This can help track
 78    down where an issue is occurring. (If you t     76    down where an issue is occurring. (If you think the parser is at fault, you
 79    can run it manually against ``stdin`` or a  !!  77    can run it manually against stdin or a file with ``kunit.py parse``.)
 80 3. Running the UML kernel directly can often r !!  78 3. Running the UML kernel directly can often reveal issues or error messages
 81    ``kunit_tool`` ignores. This should be as s !!  79    kunit_tool ignores. This should be as simple as running ``./vmlinux`` after
 82    after building the UML kernel (for example, !!  80    building the UML kernel (e.g., by using ``kunit.py build``). Note that UML
 83    Note that UML has some unusual requirements !!  81    has some unusual requirements (such as the host having a tmpfs filesystem
 84    filesystem mounted), and has had issues in  !!  82    mounted), and has had issues in the past when built statically and the host
 85    the host has KASLR enabled. (On older host  !!  83    has KASLR enabled. (On older host kernels, you may need to run ``setarch
 86    ``setarch `uname -m` -R ./vmlinux`` to disa !!  84    `uname -m` -R ./vmlinux`` to disable KASLR.)
 87 4. Make sure the kernel .config has ``CONFIG_K     85 4. Make sure the kernel .config has ``CONFIG_KUNIT=y`` and at least one test
 88    (e.g. ``CONFIG_KUNIT_EXAMPLE_TEST=y``). kun     86    (e.g. ``CONFIG_KUNIT_EXAMPLE_TEST=y``). kunit_tool will keep its .config
 89    around, so you can see what config was used     87    around, so you can see what config was used after running ``kunit.py run``.
 90    It also preserves any config changes you mi     88    It also preserves any config changes you might make, so you can
 91    enable/disable things with ``make ARCH=um m     89    enable/disable things with ``make ARCH=um menuconfig`` or similar, and then
 92    re-run kunit_tool.                              90    re-run kunit_tool.
 93 5. Try to run ``make ARCH=um defconfig`` befor     91 5. Try to run ``make ARCH=um defconfig`` before running ``kunit.py run``. This
 94    may help clean up any residual config items     92    may help clean up any residual config items which could be causing problems.
 95 6. Finally, try running KUnit outside UML. KUn !!  93 6. Finally, try running KUnit outside UML. KUnit and KUnit tests can run be
 96    built into any kernel, or can be built as a     94    built into any kernel, or can be built as a module and loaded at runtime.
 97    Doing so should allow you to determine if U     95    Doing so should allow you to determine if UML is causing the issue you're
 98    seeing. When tests are built-in, they will      96    seeing. When tests are built-in, they will execute when the kernel boots, and
 99    modules will automatically execute associat     97    modules will automatically execute associated tests when loaded. Test results
100    can be collected from ``/sys/kernel/debug/k     98    can be collected from ``/sys/kernel/debug/kunit/<test suite>/results``, and
101    can be parsed with ``kunit.py parse``. For  !!  99    can be parsed with ``kunit.py parse``. For more details, see "KUnit on
                                                   >> 100    non-UML architectures" in :doc:`usage`.
102                                                   101 
103 If none of the above tricks help, you are alwa    102 If none of the above tricks help, you are always welcome to email any issues to
104 kunit-dev@googlegroups.com.                       103 kunit-dev@googlegroups.com.
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php