Skip to content

Commit

Permalink
fixup! tests: add tests/spec_testsuite/proposals/threads
Browse files Browse the repository at this point in the history
Signed-off-by: Harald Hoyer <[email protected]>
  • Loading branch information
haraldh committed Nov 20, 2022
1 parent a2dca4d commit a04786d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 59 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ wasmtime-wast = { workspace = true, features = ['component-model'] }
wasmtime-component-util = { workspace = true }
component-macro-test = { path = "crates/misc/component-macro-test" }
component-test-util = { workspace = true }
bstr = "0.2.17"

[target.'cfg(windows)'.dev-dependencies]
windows-sys = { workspace = true, features = ["Win32_System_Memory"] }
Expand Down
56 changes: 8 additions & 48 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ fn main() -> anyhow::Result<()> {
writeln!(out, "mod {} {{", strategy)?;

with_test_module(&mut out, "misc", |out| {
test_directory(out, "tests/misc_testsuite", strategy, true, true)?;
test_directory(out, "tests/misc_testsuite", strategy)?;
test_directory_module(out, "tests/misc_testsuite/multi-memory", strategy)?;
test_directory_module(out, "tests/misc_testsuite/simd", strategy)?;
test_directory_module(out, "tests/misc_testsuite/threads", strategy)?;
test_directory_module(out, "tests/misc_testsuite/memory64", strategy)?;
test_directory_module(out, "tests/misc_testsuite/component-model", strategy)?;
test_directory_module_no_pooling(
out,
"tests/misc_testsuite/threads-shared-memory",
strategy,
)?;
test_directory_module(out, "tests/misc_testsuite/threads-shared-memory", strategy)?;
Ok(())
})?;

with_test_module(&mut out, "spec", |out| {
let spec_tests = test_directory(out, "tests/spec_testsuite", strategy, true, true)?;
let spec_tests = test_directory(out, "tests/spec_testsuite", strategy)?;
// Skip running spec_testsuite tests if the submodule isn't checked
// out.
if spec_tests > 0 {
Expand All @@ -49,11 +45,7 @@ fn main() -> anyhow::Result<()> {
"tests/spec_testsuite/proposals/multi-memory",
strategy,
)?;
test_directory_module_no_ref_no_pooling(
out,
"tests/spec_testsuite/proposals/threads",
strategy,
)?;
test_directory_module(out, "tests/spec_testsuite/proposals/threads", strategy)?;
} else {
println!(
"cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
Expand All @@ -80,41 +72,13 @@ fn test_directory_module(
) -> anyhow::Result<usize> {
let path = path.as_ref();
let testsuite = &extract_name(path);
with_test_module(out, testsuite, |out| {
test_directory(out, path, strategy, true, true)
})
}

fn test_directory_module_no_pooling(
out: &mut String,
path: impl AsRef<Path>,
strategy: &str,
) -> anyhow::Result<usize> {
let path = path.as_ref();
let testsuite = &extract_name(path);
with_test_module(out, testsuite, |out| {
test_directory(out, path, strategy, false, true)
})
}

fn test_directory_module_no_ref_no_pooling(
out: &mut String,
path: impl AsRef<Path>,
strategy: &str,
) -> anyhow::Result<usize> {
let path = path.as_ref();
let testsuite = &extract_name(path);
with_test_module(out, testsuite, |out| {
test_directory(out, path, strategy, false, false)
})
with_test_module(out, testsuite, |out| test_directory(out, path, strategy))
}

fn test_directory(
out: &mut String,
path: impl AsRef<Path>,
strategy: &str,
allow_pooling: bool,
reference_types: bool,
) -> anyhow::Result<usize> {
let path = path.as_ref();
let mut dir_entries: Vec<_> = path
Expand All @@ -140,10 +104,8 @@ fn test_directory(

let testsuite = &extract_name(path);
for entry in dir_entries.iter() {
write_testsuite_tests(out, entry, testsuite, strategy, false, reference_types)?;
if allow_pooling {
write_testsuite_tests(out, entry, testsuite, strategy, true, reference_types)?;
}
write_testsuite_tests(out, entry, testsuite, strategy, false)?;
write_testsuite_tests(out, entry, testsuite, strategy, true)?;
}

Ok(dir_entries.len())
Expand Down Expand Up @@ -180,7 +142,6 @@ fn write_testsuite_tests(
testsuite: &str,
strategy: &str,
pooling: bool,
reference_types: bool,
) -> anyhow::Result<()> {
let path = path.as_ref();
let testname = extract_name(path);
Expand All @@ -200,11 +161,10 @@ fn write_testsuite_tests(
writeln!(out, " let _ = env_logger::try_init();")?;
writeln!(
out,
" crate::wast::run_wast(r#\"{}\"#, crate::wast::Strategy::{}, {}, {}).unwrap();",
" crate::wast::run_wast(r#\"{}\"#, crate::wast::Strategy::{}, {}).unwrap();",
path.display(),
strategy,
pooling,
reference_types
)?;
writeln!(out, "}}")?;
writeln!(out)?;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl WastCommand {
let mut wast_context = WastContext::new(store);

wast_context
.register_spectest()
.register_spectest(true)
.expect("error instantiating \"spectest\"");

for script in self.scripts.iter() {
Expand Down
23 changes: 13 additions & 10 deletions tests/all/wast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Context;
use bstr::ByteSlice;
use once_cell::sync::Lazy;
use std::path::Path;
use std::sync::{Condvar, Mutex};
Expand All @@ -13,27 +14,29 @@ include!(concat!(env!("OUT_DIR"), "/wast_testsuite_tests.rs"));
// Each of the tests included from `wast_testsuite_tests` will call this
// function which actually executes the `wast` test suite given the `strategy`
// to compile it.
fn run_wast(
wast: &str,
strategy: Strategy,
pooling: bool,
reference_types: bool,
) -> anyhow::Result<()> {
fn run_wast(wast: &str, strategy: Strategy, pooling: bool) -> anyhow::Result<()> {
drop(env_logger::try_init());

let wast_bytes =
std::fs::read(path).with_context(|| format!("failed to read `{}`", path.display()))?;
let wast_bytes = std::fs::read(wast).with_context(|| format!("failed to read `{}`", wast))?;

match strategy {
Strategy::Cranelift => {}
_ => unimplemented!(),
}
let reference_types = !wast.contains("/proposals/threads/");

let wast = Path::new(wast);

let memory64 = feature_found(wast, "memory64");
let multi_memory = feature_found(wast, "multi-memory");
let threads = feature_found(wast, "threads");
let use_shared_memory = feature_found_src(&wast_bytes, "shared-memory");
let use_shared_memory = feature_found_src(&wast_bytes, "shared_memory")
|| feature_found_src(&wast_bytes, "shared)");

if pooling && use_shared_memory {
eprintln!("skipping pooling test with shared memory");
return Ok(());
}

let mut cfg = Config::new();
cfg.wasm_multi_memory(multi_memory)
Expand Down Expand Up @@ -109,7 +112,7 @@ fn run_wast(
let mut wast_context = WastContext::new(store);

wast_context.register_spectest(use_shared_memory)?;
wast_context.run_buffer(path.to_str().unwrap(), &wast_bytes)?;
wast_context.run_buffer(wast.to_str().unwrap(), &wast_bytes)?;

Ok(())
}
Expand Down

0 comments on commit a04786d

Please sign in to comment.