diff --git a/Cargo.lock b/Cargo.lock index b8bf5efaa1..ae57147bd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2805,6 +2805,7 @@ dependencies = [ "tempfile", "wasi-cap-std-sync", "wasi-common", + "wasi-virtfs", "wasmtime", "wasmtime-wasi", "wat", diff --git a/crates/test-programs/Cargo.toml b/crates/test-programs/Cargo.toml index ca7359ebeb..458864bf2b 100644 --- a/crates/test-programs/Cargo.toml +++ b/crates/test-programs/Cargo.toml @@ -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" } diff --git a/crates/test-programs/build.rs b/crates/test-programs/build.rs index 1bf80af504..f7b51baf24 100644 --- a/crates/test-programs/build.rs +++ b/crates/test-programs/build.rs @@ -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,52 +170,52 @@ 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" { - match name { - // Trailing slash related bugs: - "path_rename_file_trailing_slashes" => true, - "remove_directory_trailing_slashes" => true, - _ => false, - } - } else { - unreachable!() + 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, } } #[cfg(windows)] /// Ignore tests that aren't supported yet. - fn ignore(testsuite: &str, name: &str) -> bool { - if testsuite == "wasi-tests" { - match name { - // Panic: Metadata not associated with open file - // https://github.com/bytecodealliance/cap-std/issues/142 - "fd_readdir" => true, - "fd_flags_set" => true, - "path_filestat" => true, - "symlink_filestat" => true, - // Fix merged, waiting for cap-std release - "nofollow_errors" => true, - // waiting on DirExt::delete_file_or_symlink - "symlink_create" => true, - // Bug: windows lets us rename an empty directory to a path containing an empty file - "path_rename" => true, - // Trailing slash related bugs - "interesting_paths" => true, - "path_rename_file_trailing_slashes" => true, - "remove_directory_trailing_slashes" => true, - _ => false, - } - } else { - unreachable!() + 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 + "fd_readdir" => true, + "fd_flags_set" => true, + "path_filestat" => true, + "symlink_filestat" => true, + // Fix merged, waiting for cap-std release + "nofollow_errors" => true, + // waiting on DirExt::delete_file_or_symlink + "symlink_create" => true, + // Bug: windows lets us rename an empty directory to a path containing an empty file + "path_rename" => true, + // Trailing slash related bugs + "interesting_paths" => true, + "path_rename_file_trailing_slashes" => true, + "remove_directory_trailing_slashes" => true, + _ => false, } } /// 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), } } } diff --git a/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs b/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs index 8af9e1bffa..343385bd27 100644 --- a/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs +++ b/crates/test-programs/tests/wasm_tests/runtime/cap_std_sync.rs @@ -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)?;