^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) =================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) kunit_tool How-To
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) =================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) What is kunit_tool?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) ===================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) kunit_tool is a script (``tools/testing/kunit/kunit.py``) that aids in building
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) the Linux kernel as UML (`User Mode Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) <http://user-mode-linux.sourceforge.net/>`_), running KUnit tests, parsing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) the test results and displaying them in a user friendly manner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) kunit_tool addresses the problem of being able to run tests without needing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) virtual machine or actual hardware with User Mode Linux. User Mode Linux is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) Linux architecture, like ARM or x86; however, unlike other architectures it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) compiles the kernel as a standalone Linux executable that can be run like any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) other program directly inside of a host operating system. To be clear, it does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) not require any virtualization support: it is just a regular program.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) What is a .kunitconfig?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) =======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) It's just a defconfig that kunit_tool looks for in the base directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) kunit_tool uses it to generate a .config as you might expect. In addition, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) verifies that the generated .config contains the CONFIG options in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) .kunitconfig; the reason it does this is so that it is easy to be sure that a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) CONFIG that enables a test actually ends up in the .config.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) How do I use kunit_tool?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) If a kunitconfig is present at the root directory, all you have to do is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .. code-block:: bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ./tools/testing/kunit/kunit.py run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) However, you most likely want to use it with the following options:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .. code-block:: bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) ./tools/testing/kunit/kunit.py run --timeout=30 --jobs=`nproc --all`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) - ``--timeout`` sets a maximum amount of time to allow tests to run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) - ``--jobs`` sets the number of threads to use to build the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) This command will work even without a .kunitconfig file: if no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .kunitconfig is present, a default one will be used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) For a list of all the flags supported by kunit_tool, you can run:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .. code-block:: bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ./tools/testing/kunit/kunit.py run --help