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

TOMOYO Linux Cross Reference
Linux/Documentation/dev-tools/kunit/architecture.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/architecture.rst (Version linux-6.12-rc7) and /Documentation/dev-tools/kunit/architecture.rst (Version linux-2.4.37.11)


  1 .. SPDX-License-Identifier: GPL-2.0               
  2                                                   
  3 ==================                                
  4 KUnit Architecture                                
  5 ==================                                
  6                                                   
  7 The KUnit architecture is divided into two par    
  8                                                   
  9 - `In-Kernel Testing Framework`_                  
 10 - `kunit_tool (Command-line Test Harness)`_       
 11                                                   
 12 In-Kernel Testing Framework                       
 13 ===========================                       
 14                                                   
 15 The kernel testing library supports KUnit test    
 16 KUnit. These KUnit tests are kernel code. KUni    
 17 tasks:                                            
 18                                                   
 19 - Organizes tests                                 
 20 - Reports test results                            
 21 - Provides test utilities                         
 22                                                   
 23 Test Cases                                        
 24 ----------                                        
 25                                                   
 26 The test case is the fundamental unit in KUnit    
 27 into suites. A KUnit test case is a function w    
 28 ``void (*)(struct kunit *test)``. These test c    
 29 struct called struct kunit_case.                  
 30                                                   
 31 .. note:                                          
 32         ``generate_params`` is optional for no    
 33                                                   
 34 Each KUnit test case receives a ``struct kunit    
 35 running test. The KUnit assertion macros and o    
 36 ``struct kunit`` context object. As an excepti    
 37                                                   
 38 - ``->priv``: The setup functions can use it t    
 39   user data.                                      
 40                                                   
 41 - ``->param_value``: It contains the parameter    
 42   retrieved in the parameterized tests.           
 43                                                   
 44 Test Suites                                       
 45 -----------                                       
 46                                                   
 47 A KUnit suite includes a collection of test ca    
 48 are represented by the ``struct kunit_suite``.    
 49                                                   
 50 .. code-block:: c                                 
 51                                                   
 52         static struct kunit_case example_test_    
 53                 KUNIT_CASE(example_test_foo),     
 54                 KUNIT_CASE(example_test_bar),     
 55                 KUNIT_CASE(example_test_baz),     
 56                 {}                                
 57         };                                        
 58                                                   
 59         static struct kunit_suite example_test    
 60                 .name = "example",                
 61                 .init = example_test_init,        
 62                 .exit = example_test_exit,        
 63                 .test_cases = example_test_cas    
 64         };                                        
 65         kunit_test_suite(example_test_suite);     
 66                                                   
 67 In the above example, the test suite ``example    
 68 test cases ``example_test_foo``, ``example_tes    
 69 ``example_test_baz``. Before running the test,    
 70 is called and after running the test, ``exampl    
 71 The ``kunit_test_suite(example_test_suite)`` r    
 72 with the KUnit test framework.                    
 73                                                   
 74 Executor                                          
 75 --------                                          
 76                                                   
 77 The KUnit executor can list and run built-in K    
 78 The Test suites are stored in a linker section    
 79 called ``.kunit_test_suites``. For the code, s    
 80 definition in                                     
 81 `include/asm-generic/vmlinux.lds.h <https://gi    
 82 The linker section consists of an array of poi    
 83 ``struct kunit_suite``, and is populated by th    
 84 macro. The KUnit executor iterates over the li    
 85 run all the tests that are compiled into the k    
 86                                                   
 87 .. kernel-figure:: kunit_suitememorydiagram.sv    
 88         :alt:   KUnit Suite Memory                
 89                                                   
 90         KUnit Suite Memory Diagram                
 91                                                   
 92 On the kernel boot, the KUnit executor uses th    
 93 of this section to iterate over and run all te    
 94 executor, see                                     
 95 `lib/kunit/executor.c <https://git.kernel.org/    
 96 When built as a module, the ``kunit_test_suite    
 97 ``module_init()`` function, which runs all the    
 98 unit instead of utilizing the executor.           
 99                                                   
