Skip to content

Add a disas test suite for Wasmtime#8129

Merged
alexcrichton merged 4 commits into
bytecodealliance:mainfrom
alexcrichton:test-wasmtime-codegen
Mar 14, 2024
Merged

Add a disas test suite for Wasmtime#8129
alexcrichton merged 4 commits into
bytecodealliance:mainfrom
alexcrichton:test-wasmtime-codegen

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton commented Mar 14, 2024

This commit adds a suite of tests at tests/disas/*.wat which is intended to replace the tests in cranelift/filetests/filetests/wasm. Tests are configured differently than before using Wasmtime CLI flags rather than a custom TOML-based configuration scheme. Otherwise though the same shape of tests is supported.

This commit migrates a small handful of tests as a showcase and bulk migration is left for a follow-up.

This commit adds a suite of tests at `tests/asm/*.wat` which is intended
to replace the tests in `cranelift/filetests/filetests/wasm`. Tests are
configured differently than before using Wasmtime CLI flags rather than
a custom TOML-based configuration scheme. Otherwise though the same
shape of tests is supported.

This commit migrates a small handful of tests as a showcase and bulk
migration is left for a follow-up.
@alexcrichton alexcrichton requested review from a team as code owners March 14, 2024 03:04
@alexcrichton alexcrichton requested review from fitzgen and jameysharp and removed request for a team March 14, 2024 03:04
@alexcrichton
Copy link
Copy Markdown
Member Author

This was inspired by #8125 and the discussion there

@github-actions github-actions Bot added the cranelift Issues related to the Cranelift code generator label Mar 14, 2024
Copy link
Copy Markdown
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.

Instead of tests/asm maybe we should call this tests/dis or tests/disas since there are CLIF "disassemblies" in there too?

Comment thread tests/asm.rs Outdated
Comment on lines +106 to +136
for line in contents.lines() {
let directive = match line.strip_prefix(";;!") {
Some("") | None => continue,
Some(s) => s.trim(),
};
if directive == "compile" {
compile = true;
continue;
}
if directive == "optimize" {
optimize = true;
continue;
}
if let Some(s) = directive.strip_prefix("flags: ") {
flags.extend(
s.split_whitespace()
.filter(|s| !s.is_empty())
.map(|s| s.to_string()),
);
continue;
}
if let Some(s) = directive.strip_prefix("target: ") {
if target.is_some() {
bail!("two targets have been specified");
}
target = Some(s);
continue;
}

bail!("unknown directive: {directive}");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we avoid manual parsing and do the TOML thing like the other tests? Can still use exact CLI flags by having the toml just contain a string of CLI flags for that particular setting.

But manual parsing is just annoying to extend down the line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was actually hoping we could skip TOML entirely since that felt heavyweight enough to justify with custom heaps/tables but with just a few booleans and such it feels sort of overkill. For example it feels overly verbose to do:

;;! flags = ["-Oopt-level=s", "-Ccranelift-has-avx"]

as opposed to:

;;! flags: -O opt-level=s -C cranelift-has-avx

I don't necessarily have a great feeling for how extensible we want this to be down the line though. I was sort of also taking inspiration from compiletest-based tests in rust-lang/rust, but I know the parsing there is sort of gnarly nowadays given all the directives it supports.

Copy link
Copy Markdown
Member

@fitzgen fitzgen Mar 14, 2024

Choose a reason for hiding this comment

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

I was thinking we would have a single string for all CLI flags rather than an array of strings of individual flags, which should make it a little less verbose:

;;! flags: "-O opt-level=s -C cranelift-has-avx"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was sort of also taking inspiration from compiletest-based tests in rust-lang/rust, but I know the parsing there is sort of gnarly nowadays given all the directives it supports.

Yeah this is the kind of thing I am afraid of

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, I've switched back to TOML

@alexcrichton alexcrichton changed the title Add an asm test suite for Wasmtime Add a disas test suite for Wasmtime Mar 14, 2024
@alexcrichton alexcrichton added this pull request to the merge queue Mar 14, 2024
github-merge-queue Bot pushed a commit that referenced this pull request Mar 14, 2024
* Add an `asm` test suite for Wasmtime

This commit adds a suite of tests at `tests/asm/*.wat` which is intended
to replace the tests in `cranelift/filetests/filetests/wasm`. Tests are
configured differently than before using Wasmtime CLI flags rather than
a custom TOML-based configuration scheme. Otherwise though the same
shape of tests is supported.

This commit migrates a small handful of tests as a showcase and bulk
migration is left for a follow-up.

* Organize the asm.rs test with methods/functions

* Switch back to TOML for config parsing
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 14, 2024
Takes a bit too long in cranelift
@alexcrichton alexcrichton enabled auto-merge March 14, 2024 19:55
@alexcrichton alexcrichton added this pull request to the merge queue Mar 14, 2024
Merged via the queue into bytecodealliance:main with commit b2c28ba Mar 14, 2024
@alexcrichton alexcrichton deleted the test-wasmtime-codegen branch March 14, 2024 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants