Lines Matching +full:test +full:- +full:docs

1 // SPDX-License-Identifier: GPL-2.0
3 //! KUnit-based macros for Rust unit tests.
5 //! C header: [`include/kunit/test.h`](srctree/include/kunit/test.h)
7 //! Reference: <https://docs.kernel.org/dev-tools/kunit/index.html>
15 /// Prints a KUnit error-level message.
20 // SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we
31 /// Prints a KUnit info-level message.
36 // SAFETY: The format string is null-terminated and the `%pA` specifier matches the argument we
64 static LINE: i32 = ::core::line!() as i32 - $diff;
70 // The assertion failed but this task is not running a KUnit test, so we cannot call
72 // macro is called from an spawned thread in a test (see
73 // `scripts/rustdoc_test_gen.rs`) or if some non-test code calls this macro by
85 " Failure not reported to KUnit since this is a non-KUnit task\n"
115 // - FFI call.
116 // - The `kunit_test` pointer is valid because we got it from
118 // test, and that the pointer can be passed to KUnit functions and assertions.
119 // - The string pointers (`file` and `condition` above) point to null-terminated
121 // - The function pointer (`format`) points to the proper function.
122 // - The pointers passed will remain valid since they point to `static`s.
123 // - The format string is allowed to be null.
124 // - There are, however, problems with this: first of all, this will end up stopping
129 // too. For the moment, given that test failures are reported immediately before the
130 // next test runs, that test failures should be fixed and that KUnit is explicitly
143 // SAFETY: FFI call; the `test` pointer is valid because this hidden macro should only
144 // be called by the generated documentation tests which forward the test pointer given
170 fn is_test_result_ok(&self) -> bool;
174 fn is_test_result_ok(&self) -> bool {
180 fn is_test_result_ok(&self) -> bool {
185 /// Returns whether a test result is to be considered OK.
190 pub fn is_test_result_ok(t: impl TestResult) -> bool {
194 /// Represents an individual test case.
196 /// The [`kunit_unsafe_test_suite!`] macro expects a NULL-terminated list of valid test cases.
202 ) -> kernel::bindings::kunit_case {
218 /// Represents the NULL test case delimiter.
220 /// The [`kunit_unsafe_test_suite!`] macro expects a NULL-terminated list of test cases. This
223 pub const fn kunit_case_null() -> kernel::bindings::kunit_case {
239 /// Registers a KUnit test suite.
243 /// `test_cases` must be a NULL terminated array of valid test cases,
244 /// whose lifetime is at least that of the test suite (i.e., static).
272 "The test suite name `",
322 /// Returns whether we are currently running a KUnit test.
324 /// In some cases, you need to call test-only code from outside the test case, for example, to
326 /// currently running a KUnit test or not.
330 /// This example shows how a function can be mocked to return a well-known value while testing:
334 /// fn fn_mock_example(n: i32) -> i32 {
345 pub fn in_kunit_test() -> bool {
355 #[test]
360 #[test]
365 #[test]
368 // This test should never run because of the `cfg`.