[PATCH 0/2] rust: add Derive macro unit tests

Manos Pitsidianakis posted 2 patches 5 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250704-rust._5Fadd._5Fderive._5Fmacro._5Funit._5Ftests-v1-0-ebd47fa7f78f@linaro.org
Maintainers: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
rust/qemu-api-macros/meson.build  |   3 +
rust/qemu-api-macros/src/lib.rs   |   7 +-
rust/qemu-api-macros/src/tests.rs | 135 ++++++++++++++++++++++++++++++++++++++
rust/qemu-api-macros/src/utils.rs |   1 +
4 files changed, 144 insertions(+), 2 deletions(-)
[PATCH 0/2] rust: add Derive macro unit tests
Posted by Manos Pitsidianakis 5 months, 1 week ago
We don't currently test our proc macros and it'd be nice to do so.

Usually this would be done with something like
https://crates.io/crates/trybuild which runs cargo and tries to compile
a test input, and checks for success/failure. However we cannot use it
with meson directly, plus it would drag in a lot of dependencies anyway.

Instead of compiling, we can easily just expand test input into token
streams since we already split macro implementation into separate
functions, allowing us to either get a TokenStream back or a compile
error message.

You can run the added tests directly with this meson command:

  meson test rust-qemu-api-macros-tests

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
Manos Pitsidianakis (2):
      rust/qemu-api-macros: normalize TryInto output
      rust/qemu-api-macros: add unit tests

 rust/qemu-api-macros/meson.build  |   3 +
 rust/qemu-api-macros/src/lib.rs   |   7 +-
 rust/qemu-api-macros/src/tests.rs | 135 ++++++++++++++++++++++++++++++++++++++
 rust/qemu-api-macros/src/utils.rs |   1 +
 4 files changed, 144 insertions(+), 2 deletions(-)
---
base-commit: c77283dd5d79149f4e7e9edd00f65416c648ee59
change-id: 20250704-rust_add_derive_macro_unit_tests-3e7daf905d62

--
γαῖα πυρί μιχθήτω


Re: [PATCH 0/2] rust: add Derive macro unit tests
Posted by Paolo Bonzini 5 months, 1 week ago
On 7/4/25 12:26, Manos Pitsidianakis wrote:
> We don't currently test our proc macros and it'd be nice to do so.
> 
> Usually this would be done with something like
> https://crates.io/crates/trybuild which runs cargo and tries to compile
> a test input, and checks for success/failure. However we cannot use it
> with meson directly, plus it would drag in a lot of dependencies anyway.
> 
> Instead of compiling, we can easily just expand test input into token
> streams since we already split macro implementation into separate
> functions, allowing us to either get a TokenStream back or a compile
> error message.
> 
> You can run the added tests directly with this meson command:
> 
>    meson test rust-qemu-api-macros-tests
> 
> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>

Nice.  Adjusted for MacroError removal and applied, thanks.

Paolo
Re: [PATCH 0/2] rust: add Derive macro unit tests
Posted by Zhao Liu 5 months, 1 week ago
> You can run the added tests directly with this meson command:
> 
>   meson test rust-qemu-api-macros-tests

Hi Manos, do you meet this error:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mesonbuild/mesonmain.py", line 146, in run
    return options.run_func(options)
  File "/usr/lib/python3/dist-packages/mesonbuild/mtest.py", line 2004, in run
    b = build.load(options.wd)
  File "/usr/lib/python3/dist-packages/mesonbuild/build.py", line 2868, in load
    obj = pickle.load(f)
ModuleNotFoundError: No module named 'mesonbuild.options'

ERROR: Unhandled python exception

    This is a Meson bug and should be reported!
---

But I've tested this series via `make check`.
Re: [PATCH 0/2] rust: add Derive macro unit tests
Posted by Manos Pitsidianakis 5 months, 1 week ago
On Fri, Jul 4, 2025 at 3:14 PM Zhao Liu <zhao1.liu@intel.com> wrote:
>
> > You can run the added tests directly with this meson command:
> >
> >   meson test rust-qemu-api-macros-tests
>
> Hi Manos, do you meet this error:
>
> Traceback (most recent call last):
>   File "/usr/lib/python3/dist-packages/mesonbuild/mesonmain.py", line 146, in run
>     return options.run_func(options)
>   File "/usr/lib/python3/dist-packages/mesonbuild/mtest.py", line 2004, in run
>     b = build.load(options.wd)
>   File "/usr/lib/python3/dist-packages/mesonbuild/build.py", line 2868, in load
>     obj = pickle.load(f)
> ModuleNotFoundError: No module named 'mesonbuild.options'
>
> ERROR: Unhandled python exception
>
>     This is a Meson bug and should be reported!
> ---
>
> But I've tested this series via `make check`.
>
>
>
>

Sounds like it used your global meson installation instead of the one
from the virtual environment of your build directory.

Thank you for testing!

-- 
Manos Pitsidianakis
Emulation and Virtualization Engineer at Linaro Ltd