rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: "David Gow" <davidgow@google.com>,
	"José Expósito" <jose.exposito89@gmail.com>
Cc: "Brendan Higgins" <brendan.higgins@linux.dev>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] rust: macros: add macro to easily run KUnit tests
Date: Tue, 1 Aug 2023 16:44:32 +0200	[thread overview]
Message-ID: <CANiq72mJjB_ubHx-y316o7b0KNjdHOrA9Wz0ievRvoTi1jVR5A@mail.gmail.com> (raw)
In-Reply-To: <20230720-rustbind-v1-2-c80db349e3b5@google.com>

On Thu, Jul 20, 2023 at 8:40 AM David Gow <davidgow@google.com> wrote:
>
> The only difference with user-space tests is that instead of using
> `#[cfg(test)]`, `#[kunit_tests(kunit_test_suit_name)]` is used.

I may be missing something, but this does not appear to map the
`assert*!`s to the KUnit APIs, is that correct? (i.e. like we do for
`rustdoc`-tests).

I made an assertion fail, and it seems to use the standard library
macros, thus panicking and ending up in `BUG()` (rather than a failed
test):

    rust_kernel: panicked at 'assertion failed: `(left == right)`
      left: `true`,
     right: `false`', rust/kernel/kunit.rs:329:1
    ------------[ cut here ]------------
    kernel BUG at rust/helpers.c:34!

Then the test times out eventually and things break:

        # rust_test_kunit_kunit_tests: try timed out
    ------------[ cut here ]------------
    refcount_t: addition on 0; use-after-free.

> +    // Add `#[cfg(CONFIG_KUNIT)]` before the module declaration.
> +    let config_kunit = "#[cfg(CONFIG_KUNIT)]".to_owned().parse().unwrap();
> +    tokens.insert(
> +        0,
> +        TokenTree::Group(Group::new(Delimiter::None, config_kunit)),
> +    );

I wonder about compile-time here with this approach. As far as I
understand, having the `cfg` explicitly outside the proc macro would
avoid invoking it.

Do we know the potential compile-time impact, especially when we will
have many tests?
ventually it would be ideal to have an approach closer to the
`rustdoc` one, where the compiler finds the tests for us and we
generate the needed code in the build system, i.e. outside a proc
macro.

Cheers,
Miguel

  parent reply	other threads:[~2023-08-01 14:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  6:38 [PATCH 0/3] rust: kunit: Support KUnit tests with a user-space like syntax David Gow
2023-07-20  6:38 ` [PATCH 1/3] rust: kunit: add KUnit case and suite macros David Gow
2023-07-25 18:07   ` Boqun Feng
2023-07-20  6:38 ` [PATCH 2/3] rust: macros: add macro to easily run KUnit tests David Gow
2023-07-30 21:49   ` Boqun Feng
2023-08-01 14:44   ` Miguel Ojeda [this message]
2023-07-20  6:38 ` [PATCH 3/3] rust: kunit: allow to know if we are in a test David Gow
2023-07-25 23:34   ` Boqun Feng

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=CANiq72mJjB_ubHx-y316o7b0KNjdHOrA9Wz0ievRvoTi1jVR5A@mail.gmail.com \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=gary@garyguo.net \
    --cc=jose.exposito89@gmail.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).