From 3504d1bce9920b23499ab1af682cdf1eceba7c75 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 2 Sep 2026 22:59:59 +0100 Subject: rust: kunit: use `file!()` inside `kunit_assert!` This parameter is needed currently because doctests want to override the file. Simplify it by changing it to use `file!()`. Have doctests override `file!()` macro to achieve the current behavior. This allows us to remove the `file` helper and associated Kconfig options. Reviewed-by: David Gow Signed-off-by: Gary Guo Link: https://patch.msgid.link/20260902-kunit-v2-1-eda3ed6c00c5@garyguo.net Signed-off-by: Miguel Ojeda --- scripts/rustdoc_test_gen.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/rustdoc_test_gen.rs b/scripts/rustdoc_test_gen.rs index d087c0d9fcb3..bb57745ec339 100644 --- a/scripts/rustdoc_test_gen.rs +++ b/scripts/rustdoc_test_gen.rs @@ -176,12 +176,18 @@ fn main() { r#"/// Generated `{name}` KUnit test case from a Rust documentation test. #[no_mangle] pub extern "C" fn {kunit_name}(__kunit_test: *mut ::kernel::bindings::kunit) {{ + /// Overrides the usual [`file!`] macro with one that expands to the real path. + #[allow(unused)] + macro_rules! file {{ + () => {{ "{real_path}" }} + }} + /// Overrides the usual [`assert!`] macro with one that calls KUnit instead. #[allow(unused)] macro_rules! assert {{ ($cond:expr $(,)?) => {{{{ ::kernel::kunit_assert!( - "{kunit_name}", c"{real_path}", __DOCTEST_ANCHOR - {line}, $cond + "{kunit_name}", __DOCTEST_ANCHOR - {line}, $cond ); }}}} }} @@ -191,7 +197,7 @@ pub extern "C" fn {kunit_name}(__kunit_test: *mut ::kernel::bindings::kunit) {{ macro_rules! assert_eq {{ ($left:expr, $right:expr $(,)?) => {{{{ ::kernel::kunit_assert_eq!( - "{kunit_name}", c"{real_path}", __DOCTEST_ANCHOR - {line}, $left, $right + "{kunit_name}", __DOCTEST_ANCHOR - {line}, $left, $right ); }}}} }} -- cgit v1.2.3