Skip to content

Commit

Permalink
cranelift-wasm: Remove wasmtests test suite
Browse files Browse the repository at this point in the history
The cranelift/wasm/wasmtests suite verifies that the given WebAssembly
modules compile without errors using cranelift-wasm's DummyEnvironment.

That environment is not particularly representative of how we actually
compile WebAssembly modules in Wasmtime, so it's better to perform these
tests in Wasmtime itself.

The rust_fannkuch test can move to Wasmtime's misc test suite because it
can be both compiled and instantiated without any extra setup. This
tests more than was tested in cranelift-wasm, which didn't try to
instantiate the module. By moving it to a wast test we could also choose
to add assertions about the execution of this module, but I don't think
that's necessary.

I'm just deleting the embenchen tests because they can't be instantiated
without setting up a bunch of imports, and it's not clear to me that
testing that they can be compiled offers any value for helping us find
bugs or regressions.

Finally, I'm also deleting the test case which was extracted from a fuzz
bug in 2019, before Cranelift was merged into the Wasmtime repo:
bytecodealliance/cranelift#1306

That test is interesting, but running it here only tests code in
DummyEnvironment, not anything reachable from Wasmtime. There was a
report of exactly the same bug in Wasmtime two years later, and the fix
included tests in tests/misc_testsuite/empty.wast to cover this case.
bytecodealliance#3509

The `empty.wast` test is better than this one because it has minimal and
well-commented binary modules which I've verified still trigger the same
bug if the fix is reverted. By contrast, since this older test was
produced by a fuzzer, it is larger than necessary and the end of its
name section is malformed and unparseable.
  • Loading branch information
jameysharp committed Mar 15, 2024
1 parent b0f13dc commit 0aad19c
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 46,987 deletions.
1 change: 0 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

"cranelift:wasm":
- "cranelift/wasm/**"
- "cranelift/wasmtests/**"

"fuzzing":
- "crates/fuzzing/**"
Expand Down
60 changes: 0 additions & 60 deletions cranelift/wasm/tests/wasm_testsuite.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
use cranelift_codegen::isa::{CallConv, TargetFrontendConfig};
use cranelift_codegen::print_errors::pretty_verifier_error;
use cranelift_codegen::settings::{self, Flags};
use cranelift_codegen::verifier;
use cranelift_wasm::{translate_module, DummyEnvironment, FuncIndex};
use std::fs;
use std::path::Path;
use target_lexicon::PointerWidth;

#[test]
fn testsuite() {
let mut paths: Vec<_> = fs::read_dir("./wasmtests")
.unwrap()
.map(|r| r.unwrap())
.filter(|p| {
// Ignore files starting with `.`, which could be editor temporary files
if let Some(stem) = p.path().file_stem() {
if let Some(stemstr) = stem.to_str() {
return !stemstr.starts_with('.');
}
}
false
})
.collect();
paths.sort_by_key(|dir| dir.path());
let flags = Flags::new(settings::builder());
for path in paths {
let path = path.path();
println!("=== {} ===", path.display());
let data = read_module(&path);
handle_module(data, &flags);
}
}

#[test]
fn use_name_section() {
let data = wat::parse_str(
Expand All @@ -56,36 +26,6 @@ fn use_name_section() {
);
}

fn read_module(path: &Path) -> Vec<u8> {
match path.extension() {
None => {
panic!("the file extension is not wasm or wat");
}
Some(ext) => match ext.to_str() {
Some("wasm") => std::fs::read(path).expect("error reading wasm file"),
Some("wat") => wat::parse_file(path)
.map_err(|e| e.to_string())
.expect("failed to parse wat"),
None | Some(&_) => panic!("the file extension for {:?} is not wasm or wat", path),
},
}
}

fn handle_module(data: Vec<u8>, flags: &Flags) {
let mut dummy_environ = DummyEnvironment::new(TargetFrontendConfig {
default_call_conv: CallConv::SystemV,
pointer_width: PointerWidth::U64,
});

translate_module(&data, &mut dummy_environ).unwrap();

for func in dummy_environ.info.function_bodies.values() {
verifier::verify_function(func, flags)
.map_err(|errors| panic!("{}", pretty_verifier_error(func, None, errors)))
.unwrap();
}
}

#[test]
fn reachability_is_correct() {
let tests = vec![
Expand Down
Loading

0 comments on commit 0aad19c

Please sign in to comment.