brintos

brintos / linux-shallow public Read only

0
0
Text · 5.6 KiB · fae426f Raw
105 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3==========================4Frequently Asked Questions5==========================6 7How is this different from Autotest, kselftest, and so on?8==========================================================9KUnit is a unit testing framework. Autotest, kselftest (and some others) are10not.11 12A `unit test <https://martinfowler.com/bliki/UnitTest.html>`_ is supposed to13test a single unit of code in isolation and hence the name *unit test*. A unit14test should be the finest granularity of testing and should allow all possible15code paths to be tested in the code under test. This is only possible if the16code under test is small and does not have any external dependencies outside of17the test's control like hardware.18 19There are no testing frameworks currently available for the kernel that do not20require installing the kernel on a test machine or in a virtual machine. All21testing frameworks require tests to be written in userspace and run on the22kernel under test. This is true for Autotest, kselftest, and some others,23disqualifying any of them from being considered unit testing frameworks.24 25Does KUnit support running on architectures other than UML?26===========================================================27 28Yes, mostly.29 30For the most part, the KUnit core framework (what we use to write the tests)31can compile to any architecture. It compiles like just another part of the32kernel and runs when the kernel boots, or when built as a module, when the33module is loaded.  However, there is infrastructure, like the KUnit Wrapper34(``tools/testing/kunit/kunit.py``) that might not support some architectures35(see :ref:`kunit-on-qemu`).36 37In short, yes, you can run KUnit on other architectures, but it might require38more work than using KUnit on UML.39 40For more information, see :ref:`kunit-on-non-uml`.41 42.. _kinds-of-tests:43 44What is the difference between a unit test and other kinds of tests?45====================================================================46Most existing tests for the Linux kernel would be categorized as an integration47test, or an end-to-end test.48 49- A unit test is supposed to test a single unit of code in isolation. A unit50  test should be the finest granularity of testing and, as such, allows all51  possible code paths to be tested in the code under test. This is only possible52  if the code under test is small and does not have any external dependencies53  outside of the test's control like hardware.54- An integration test tests the interaction between a minimal set of components,55  usually just two or three. For example, someone might write an integration56  test to test the interaction between a driver and a piece of hardware, or to57  test the interaction between the userspace libraries the kernel provides and58  the kernel itself. However, one of these tests would probably not test the59  entire kernel along with hardware interactions and interactions with the60  userspace.61- An end-to-end test usually tests the entire system from the perspective of the62  code under test. For example, someone might write an end-to-end test for the63  kernel by installing a production configuration of the kernel on production64  hardware with a production userspace and then trying to exercise some behavior65  that depends on interactions between the hardware, the kernel, and userspace.66 67KUnit is not working, what should I do?68=======================================69 70Unfortunately, there are a number of things which can break, but here are some71things to try.72 731. Run ``./tools/testing/kunit/kunit.py run`` with the ``--raw_output``74   parameter. This might show details or error messages hidden by the kunit_tool75   parser.762. Instead of running ``kunit.py run``, try running ``kunit.py config``,77   ``kunit.py build``, and ``kunit.py exec`` independently. This can help track78   down where an issue is occurring. (If you think the parser is at fault, you79   can run it manually against ``stdin`` or a file with ``kunit.py parse``.)803. Running the UML kernel directly can often reveal issues or error messages,81   ``kunit_tool`` ignores. This should be as simple as running ``./vmlinux``82   after building the UML kernel (for example, by using ``kunit.py build``).83   Note that UML has some unusual requirements (such as the host having a tmpfs84   filesystem mounted), and has had issues in the past when built statically and85   the host has KASLR enabled. (On older host kernels, you may need to run86   ``setarch `uname -m` -R ./vmlinux`` to disable KASLR.)874. Make sure the kernel .config has ``CONFIG_KUNIT=y`` and at least one test88   (e.g. ``CONFIG_KUNIT_EXAMPLE_TEST=y``). kunit_tool will keep its .config89   around, so you can see what config was used after running ``kunit.py run``.90   It also preserves any config changes you might make, so you can91   enable/disable things with ``make ARCH=um menuconfig`` or similar, and then92   re-run kunit_tool.935. Try to run ``make ARCH=um defconfig`` before running ``kunit.py run``. This94   may help clean up any residual config items which could be causing problems.956. Finally, try running KUnit outside UML. KUnit and KUnit tests can be96   built into any kernel, or can be built as a module and loaded at runtime.97   Doing so should allow you to determine if UML is causing the issue you're98   seeing. When tests are built-in, they will execute when the kernel boots, and99   modules will automatically execute associated tests when loaded. Test results100   can be collected from ``/sys/kernel/debug/kunit/<test suite>/results``, and101   can be parsed with ``kunit.py parse``. For more details, see :ref:`kunit-on-qemu`.102 103If none of the above tricks help, you are always welcome to email any issues to104kunit-dev@googlegroups.com.105