forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explain how to run unit tests and documentation tests. Note that the documentation uses "--arch=x86_64" to run KUnit tests because UML is not working at the moment [1]. [1] #881 Signed-off-by: José Expósito <[email protected]>
- Loading branch information
1 parent
da1e6a1
commit f5ea626
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
Unit Testing | ||
============ | ||
|
||
Like in any other Rust project it is possible to write and run unit tests and | ||
documentation tests in the kernel. | ||
|
||
Running Unit Tests | ||
------------------ | ||
|
||
Unit tests in the kernel are identical to user-space Rust tests: | ||
|
||
.. code-block:: rust | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
let result = 2 + 2; | ||
assert_eq!(result, 4); | ||
} | ||
} | ||
And can be run using the ``rusttest`` Make target: | ||
|
||
.. code-block:: bash | ||
$ make LLVM=1 rusttest | ||
Running Documentation Tests | ||
--------------------------- | ||
|
||
Like in user-space, it is possible to write documentation tests: | ||
|
||
.. code-block:: rust | ||
/// ``` | ||
/// let result = 2 + 2; | ||
/// assert_eq!(result, 4); | ||
/// ``` | ||
Documentation tests use KUnit and, thanks to the configuration file present in | ||
``rust/.kunitconfig``, it is possible to run them using the ``kunit.py`` tool: | ||
|
||
.. code-block:: bash | ||
$ ./tools/testing/kunit/kunit.py run --kunitconfig=rust \ | ||
--make_options LLVM=1 --arch=x86_64 |