Skip to content

Commit

Permalink
Merge #2546
Browse files Browse the repository at this point in the history
2546: test(wasi) Running all WASI tests with `wasmer_vfs::mem_fs` too r=Hywan a=Hywan

# Description

This WIP PR updates our WASI test framework to specifically test with `wasmer_vfs::host_fs` (the default, as of now) _and_ with `wasmer_vfs::mem_fs` (🆕!).

Bug trophies:

* #2545
* #2550
* #2551

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Ivan Enderlin <[email protected]>
  • Loading branch information
bors[bot] and Hywan authored Sep 3, 2021
2 parents d07997e + 7ebe3a4 commit 4ab4e91
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 79 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.

23 changes: 16 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,27 @@ fn main() -> anyhow::Result<()> {
buffer: String::new(),
path: vec![],
};
let wasi_versions = ["unstable", "snapshot1"];

with_test_module(&mut wasitests, "wasitests", |wasitests| {
for wasi_version in &wasi_versions {
for wasi_version in &["unstable", "snapshot1"] {
with_test_module(wasitests, wasi_version, |wasitests| {
let _wasi_tests = test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
wasi_processor,
)?;
for (wasi_filesystem_test_name, wasi_filesystem_kind) in &[
("host_fs", "WasiFileSystemKind::Host"),
("mem_fs", "WasiFileSystemKind::InMemory"),
] {
with_test_module(wasitests, wasi_filesystem_test_name, |wasitests| {
test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
|out, path| wasi_processor(out, path, wasi_filesystem_kind),
)
})?;
}

Ok(())
})?;
}

Ok(())
})?;

Expand Down
3 changes: 3 additions & 0 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,12 @@ impl PreopenDirBuilder {
}
let path = self.path.clone().unwrap();

/*
if !path.exists() {
return Err(WasiStateCreationError::PreopenedDirectoryNotFound(path));
}
*/