100 In KUnit tests, some error classes do not affe    
101 or parts of the kernel, each KUnit case execut    
102 context. See the ``kunit_try_catch_run()`` fun    
103 `lib/kunit/try-catch.c <https://git.kernel.org    
104                                                   
105 Assertion Macros                                  
106 ----------------                                  
107                                                   
108 KUnit tests verify state using expectations/as    
109 All expectations/assertions are formatted as:     
110 ``KUNIT_{EXPECT|ASSERT}_<op>[_MSG](kunit, prop    
111                                                   
112 - ``{EXPECT|ASSERT}`` determines whether the c    
113   expectation.                                    
114   In the event of a failure, the testing flow     
115                                                   
116         - For expectations, the test is marked    
117                                                   
118         - Failing assertions, on the other han    
119           terminated immediately.                 
120                                                   
121                 - Assertions call the function    
122                   ``void __noreturn __kunit_ab    
123                                                   
124                 - ``__kunit_abort`` calls the     
125                   ``void __noreturn kunit_try_    
126                                                   
127                 - ``kunit_try_catch_throw`` ca    
128                   ``void kthread_complete_and_    
129                   and terminates the special t    
130                                                   
131 - ``<op>`` denotes a check with options: ``TRU    
132   has the boolean value "true"), ``EQ`` (two s    
133   equal), ``NOT_ERR_OR_NULL`` (supplied pointe    
134   contain an "err" value).                        
135                                                   
136 - ``[_MSG]`` prints a custom message on failur    
137                                                   
138 Test Result Reporting                             
139 ---------------------                             
140 KUnit prints the test results in KTAP format.     
141 Documentation/dev-tools/ktap.rst.                 
142 KTAP works with KUnit and Kselftest. The KUnit    
143 dmesg, and debugfs (if configured).               
144                                                   
145 Parameterized Tests                               
146 -------------------                               
147                                                   
148 Each KUnit parameterized test is associated wi    
149 parameters. The test is invoked multiple times    
150 value and the parameter is stored in the ``par    
151 The test case includes a KUNIT_CASE_PARAM() ma    
152 generator function. The generator function is     
153 and returns the next parameter. It also includ    
154 array-based common-case generators.               
155                                                   
156 kunit_tool (Command-line Test Harness)            
157 ======================================            
158                                                   
159 ``kunit_tool`` is a Python script, found in ``    
160 is used to configure, build, execute, parse te    
161 previous commands in correct order (i.e., conf    
162 You have two options for running KUnit tests:     
163 enabled and manually parse the results (see       
164 Documentation/dev-tools/kunit/run_manual.rst)     
165 (see Documentation/dev-tools/kunit/run_wrapper    
166                                                   
167 - ``configure`` command generates the kernel `    
168   ``.kunitconfig`` file (and any architecture-    
169   The Python scripts available in ``qemu_confi    
170   (for example, ``tools/testing/kunit/qemu con    
171   additional configuration options for specifi    
172   It parses both the existing ``.config`` and     
173   to ensure that ``.config`` is a superset of     
174   If not, it will combine the two and run ``ma    
175   the ``.config`` file. It then checks to see     
176   This verifies that all the Kconfig dependenc    
177   file ``.kunitconfig``. The ``kunit_config.py    
178   Kconfigs. The code which runs ``make olddefc    
179   ``kunit_kernel.py`` script. You can invoke t    
180   ``./tools/testing/kunit/kunit.py config`` an    
181   generate a ``.config`` file.                    
182 - ``build`` runs ``make`` on the kernel tree w    
183   (depends on the architecture and some option    
184   and reports any errors.                         
185   To build a KUnit kernel from the current ``.    
186   ``build`` argument: ``./tools/testing/kunit/    
187 - ``exec`` command executes kernel results eit    
188   User-mode Linux configuration), or through a    
189   as QEMU. It reads results from the log using    
190   output (stdout), and passes them to ``parse`    
191   If you already have built a kernel with buil    
192   you can run the kernel and display the test     
193   argument: ``./tools/testing/kunit/kunit.py e    
194 - ``parse`` extracts the KTAP output from a ke    
195   the test results, and prints a summary. For     
196   diagnostic output will be included.             
                                                      

~ [ 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