diff --git a/tests/all/wasi_testsuite.rs b/tests/all/wasi_testsuite.rs index 8d18aa328acc..65a635dcac56 100644 --- a/tests/all/wasi_testsuite.rs +++ b/tests/all/wasi_testsuite.rs @@ -33,21 +33,7 @@ fn wasi_testsuite() -> Result<()> { const WASI_COMMON_IGNORE_LIST: &[&str] = &[ "environ_get-multiple-variables.wasm", "environ_sizes_get-multiple-variables.wasm", - "fdopendir-with-access.wasm", - "fopen-with-access.wasm", - "lseek.wasm", - "pread-with-access.wasm", - "pwrite-with-access.wasm", - "stat-dev-ino.wasm", - "close_preopen.wasm", - "dangling_fd.wasm", - "dangling_symlink.wasm", - "directory_seek.wasm", "fd_advise.wasm", - "fd_filestat_set.wasm", - "fd_flags_set.wasm", - "fd_readdir.wasm", - "interesting_paths.wasm", ]; run_all( "tests/wasi_testsuite/wasi-common", @@ -68,7 +54,12 @@ fn wasi_testsuite() -> Result<()> { } fn run_all(testsuite_dir: &str, extra_flags: &[&str], ignore: &[&str]) -> Result<()> { - for module in list_modules(testsuite_dir) { + // In case the previous run ended in failure, we clean up any created files + // that would otherwise be cleaned up at the end of this function. + clean_garbage(testsuite_dir)?; + + // Execute and check each WebAssembly test case. + for module in list_files(testsuite_dir, is_wasm) { if should_ignore(&module, ignore) { println!("Ignoring {}", module.display()); } else { @@ -88,14 +79,19 @@ fn run_all(testsuite_dir: &str, extra_flags: &[&str], ignore: &[&str]) -> Result } } } - Ok(()) + + // Clean up any created files to avoid making the Git repository dirty. + clean_garbage(testsuite_dir) } -fn list_modules(testsuite_dir: &str) -> impl Iterator { +fn list_files(testsuite_dir: &str, filter: F) -> impl Iterator +where + F: FnMut(&DirEntry) -> bool, +{ WalkDir::new(testsuite_dir) .into_iter() .filter_map(Result::ok) - .filter(is_wasm) + .filter(filter) .map(|e| e.path().to_path_buf()) } @@ -122,8 +118,8 @@ fn build_command>(module: P, extra_flags: &[&str], spec: &Spec) - cmd.args(extra_flags); if let Some(dirs) = &spec.dirs { for dir in dirs { - cmd.arg("--dir"); - cmd.arg(parent_dir.join(dir)); + cmd.arg("--mapdir"); + cmd.arg(format!("{}::{}", dir, parent_dir.join(dir).display())); } } cmd.arg(module.as_ref().to_str().unwrap()); @@ -141,6 +137,24 @@ fn build_command>(module: P, extra_flags: &[&str], spec: &Spec) - Ok(cmd) } +fn clean_garbage(testsuite_dir: &str) -> Result<()> { + for path in list_files(testsuite_dir, is_garbage) { + println!("Removing {}", path.display()); + if path.is_dir() { + fs::remove_dir(path)?; + } else { + fs::remove_file(path)?; + } + } + Ok(()) +} + +fn is_garbage(entry: &DirEntry) -> bool { + let path = entry.path(); + let ext = path.extension().map(OsStr::to_str).flatten(); + ext == Some("cleanup") +} + #[derive(Debug, Default, Deserialize)] struct Spec { args: Option>,