test-programs: test both cap-std-sync and virtfs backend

This commit is contained in:
Pat Hickey
2021-01-30 13:39:18 -08:00
parent 533db3e807
commit fcecb3fea6
4 changed files with 58 additions and 45 deletions

1
Cargo.lock generated
View File

@@ -2805,6 +2805,7 @@ dependencies = [
"tempfile",
"wasi-cap-std-sync",
"wasi-common",
"wasi-virtfs",
"wasmtime",
"wasmtime-wasi",
"wat",

View File

@@ -12,6 +12,7 @@ cfg-if = "1.0"
[dev-dependencies]
wasi-common = { path = "../wasi-common", version = "0.22.0" }
wasi-virtfs = { path = "../wasi-common/virtfs", version = "0.22.0" }
wasi-cap-std-sync = { path = "../wasi-common/cap-std-sync", version = "0.22.0" }
wasmtime = { path = "../wasmtime", version = "0.22.0" }
wasmtime-wasi = { path = "../wasi", version = "0.22.0" }

View File

@@ -39,7 +39,9 @@ mod wasi_tests {
let mut out =
File::create(out_dir.join("wasi_tests.rs")).expect("error generating test source file");
build_tests("wasi-tests", &out_dir).expect("building tests");
test_directory(&mut out, "wasi-tests", &out_dir).expect("generating tests");
test_directory(&mut out, "wasi-cap-std-sync", "cap_std_sync", &out_dir)
.expect("generating tests");
test_directory(&mut out, "wasi-virtfs", "virtfs", &out_dir).expect("generating tests");
}
fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> {
@@ -68,7 +70,12 @@ mod wasi_tests {
Ok(())
}
fn test_directory(out: &mut File, testsuite: &str, out_dir: &Path) -> io::Result<()> {
fn test_directory(
out: &mut File,
testsuite: &str,
runtime: &str,
out_dir: &Path,
) -> io::Result<()> {
let mut dir_entries: Vec<_> = read_dir(out_dir.join("wasm32-wasi/release"))
.expect("reading testsuite directory")
.map(|r| r.expect("reading testsuite directory entry"))
@@ -103,7 +110,11 @@ mod wasi_tests {
.expect("testsuite filename should be representable as a string")
.replace("-", "_")
)?;
writeln!(out, " use super::{{runtime, utils, setup_log}};")?;
writeln!(
out,
" use super::{{runtime::{} as runtime, utils, setup_log}};",
runtime
)?;
for dir_entry in dir_entries {
write_testsuite_tests(out, &dir_entry.path(), testsuite)?;
}
@@ -159,25 +170,28 @@ mod wasi_tests {
Ok(())
}
fn ignore(testsuite: &str, name: &str) -> bool {
match testsuite {
"wasi-cap-std-sync" => cap_std_sync_ignore(name),
"wasi-virtfs" => false,
_ => panic!("unknown test suite: {}", testsuite),
}
}
#[cfg(not(windows))]
/// Ignore tests that aren't supported yet.
fn ignore(testsuite: &str, name: &str) -> bool {
if testsuite == "wasi-tests" {
fn cap_std_sync_ignore(name: &str) -> bool {
match name {
// Trailing slash related bugs:
"path_rename_file_trailing_slashes" => true,
"remove_directory_trailing_slashes" => true,
_ => false,
}
} else {
unreachable!()
}
}
#[cfg(windows)]
/// Ignore tests that aren't supported yet.
fn ignore(testsuite: &str, name: &str) -> bool {
if testsuite == "wasi-tests" {
fn cap_std_sync_ignore(name: &str) -> bool {
match name {
// Panic: Metadata not associated with open file
// https://github.com/bytecodealliance/cap-std/issues/142
@@ -197,14 +211,11 @@ mod wasi_tests {
"remove_directory_trailing_slashes" => true,
_ => false,
}
} else {
unreachable!()
}
}
/// Mark tests which do not require preopens
fn no_preopens(testsuite: &str, name: &str) -> bool {
if testsuite == "wasi-tests" {
if testsuite.starts_with("wasi-") {
match name {
"big_random_buf" => true,
"clock_time_get" => true,
@@ -213,19 +224,19 @@ mod wasi_tests {
_ => false,
}
} else {
unreachable!()
panic!("unknown test suite {}", testsuite)
}
}
/// Mark tests which require inheriting parent process stdio
fn inherit_stdio(testsuite: &str, name: &str) -> bool {
if testsuite == "wasi-tests" {
match name {
match testsuite {
"wasi-cap-std-sync" => match name {
"poll_oneoff_stdio" => true,
_ => false,
}
} else {
unreachable!()
},
"wasi-virtfs" => false,
_ => panic!("unknown test suite {}", testsuite),
}
}
}

View File

@@ -42,11 +42,11 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
builder = builder.env("ERRNO_MODE_UNIX", "1")?;
}
let snapshot1 = wasmtime_wasi::Wasi::new(&store, builder.build()?);
let wasi = wasmtime_wasi::Wasi::new(&store, builder.build()?);
let mut linker = Linker::new(&store);
snapshot1.add_to_linker(&mut linker)?;
wasi.add_to_linker(&mut linker)?;
let module = Module::new(store.engine(), &data).context("failed to create wasm module")?;
let instance = linker.instantiate(&module)?;