Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasmtime: Introduce the test-macros crate #8622

Merged
merged 6 commits into from
May 28, 2024

Conversation

saulecabrera
Copy link
Member

@saulecabrera saulecabrera commented May 15, 2024

This commit introduces the test-macros crate. The whole idea behind this crate is to export a single or multiple macros to make it easier to configure Wasmtime for integration tests. The main use-case at this time, is running a subset of the integration tests with Cranelift and Winch. This crate could be extended to serve other use-cases, like testing pooling allocator and/or GC configurations.

This commit introduces a single example of how this macro could be used. If there's agreement on merging this change in some shape or form, I'll follow up with migrating the current tests to use #[wasmtime_test] where applicable.

Part of what's implemented in this PR was discussed in Cranelift's meeting on April 24th, 2024, however there are several discussion points that are still "in the air", like for example, what's the best way to avoid the combinatorial explosion problem for the potential test matrix.

--

cc/ @alexcrichton @fitzgen I'm opening this a draft, but feel free to leave any feedback according the discussion in the Cranelift meeting. I'm a bit concerned because I don't really have a good answer to the combinatorial problem of the test matrix, at least initially I suspect this won't be an issue necessarily, but if this macro grows in functionality I think it might be a problem.

This commit introduces the `test-macros` crate. The whole idea behind this crate is to export a single or multiple macros to make it easier to configure Wasmtime for integration tests. The main use-case at this time, is running a subset of the integration tests with Cranelift and Winch. This crate could be extended to serve other use-cases, like testing pooling allocator and/or GC configurations.  

This commit introduces a single example of how this macro could be used. If there's agreement on merging this change in some shape or form, I'll follow up with migrating the current tests to use `#[wasmtime_test]` where applicable. 

Part of what's implemented in this PR was discussed in Cranelift's meeting on [April 24th, 2024](https://github.com/bytecodealliance/meetings/blob/main/cranelift/2024/cranelift-04-24.md), however there are several discussion points that are still "in the air", like for example, what's the best way to avoid the combinatorial explosion problem for the potential test matrix.
@fitzgen
Copy link
Member

fitzgen commented May 15, 2024

Excited for this! Will take a look today

crates/test-macros/Cargo.toml Outdated Show resolved Hide resolved
crates/test-macros/src/lib.rs Outdated Show resolved Hide resolved

parse_macro_input!(attrs with parser);

match expand(&strategies, parse_macro_input!(item as ItemFn)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible concern about ItemFn here is that in the limit the entire test crate will be tagged with #[wasmtime_test] and that means the entire crate is parsed through syn and emitted back out. Technically the only needed part here is the function signature.

I'm not sure if it's worth it, but this could try to be a bit clever where it parses syn::ItemFn manually up to the block and then keeps the block as an opaque TokenStream (since it's known that it's brace-delimited anyway).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Took me a bit to figure out, but I was able to make this idea work by introducing a partial function parser as per your suggestion. Let me know what you think!

crates/test-macros/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely going in a good direction!

Cargo.toml Outdated Show resolved Hide resolved
Comment on lines +8 to +10
#[wasmtime_test(strategies(Cranelift, Winch))]
#[cfg_attr(miri, ignore)]
fn call_wasm_to_wasm() -> Result<()> {
fn call_wasm_to_wasm(config: &mut Config) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is exactly what I was imagining usage would look like 👍

- Fix version
- Add `[lints]`
- Add publish key
This commit adds a `TestConfig` struct that holds the supported Wasmtime
test configuration. Additonally this commit introduces a partial
function parser, in which only the attributes, visibility, and signature
are fully parsed, leaving the function body as an opaque `TokenStream`
@saulecabrera saulecabrera marked this pull request as ready for review May 24, 2024 18:54
@saulecabrera saulecabrera requested review from a team as code owners May 24, 2024 18:54
@saulecabrera saulecabrera requested review from pchickey and removed request for a team May 24, 2024 18:54
@saulecabrera
Copy link
Member Author

saulecabrera commented May 24, 2024

Thanks for the reviews Alex and Nick. I've addressed all the comments, I think this is ready for another round of reviews.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thanks!

I'm going to go ahead and merge, but some other assorted thoughts (which are fine as follow-ups or to ignore entirely):

  • Should the default perhaps be the "full matrix" of tests? For example pooling, default settings (cranelift), and winch might be the three main configurations to execute in right now.
  • Instead of opting-in to strategy should the attributes be "skip this test on winch" or similar? (e.g. eagerly running all tests instead of having to opt-in to testing)

In any case it might make more sense to expand the current strategy implemented and see how it looks after?

@alexcrichton alexcrichton added this pull request to the merge queue May 28, 2024
Merged via the queue into bytecodealliance:main with commit f0845e5 May 28, 2024
36 checks passed
@saulecabrera saulecabrera deleted the add-test-macros branch May 28, 2024 23:00
@saulecabrera
Copy link
Member Author

Those are good suggestions Alex, I like the idea of opting out instead of opting in, it has the potential to make the macro less verbose and easier to integrate. I'll start migrating the tests and see how things shape up and update the macro definition if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants