Lines Matching +full:test +full:- +full:docs
1 .. SPDX-License-Identifier: GPL-2.0
6 This document contains useful information how to test the Rust code in the
11 - The KUnit tests.
12 - The ``#[test]`` tests.
13 - The Kselftests.
16 ---------------
27 ./tools/testing/kunit/kunit.py run --make_options LLVM=1 --arch x86_64 --kconfig_add CONFIG_RUST=y
29 Alternatively, KUnit can run them as kernel built-in at boot. Refer to
30 Documentation/dev-tools/kunit/index.rst for the general KUnit documentation
31 and Documentation/dev-tools/kunit/architecture.rst for the details of kernel
32 built-in vs. command line testing.
37 Kernel hacking -> Kernel Testing and Coverage -> KUnit - Enable support for unit tests
39 Kernel hacking -> Rust hacking -> Doctests for the `kernel` crate
52 .. code-block:: rust
59 pub fn f(a: i32, b: i32) -> i32 {
64 as-is would be useful already, since it allows verifying that examples compile
66 as running those that do not depend on in-kernel APIs.
68 For the kernel, however, these tests get transformed into KUnit test suites.
93 Tests using the `? <https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question…
96 .. code-block:: rust
109 location (file and line) of the original test (i.e. instead of the location in
120 addition, it may allow us to test third-party code more easily in the future.
131 https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
133 The ``#[test]`` tests
134 ---------------------
136 Additionally, there are the ``#[test]`` tests. Like for documentation tests,
141 the name of the test suite as an argument.
143 For instance, assume we want to test the function ``f`` from the documentation
146 .. code-block:: rust
152 #[test]
170 `? <https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator>`_
171 operator is supported, i.e. the test functions may return either nothing (i.e.
174 .. code-block:: rust
180 #[test]
181 fn test_g() -> Result {
188 If we run the test and the call to ``g`` fails, then the kernel log would show::
200 If a ``#[test]`` test could be useful as an example for the user, then please
201 use a documentation test instead. Even edge cases of an API, e.g. error or
205 ---------------------------
217 --------------
235 Refer to Documentation/dev-tools/kselftest.rst for the general Kselftest