forked from Rust-for-Linux/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: rust: document automated testing
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] Rust-for-Linux#881 Reviewed-by: David Gow <[email protected]> Signed-off-by: José Expósito <[email protected]>
- Loading branch information
1 parent
6074e8f
commit f60d3c4
Showing
2 changed files
with
53 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,52 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
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 it is possible to run them either on boot or | ||
using the ``kunit.py`` tool: | ||
|
||
.. code-block:: bash | ||
$ ./tools/testing/kunit/kunit.py run --kunitconfig=rust \ | ||
--make_options LLVM=1 --arch=x86_64 | ||
For general information about KUnit and `kunit.py``, please refer to | ||
Documentation/dev-tools/kunit/start.rst. |