lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CABVgOS==nuX4RUv8XHoexxwo9bJr28OSDZLJzFjXtCNh7ew94w@mail.gmail.com>
Date: Fri, 1 Nov 2024 14:44:42 +0800
From: David Gow <davidgow@...gle.com>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, José Expósito <jose.exposito89@...il.com>, 
	Brendan Higgins <brendan.higgins@...ux.dev>, Rae Moar <rmoar@...gle.com>, 
	Alex Gaynor <alex.gaynor@...il.com>, Gary Guo <gary@...yguo.net>, 
	Benno Lossin <benno.lossin@...ton.me>, Björn Roy Baron <bjorn3_gh@...tonmail.com>, 
	Alice Ryhl <aliceryhl@...gle.com>, Matt Gilbride <mattgilbride@...gle.com>, 
	kunit-dev@...glegroups.com, linux-kselftest@...r.kernel.org, 
	rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 2/3] rust: macros: add macro to easily run KUnit tests

On Wed, 30 Oct 2024 at 13:11, Boqun Feng <boqun.feng@...il.com> wrote:
>
> On Wed, Oct 30, 2024 at 12:57:14PM +0800, David Gow wrote:
> > From: José Expósito <jose.exposito89@...il.com>
> > Add a new procedural macro (`#[kunit_tests(kunit_test_suit_name)]`) to
> > run KUnit tests using a user-space like syntax.
> >
> > The macro, that should be used on modules, transforms every `#[test]`
> > in a `kunit_case!` and adds a `kunit_unsafe_test_suite!` registering
> > all of them.
> >
> > The only difference with user-space tests is that instead of using
> > `#[cfg(test)]`, `#[kunit_tests(kunit_test_suit_name)]` is used.
> >
> > Note that `#[cfg(CONFIG_KUNIT)]` is added so the test module is not
> > compiled when `CONFIG_KUNIT` is set to `n`.
> >
> > Reviewed-by: David Gow <davidgow@...gle.com>
> > Signed-off-by: José Expósito <jose.exposito89@...il.com>
> > [Updated to use new const fn.]
> > Signed-off-by: David Gow <davidgow@...gle.com>
> > ---
> >
> > Changes since v2:
> > https://lore.kernel.org/linux-kselftest/20241029092422.2884505-3-davidgow@google.com/
> > - Include missing rust/macros/kunit.rs file from v2. (Thanks Boqun!)
> > - The proc macro now emits an error if the suite name is too long.
> >
> > Changes since v1:
> > https://lore.kernel.org/lkml/20230720-rustbind-v1-2-c80db349e3b5@google.com/
> > - Rebased on top of rust-next
> > - Make use of the new const functions, rather than the kunit_case!()
> >   macro.
> >
> > ---
> >  MAINTAINERS          |   1 +
> >  rust/kernel/kunit.rs |  11 ++++
> >  rust/macros/kunit.rs | 153 +++++++++++++++++++++++++++++++++++++++++++
> >  rust/macros/lib.rs   |  29 ++++++++
> >  4 files changed, 194 insertions(+)
> >  create mode 100644 rust/macros/kunit.rs
> >

(...snip...)

> > +    let new_body: TokenStream = vec![body.stream(), kunit_macros.parse().unwrap()]
> > +        .into_iter()
> > +        .collect();
> > +
> > +    // Remove the `#[test]` macros.
> > +    let new_body = new_body.to_string().replace("#[test]", "");
>
> Yeah, I want to see how you do it this time ;-) So if you do a
> `.to_string()` on a `TokenStream`, you lose all the span [1] information
> ("span information" is a term invited by me, hope I get it right ;-))
> e.g. if there is a compile error in the test code, the compiler cannot
> report the exact line of the error, it can only report there is an
> error.
>
> Last time I find how to preserve the Span:
>
>         https://lore.kernel.org/rust-for-linux/ZMba0_XXZuTgWyWY@boqun-archlinux/
>
> Hope it helps!
>
> [1]: https://doc.rust-lang.org/proc_macro/struct.Span.html
>
> Regards,
> Boqun

Thanks. I managed to get this working, but just ended up with an
uglier version of your change, so I've copied it in and added you as a
co-developer for this patch in v4.

It made clippy catch a couple of warnings in the example tests, too,
so it's clearly working well.

Cheers,
-- David

Download attachment "smime.p7s" of type "application/pkcs7-signature" (5294 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