Skip to content

Commit

Permalink
docs: rust: document automated testing
Browse files Browse the repository at this point in the history
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
JoseExposito committed Dec 7, 2022
1 parent 6074e8f commit f60d3c4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions Documentation/rust/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ in the kernel, please read the quick-start.rst guide.
general-information
coding-guidelines
arch-support
testing

.. only:: subproject and html

Expand Down
52 changes: 52 additions & 0 deletions Documentation/rust/testing.rst
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.

0 comments on commit f60d3c4

Please sign in to comment.