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