From: Gary Guo <gary@garyguo.net>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Brendan Higgins" <brendan.higgins@linux.dev>,
"David Gow" <david@davidgow.net>,
"Rae Moar" <raemoar63@gmail.com>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
Gary Guo <gary@garyguo.net>
Subject: [PATCH v2 0/3] rust: doctest: unify with other kunit tests
Date: Wed, 02 Sep 2026 22:59:58 +0100 [thread overview]
Message-ID: <20260902-kunit-v2-0-eda3ed6c00c5@garyguo.net> (raw)
Currently in Rust, kunit tests are handled with `kunit_tests`, while the
doctests generate a lot `extern "C"` functions and invoke them through a
generated C wrapper.
This is currently needed because of the special treatment of file name and
line numbers from doctests. Convert them to override `file!()` and
`line!()` macro instead, and use them inside `kunit_assert!`.
With this it is possible to just generate `#[kunit_tests]` and `#[test]`
for doctests.
David mentioned in [1] that this should route via the Rust tree.
Link: https://lore.kernel.org/rust-for-linux/e30d16ec-f5a3-4cd8-9b25-96e0dfa8b9d2@davidgow.net/ [1]
Signed-off-by: Gary Guo <gary@garyguo.net>
---
Changes in v2:
- Rebased on v7.3-rc1
- Picked up tags
- Link to v1: https://patch.msgid.link/20260616-kunit-v1-0-b191604a8d6b@garyguo.net
---
Gary Guo (3):
rust: kunit: use `file!()` inside `kunit_assert!`
rust: kunit: use `line!()` inside `kunit_assert!`
rust: doctest: generate Rust kunit test suites
Documentation/rust/general-information.rst | 4 +-
init/Kconfig | 3 --
rust/Makefile | 4 +-
rust/kernel/kunit.rs | 11 +++--
rust/kernel/str.rs | 2 +-
rust/macros/helpers.rs | 16 -------
rust/macros/kunit.rs | 5 +-
rust/macros/lib.rs | 5 --
scripts/rustdoc_test_gen.rs | 73 ++++++++----------------------
9 files changed, 30 insertions(+), 93 deletions(-)
---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260616-kunit-348f2c029b1e
Best regards,
--
Gary Guo <gary@garyguo.net>
next reply other threads:[~2026-09-02 22:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 21:59 Gary Guo [this message]
2026-09-02 21:59 ` [PATCH v2 1/3] rust: kunit: use `file!()` inside `kunit_assert!` Gary Guo
2026-09-02 22:00 ` [PATCH v2 2/3] rust: kunit: use `line!()` " Gary Guo
2026-09-02 22:00 ` [PATCH v2 3/3] rust: doctest: generate Rust kunit test suites Gary Guo
2026-09-03 12:50 ` [PATCH v2 0/3] rust: doctest: unify with other kunit tests David Gow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260902-kunit-v2-0-eda3ed6c00c5@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brendan.higgins@linux.dev \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=david@davidgow.net \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=raemoar63@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®