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", "tempfile",
"wasi-cap-std-sync", "wasi-cap-std-sync",
"wasi-common", "wasi-common",
"wasi-virtfs",
"wasmtime", "wasmtime",
"wasmtime-wasi", "wasmtime-wasi",
"wat", "wat",

View File

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

View File

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