if let Some(alias) = &self.alias {
validate_mapped_dir_alias(alias)?;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl WasiFs {
&path.to_string_lossy(),
&alias
);
let cur_dir_metadata = path.metadata().map_err(|e| {
let cur_dir_metadata = wasi_fs.fs_backing.metadata(path).map_err(|e| {
format!(
"Could not get metadata for file {:?}: {}",
path,
Expand Down
1 change: 1 addition & 0 deletions tests/compilers/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ mod wast;
pub use crate::config::{Compiler, Config, Engine};
pub use crate::wasi::run_wasi;
pub use crate::wast::run_wast;
pub use wasmer_wast::WasiFileSystemKind;
24 changes: 16 additions & 8 deletions tests/compilers/wasi.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
use std::fs::File;
use std::io::Read;
use wasmer_wast::WasiTest;
use wasmer_wast::{WasiFileSystemKind, WasiTest};

// The generated tests (from build.rs) look like:
// #[cfg(test)]
// mod singlepass {
// mod spec {
// #[test]
// fn address() -> anyhow::Result<()> {
// crate::run_wast("tests/spectests/address.wast", "singlepass")
// mod [compiler] {
// mod [spec] {
// mod [vfs] {
// #[test]
// fn [test_name]() -> anyhow::Result<()> {
// crate::run_wasi("tests/spectests/[test_name].wast", "[compiler]", WasiFileSystemKind::[vfs])
// }
// }
// }
// }
include!(concat!(env!("OUT_DIR"), "/generated_wasitests.rs"));

pub fn run_wasi(config: crate::Config, wast_path: &str, base_dir: &str) -> anyhow::Result<()> {
pub fn run_wasi(
config: crate::Config,
wast_path: &str,
base_dir: &str,
filesystem_kind: WasiFileSystemKind,
) -> anyhow::Result<()> {
println!("Running wasi wast `{}`", wast_path);
let store = config.store();

Expand All @@ -27,7 +34,8 @@ pub fn run_wasi(config: crate::Config, wast_path: &str, base_dir: &str) -> anyho
let tokens = WasiTest::lex_string(&source)?;
let wasi_test = WasiTest::parse_tokens(&tokens)?;

let succeeded = wasi_test.run(&store, base_dir)?;
let succeeded = wasi_test.run(&store, base_dir, filesystem_kind)?;

assert!(succeeded);

Ok(())
Expand Down
12 changes: 7 additions & 5 deletions tests/compilers/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ use wasmer_wast::Wast;

// The generated tests (from build.rs) look like:
// #[cfg(test)]
// mod singlepass {
// mod spec {
// #[test]
// fn address() -> anyhow::Result<()> {
// crate::run_wast("tests/spectests/address.wast", "singlepass")
// mod [compiler] {
// mod [spec] {
// mod [vfs] {
// #[test]
// fn [test_name]() -> anyhow::Result<()> {
// crate::run_wasi("tests/spectests/[test_name].wast", "[compiler]", WasiFileSystemKind::[vfs])
// }
// }
// }
// }
Expand Down
87 changes: 58 additions & 29 deletions tests/ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,53 +71,82 @@ cranelift spec::simd::simd_int_to_int_extend
### These tests don't pass due to race conditions in the new way we run tests.
### It's not built to be run in parallel with itself, so we disable it for now.

wasitests::snapshot1::writing
wasitests::unstable::writing
wasitests::snapshot1::host_fs::writing
wasitests::unstable::host_fs::writing
wasitests::snapshot1::mem_fs::writing
wasitests::unstable::mem_fs::writing

### due to hard-coded direct calls into WASI for wasi unstable

wasitests::snapshot1::fd_read
wasitests::snapshot1::poll_oneoff
wasitests::snapshot1::fd_pread
wasitests::snapshot1::fd_close
wasitests::snapshot1::fd_allocate
wasitests::snapshot1::close_preopen_fd
wasitests::snapshot1::envvar
wasitests::snapshot1::host_fs::fd_read
wasitests::snapshot1::host_fs::poll_oneoff
wasitests::snapshot1::host_fs::fd_pread
wasitests::snapshot1::host_fs::fd_close
wasitests::snapshot1::host_fs::fd_allocate
wasitests::snapshot1::host_fs::close_preopen_fd
wasitests::snapshot1::host_fs::envvar
wasitests::snapshot1::mem_fs::fd_read
wasitests::snapshot1::mem_fs::poll_oneoff
wasitests::snapshot1::mem_fs::fd_pread
wasitests::snapshot1::mem_fs::fd_close
wasitests::snapshot1::mem_fs::fd_allocate
wasitests::snapshot1::mem_fs::close_preopen_fd
wasitests::snapshot1::mem_fs::envvar

### TODO: resolve the disabled tests below. These are newly disabled tests from the migration:

### due to git clone not preserving symlinks:
wasitests::snapshot1::readlink
wasitests::unstable::readlink
wasitests::snapshot1::host_fs::readlink
wasitests::unstable::host_fs::readlink
wasitests::snapshot1::mem_fs::readlink
wasitests::unstable::mem_fs::readlink

### failing due to `remove_dir_all`. this test is also bad for parallelism
wasitests::snapshot1::create_dir
wasitests::unstable::create_dir
wasitests::snapshot1::host_fs::create_dir
wasitests::unstable::host_fs::create_dir
wasitests::snapshot1::mem_fs::create_dir
wasitests::unstable::mem_fs::create_dir

### failing because it closes `stdout` which breaks our testing system
wasitests::unstable::fd_close
wasitests::unstable::host_fs::fd_close
wasitests::unstable::mem_fs::fd_close

### failing because we're operating on stdout which is now overridden.
### TODO: check WasiFile implementation
### Alterative: split test into 2 parts, one printing to stderr, the other printing to stdout to test the real versions
wasitests::unstable::poll_oneoff
wasitests::unstable::host_fs::poll_oneoff
wasitests::unstable::mem_fs::poll_oneoff

## Failing due to different line endings on Windows
## we need a better solution to this problem:

windows wasitests::snapshot1::file_metadata
windows wasitests::snapshot1::fseek
windows wasitests::snapshot1::path_link
windows wasitests::snapshot1::path_symlink
windows wasitests::snapshot1::mapdir_with_leading_slash
windows wasitests::unstable::fd_pread
windows wasitests::unstable::fd_read
windows wasitests::unstable::file_metadata
windows wasitests::unstable::fseek
windows wasitests::unstable::path_link
windows wasitests::unstable::path_symlink
windows wasitests::unstable::mapdir_with_leading_slash
windows wasitests::snapshot1::host_fs::file_metadata
windows wasitests::snapshot1::host_fs::fseek
windows wasitests::snapshot1::host_fs::path_link
windows wasitests::snapshot1::host_fs::path_symlink
windows wasitests::snapshot1::host_fs::mapdir_with_leading_slash
windows wasitests::unstable::host_fs::fd_pread
windows wasitests::unstable::host_fs::fd_read
windows wasitests::unstable::host_fs::file_metadata
windows wasitests::unstable::host_fs::fseek
windows wasitests::unstable::host_fs::path_link
windows wasitests::unstable::host_fs::path_symlink
windows wasitests::unstable::host_fs::mapdir_with_leading_slash
windows wasitests::snapshot1::mem_fs::file_metadata
windows wasitests::snapshot1::mem_fs::fseek
windows wasitests::snapshot1::mem_fs::path_link
windows wasitests::snapshot1::mem_fs::path_symlink
windows wasitests::snapshot1::mem_fs::mapdir_with_leading_slash
windows wasitests::unstable::mem_fs::fd_pread
windows wasitests::unstable::mem_fs::fd_read
windows wasitests::unstable::mem_fs::file_metadata
windows wasitests::unstable::mem_fs::fseek
windows wasitests::unstable::mem_fs::path_link
windows wasitests::unstable::mem_fs::path_symlink
windows wasitests::unstable::mem_fs::mapdir_with_leading_slash

# This tests are disabled for now
wasitests::unstable::unix_open_special_files
wasitests::snapshot1::unix_open_special_files
wasitests::unstable::host_fs::unix_open_special_files
wasitests::snapshot1::host_fs::unix_open_special_files
wasitests::unstable::mem_fs::unix_open_special_files
wasitests::snapshot1::mem_fs::unix_open_special_files
6 changes: 2 additions & 4 deletions tests/lib/test-generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ pub struct Test {
pub body: String,
}

pub type ProcessorType = fn(&mut Testsuite, PathBuf) -> Option<Test>;

pub fn test_directory_module(
out: &mut Testsuite,
path: impl AsRef<Path>,
processor: ProcessorType,
processor: impl Fn(&mut Testsuite, PathBuf) -> Option<Test>,
) -> anyhow::Result<usize> {
let path = path.as_ref();
let testsuite = &extract_name(path);
Expand All @@ -55,7 +53,7 @@ fn write_test(out: &mut Testsuite, testname: &str, body: &str) -> anyhow::Result
pub fn test_directory(
out: &mut Testsuite,
path: impl AsRef<Path>,
processor: ProcessorType,
processor: impl Fn(&mut Testsuite, PathBuf) -> Option<Test>,
) -> anyhow::Result<usize> {
let path = path.as_ref();
let mut dir_entries: Vec<_> = path
Expand Down
10 changes: 7 additions & 3 deletions tests/lib/test-generator/src/processors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ pub fn emscripten_processor(_out: &mut Testsuite, p: PathBuf) -> Option<Test> {

/// Given a Testsuite and a path, process the path in case is a WASI
/// wasm file.
pub fn wasi_processor(_out: &mut Testsuite, p: PathBuf) -> Option<Test> {
pub fn wasi_processor(
_out: &mut Testsuite,
p: PathBuf,
wasi_filesystem_kind: &str,
) -> Option<Test> {
let ext = p.extension()?;
// Only look at wast files.
if ext != "wast" {
Expand All @@ -77,11 +81,11 @@ pub fn wasi_processor(_out: &mut Testsuite, p: PathBuf) -> Option<Test> {
};
let testname = extract_name(&p);

// The implementation of `run_wasi` lives in /tests/wasitest.rs
let body = format!(
"crate::run_wasi(config, r#\"{}\"#, \"{}\")",
"crate::run_wasi(config, r#\"{}\"#, \"{}\", crate::{})",
p.display(),
wasm_dir.display(),
wasi_filesystem_kind,
);

Some(Test {
Expand Down
1 change: 1 addition & 0 deletions tests/lib/wast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ edition = "2018"
anyhow = "1.0"
wasmer = { path = "../../../lib/api", version = "2.0.0", default-features = false, features = ["experimental-reference-types-extern-ref"] }
wasmer-wasi = { path = "../../../lib/wasi", version = "2.0.0" }
wasmer-vfs = { path = "../../../lib/vfs", version = "2.0.0" }
wast = "37.0"
serde = "1"
tempfile = "3"
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/wast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod wast;

pub use crate::error::{DirectiveError, DirectiveErrors};
pub use crate::spectest::spectest_importobject;
pub use crate::wasi_wast::WasiTest;
pub use crate::wasi_wast::{WasiFileSystemKind, WasiTest};
pub use crate::wast::Wast;

/// Version number of this crate.
Expand Down
Loading

0 comments on commit 4ab4e91

Please sign in to comment.