diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 61ddb550fc..74ccbb0304 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -102,7 +102,7 @@ jobs: - run: cargo fetch # Build and test all features except for lightbeam - - run: cargo test --features wasi-common/wasm_tests --all --exclude lightbeam --exclude wasmtime-wasi-c --exclude wasmtime-py -- --nocapture + - run: cargo test --features test-programs --all --exclude lightbeam --exclude wasmtime-wasi-c --exclude wasmtime-py -- --nocapture env: RUST_BACKTRACE: 1 @@ -219,7 +219,7 @@ jobs: - run: $CENTOS cargo build --release --manifest-path crates/api/Cargo.toml shell: bash # Test what we just built - - run: $CENTOS cargo test --features wasi-common/wasm_tests --release --all --exclude lightbeam --exclude wasmtime-wasi-c --exclude wasmtime-py --exclude wasmtime + - run: $CENTOS cargo test --features test-programs --release --all --exclude lightbeam --exclude wasmtime-wasi-c --exclude wasmtime-py --exclude wasmtime shell: bash env: RUST_BACKTRACE: 1 diff --git a/Cargo.toml b/Cargo.toml index ae78a1ad8f..2b53403ff5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,10 @@ libc = "0.2.60" rayon = "1.1" wasm-webidl-bindings = "0.6" more-asserts = "0.2.1" +# This feature requires the wasm32-wasi target be installed. It enables +# wasm32-wasi integration tests. To enable, run +# `cargo test --features test-programs`. +test-programs = { path = "crates/test-programs", optional = true } [build-dependencies] anyhow = "1.0.19" @@ -51,8 +55,6 @@ members = [ "crates/misc/py", ] -exclude = ["crates/wasi-common/wasi-misc-tests"] - [features] lightbeam = [ "wasmtime-environ/lightbeam", diff --git a/crates/test-programs/Cargo.toml b/crates/test-programs/Cargo.toml new file mode 100644 index 0000000000..e60794b05d --- /dev/null +++ b/crates/test-programs/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "test-programs" +version = "0.0.0" +authors = ["The Wasmtime Project Developers"] +readme = "README.md" +edition = "2018" +publish = false + +[build-dependencies] +cfg-if = "0.1.9" + +[dev-dependencies] +wasi-common = { path = "../wasi-common" } +wasmtime-runtime = { path = "../runtime" } +wasmtime-environ = { path = "../environ" } +wasmtime-jit = { path = "../jit" } +wasmtime-wasi = { path = "../wasi" } +wasmtime = { path = "../api" } +cranelift-codegen = "0.50.0" +target-lexicon = "0.9.0" +pretty_env_logger = "0.3.0" +tempfile = "3.1.0" +os_pipe = "0.9" +anyhow = "1.0.19" diff --git a/crates/test-programs/README.md b/crates/test-programs/README.md new file mode 100644 index 0000000000..662216f426 --- /dev/null +++ b/crates/test-programs/README.md @@ -0,0 +1,2 @@ +This is the `test-programs` crate, which builds and runs whole programs +compiled to wasm32-wasi. diff --git a/crates/test-programs/build.rs b/crates/test-programs/build.rs new file mode 100644 index 0000000000..b460c46cca --- /dev/null +++ b/crates/test-programs/build.rs @@ -0,0 +1,192 @@ +//! Build program to generate a program which runs all the testsuites. +//! +//! By generating a separate `#[test]` test for each file, we allow cargo test +//! to automatically run the files in parallel. + +use std::env; +use std::fs::{read_dir, DirEntry, File}; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; + +fn main() { + build_and_generate_tests() +} + +fn build_and_generate_tests() { + // Validate if any of test sources are present and if they changed + // This should always work since there is no submodule to init anymore + let bin_tests = std::fs::read_dir("wasi-tests/src/bin").unwrap(); + for test in bin_tests { + if let Ok(test_file) = test { + let test_file_path = test_file + .path() + .into_os_string() + .into_string() + .expect("test file path"); + println!("cargo:rerun-if-changed={}", test_file_path); + } + } + // Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm) + let out_dir = + PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set")); + 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"); +} + +fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> { + let mut cmd = Command::new("cargo"); + cmd.args(&[ + "build", + "--release", + "--target=wasm32-wasi", + "--target-dir", + out_dir.to_str().unwrap(), + ]) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .current_dir(testsuite); + let output = cmd.output()?; + + let status = output.status; + if !status.success() { + panic!( + "Building tests failed: exit code: {}", + status.code().unwrap() + ); + } + + Ok(()) +} + +fn test_directory(out: &mut File, testsuite: &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")) + .filter(|dir_entry| { + let p = dir_entry.path(); + if let Some(ext) = p.extension() { + // Only look at wast files. + if ext == "wasm" { + // Ignore files starting with `.`, which could be editor temporary files + if let Some(stem) = p.file_stem() { + if let Some(stemstr) = stem.to_str() { + if !stemstr.starts_with('.') { + return true; + } + } + } + } + } + false + }) + .collect(); + + dir_entries.sort_by_key(|dir| dir.path()); + + writeln!( + out, + "mod {} {{", + Path::new(testsuite) + .file_stem() + .expect("testsuite filename should have a stem") + .to_str() + .expect("testsuite filename should be representable as a string") + .replace("-", "_") + )?; + writeln!(out, " use super::{{runtime, utils, setup_log}};")?; + for dir_entry in dir_entries { + write_testsuite_tests(out, dir_entry, testsuite)?; + } + writeln!(out, "}}")?; + Ok(()) +} + +fn write_testsuite_tests(out: &mut File, dir_entry: DirEntry, testsuite: &str) -> io::Result<()> { + let path = dir_entry.path(); + let stemstr = path + .file_stem() + .expect("file_stem") + .to_str() + .expect("to_str"); + + writeln!(out, " #[test]")?; + if ignore(testsuite, stemstr) { + writeln!(out, " #[ignore]")?; + } + writeln!( + out, + " fn r#{}() -> anyhow::Result<()> {{", + &stemstr.replace("-", "_") + )?; + writeln!(out, " setup_log();")?; + writeln!( + out, + " let path = std::path::Path::new(r#\"{}\"#);", + path.display() + )?; + writeln!(out, " let data = utils::read_wasm(path)?;")?; + writeln!( + out, + " let bin_name = utils::extract_exec_name_from_path(path)?;" + )?; + let workspace = if no_preopens(testsuite, stemstr) { + "None" + } else { + writeln!( + out, + " let workspace = utils::prepare_workspace(&bin_name)?;" + )?; + "Some(workspace.path())" + }; + writeln!( + out, + " runtime::instantiate(&data, &bin_name, {})", + workspace + )?; + writeln!(out, " }}")?; + writeln!(out)?; + Ok(()) +} + +cfg_if::cfg_if! { + if #[cfg(not(windows))] { + /// Ignore tests that aren't supported yet. + fn ignore(_testsuite: &str, _name: &str) -> bool { + false + } + } else { + /// Ignore tests that aren't supported yet. + fn ignore(testsuite: &str, name: &str) -> bool { + if testsuite == "wasi-tests" { + match name { + "readlink_no_buffer" => true, + "dangling_symlink" => true, + "symlink_loop" => true, + "truncation_rights" => true, + "poll_oneoff" => true, + "path_link" => true, + _ => false, + } + } else { + unreachable!() + } + } + } +} + +/// Mark tests which do not require preopens +fn no_preopens(testsuite: &str, name: &str) -> bool { + if testsuite == "wasi-tests" { + match name { + "big_random_buf" => true, + "clock_time_get" => true, + "sched_yield" => true, + _ => false, + } + } else { + unreachable!() + } +} diff --git a/crates/test-programs/src/lib.rs b/crates/test-programs/src/lib.rs new file mode 100644 index 0000000000..efeb701d08 --- /dev/null +++ b/crates/test-programs/src/lib.rs @@ -0,0 +1,2 @@ +// This crate doesn't contain any code; it just exists to run tests for +// other crates in the workspace. diff --git a/crates/wasi-common/tests/wasm_tests/main.rs b/crates/test-programs/tests/wasm_tests/main.rs similarity index 65% rename from crates/wasi-common/tests/wasm_tests/main.rs rename to crates/test-programs/tests/wasm_tests/main.rs index 0a5515d52b..ce47f7ed82 100644 --- a/crates/wasi-common/tests/wasm_tests/main.rs +++ b/crates/test-programs/tests/wasm_tests/main.rs @@ -1,5 +1,3 @@ -#![cfg(feature = "wasm_tests")] - mod runtime; mod utils; @@ -13,4 +11,4 @@ fn setup_log() { }) } -include!(concat!(env!("OUT_DIR"), "/wasi_misc_tests.rs")); +include!(concat!(env!("OUT_DIR"), "/wasi_tests.rs")); diff --git a/crates/wasi-common/tests/wasm_tests/runtime.rs b/crates/test-programs/tests/wasm_tests/runtime.rs similarity index 100% rename from crates/wasi-common/tests/wasm_tests/runtime.rs rename to crates/test-programs/tests/wasm_tests/runtime.rs diff --git a/crates/wasi-common/tests/wasm_tests/utils.rs b/crates/test-programs/tests/wasm_tests/utils.rs similarity index 100% rename from crates/wasi-common/tests/wasm_tests/utils.rs rename to crates/test-programs/tests/wasm_tests/utils.rs diff --git a/crates/test-programs/wasi-tests/Cargo.toml b/crates/test-programs/wasi-tests/Cargo.toml new file mode 100644 index 0000000000..fe3d94267e --- /dev/null +++ b/crates/test-programs/wasi-tests/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "wasi-tests" +version = "0.0.0" +authors = ["The Wasmtime Project Developers"] +readme = "README.md" +edition = "2018" +publish = false + +[dependencies] +libc = "0.2.65" +wasi = "0.7.0" +more-asserts = "0.2.1" + +# This crate is built with the wasm32-wasi target, so it's separate +# from the main Wasmtime build, so use this directive to exclude it +# from the parent directory's workspace. +[workspace] diff --git a/crates/test-programs/wasi-tests/README.md b/crates/test-programs/wasi-tests/README.md new file mode 100644 index 0000000000..f281fa1a8e --- /dev/null +++ b/crates/test-programs/wasi-tests/README.md @@ -0,0 +1,3 @@ +This is the `wasi-tests` crate, which contains source code for the system-level WASI tests. + +Building these tests requires that the `wasm32-wasi` target be installed. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/big_random_buf.rs b/crates/test-programs/wasi-tests/src/bin/big_random_buf.rs similarity index 100% rename from crates/wasi-common/wasi-misc-tests/src/bin/big_random_buf.rs rename to crates/test-programs/wasi-tests/src/bin/big_random_buf.rs diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/clock_time_get.rs b/crates/test-programs/wasi-tests/src/bin/clock_time_get.rs similarity index 95% rename from crates/wasi-common/wasi-misc-tests/src/bin/clock_time_get.rs rename to crates/test-programs/wasi-tests/src/bin/clock_time_get.rs index 5de9b5c1aa..0ad84d37fd 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/clock_time_get.rs +++ b/crates/test-programs/wasi-tests/src/bin/clock_time_get.rs @@ -1,6 +1,6 @@ use more_asserts::assert_le; use wasi::wasi_unstable; -use wasi_misc_tests::wasi_wrappers::wasi_clock_time_get; +use wasi_tests::wasi_wrappers::wasi_clock_time_get; unsafe fn test_clock_time_get() { // Test that clock_time_get succeeds. Even in environments where it's not diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/close_preopen.rs b/crates/test-programs/wasi-tests/src/bin/close_preopen.rs similarity index 95% rename from crates/wasi-common/wasi-misc-tests/src/bin/close_preopen.rs rename to crates/test-programs/wasi-tests/src/bin/close_preopen.rs index 000be99418..57acb6f747 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/close_preopen.rs +++ b/crates/test-programs/wasi-tests/src/bin/close_preopen.rs @@ -2,8 +2,8 @@ use libc; use more_asserts::assert_gt; use std::{env, mem, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::wasi_wrappers::wasi_fd_fdstat_get; +use wasi_tests::open_scratch_directory; +use wasi_tests::wasi_wrappers::wasi_fd_fdstat_get; unsafe fn test_close_preopen(dir_fd: wasi_unstable::Fd) { let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd; diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/dangling_symlink.rs b/crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs similarity index 89% rename from crates/wasi-common/wasi-misc-tests/src/bin/dangling_symlink.rs rename to crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs index 8e30fc4ee7..4a36f052ad 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/dangling_symlink.rs +++ b/crates/test-programs/wasi-tests/src/bin/dangling_symlink.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::cleanup_file; -use wasi_misc_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::cleanup_file; +use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; unsafe fn test_dangling_symlink(dir_fd: wasi_unstable::Fd) { // First create a dangling symlink. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/directory_seek.rs b/crates/test-programs/wasi-tests/src/bin/directory_seek.rs similarity index 91% rename from crates/wasi-common/wasi-misc-tests/src/bin/directory_seek.rs rename to crates/test-programs/wasi-tests/src/bin/directory_seek.rs index 01783e4a27..6cf3ff10a9 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/directory_seek.rs +++ b/crates/test-programs/wasi-tests/src/bin/directory_seek.rs @@ -1,10 +1,9 @@ -use libc; use more_asserts::assert_gt; use std::{env, mem, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, close_fd, create_dir}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_fd_seek, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, close_fd, create_dir}; +use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_fd_seek, wasi_path_open}; unsafe fn test_directory_seek(dir_fd: wasi_unstable::Fd) { // Create a directory in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/fd_advise.rs b/crates/test-programs/wasi-tests/src/bin/fd_advise.rs similarity index 92% rename from crates/wasi-common/wasi-misc-tests/src/bin/fd_advise.rs rename to crates/test-programs/wasi-tests/src/bin/fd_advise.rs index 2b48b11bbb..c436cec6de 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/fd_advise.rs +++ b/crates/test-programs/wasi-tests/src/bin/fd_advise.rs @@ -2,9 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_advise, wasi_fd_filestat_get, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::{wasi_fd_advise, wasi_fd_filestat_get, wasi_path_open}; unsafe fn test_fd_advise(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/fd_filestat_set.rs b/crates/test-programs/wasi-tests/src/bin/fd_filestat_set.rs similarity index 94% rename from crates/wasi-common/wasi-misc-tests/src/bin/fd_filestat_set.rs rename to crates/test-programs/wasi-tests/src/bin/fd_filestat_set.rs index 90c39b99b1..13bfd4a8b9 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/fd_filestat_set.rs +++ b/crates/test-programs/wasi-tests/src/bin/fd_filestat_set.rs @@ -2,9 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open}; unsafe fn test_fd_filestat_set(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/fd_readdir.rs b/crates/test-programs/wasi-tests/src/bin/fd_readdir.rs similarity index 97% rename from crates/wasi-common/wasi-misc-tests/src/bin/fd_readdir.rs rename to crates/test-programs/wasi-tests/src/bin/fd_readdir.rs index 30ff87a953..79c11dcaa8 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/fd_readdir.rs +++ b/crates/test-programs/wasi-tests/src/bin/fd_readdir.rs @@ -2,8 +2,8 @@ use libc; use more_asserts::assert_gt; use std::{cmp::min, env, mem, process, slice, str}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_fd_readdir, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_fd_readdir, wasi_path_open}; const BUF_LEN: usize = 256; diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/file_allocate.rs b/crates/test-programs/wasi-tests/src/bin/file_allocate.rs similarity index 94% rename from crates/wasi-common/wasi-misc-tests/src/bin/file_allocate.rs rename to crates/test-programs/wasi-tests/src/bin/file_allocate.rs index c1e3d6a07d..5c9d5784f6 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/file_allocate.rs +++ b/crates/test-programs/wasi-tests/src/bin/file_allocate.rs @@ -1,10 +1,9 @@ -use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::{wasi_fd_filestat_get, wasi_path_open}; unsafe fn test_file_allocate(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/file_pread_pwrite.rs b/crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs similarity index 95% rename from crates/wasi-common/wasi-misc-tests/src/bin/file_pread_pwrite.rs rename to crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs index 8887ead5de..e7773fea72 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/file_pread_pwrite.rs +++ b/crates/test-programs/wasi-tests/src/bin/file_pread_pwrite.rs @@ -2,9 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_pread, wasi_fd_pwrite, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::{wasi_fd_pread, wasi_fd_pwrite, wasi_path_open}; unsafe fn test_file_pread_pwrite(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/file_seek_tell.rs b/crates/test-programs/wasi-tests/src/bin/file_seek_tell.rs similarity index 94% rename from crates/wasi-common/wasi-misc-tests/src/bin/file_seek_tell.rs rename to crates/test-programs/wasi-tests/src/bin/file_seek_tell.rs index fa7f0cd22d..abdd0aa56b 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/file_seek_tell.rs +++ b/crates/test-programs/wasi-tests/src/bin/file_seek_tell.rs @@ -2,9 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_seek, wasi_fd_tell, wasi_fd_write, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::{wasi_fd_seek, wasi_fd_tell, wasi_fd_write, wasi_path_open}; unsafe fn test_file_seek_tell(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/file_unbuffered_write.rs b/crates/test-programs/wasi-tests/src/bin/file_unbuffered_write.rs similarity index 93% rename from crates/wasi-common/wasi-misc-tests/src/bin/file_unbuffered_write.rs rename to crates/test-programs/wasi-tests/src/bin/file_unbuffered_write.rs index 270df3db83..656a04429a 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/file_unbuffered_write.rs +++ b/crates/test-programs/wasi-tests/src/bin/file_unbuffered_write.rs @@ -1,10 +1,9 @@ -use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd, create_file}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_read, wasi_fd_write, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd, create_file}; +use wasi_tests::wasi_wrappers::{wasi_fd_read, wasi_fd_write, wasi_path_open}; unsafe fn test_file_unbuffered_write(dir_fd: wasi_unstable::Fd) { // Create file diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/interesting_paths.rs b/crates/test-programs/wasi-tests/src/bin/interesting_paths.rs similarity index 97% rename from crates/wasi-common/wasi-misc-tests/src/bin/interesting_paths.rs rename to crates/test-programs/wasi-tests/src/bin/interesting_paths.rs index cfb68bc81a..d712d09ec9 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/interesting_paths.rs +++ b/crates/test-programs/wasi-tests/src/bin/interesting_paths.rs @@ -2,9 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{close_fd, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::{ +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{close_fd, create_dir, create_file}; +use wasi_tests::wasi_wrappers::{ wasi_path_open, wasi_path_remove_directory, wasi_path_unlink_file, }; diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/isatty.rs b/crates/test-programs/wasi-tests/src/bin/isatty.rs similarity index 89% rename from crates/wasi-common/wasi-misc-tests/src/bin/isatty.rs rename to crates/test-programs/wasi-tests/src/bin/isatty.rs index 945998a203..e2996d52f9 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/isatty.rs +++ b/crates/test-programs/wasi-tests/src/bin/isatty.rs @@ -1,10 +1,9 @@ -use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::wasi_path_open; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::wasi_path_open; unsafe fn test_isatty(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory and test if it's a tty. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/nofollow_errors.rs b/crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs similarity index 94% rename from crates/wasi-common/wasi-misc-tests/src/bin/nofollow_errors.rs rename to crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs index 5dd31f66d0..8102104d09 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/nofollow_errors.rs +++ b/crates/test-programs/wasi-tests/src/bin/nofollow_errors.rs @@ -2,11 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::{ - wasi_path_open, wasi_path_remove_directory, wasi_path_symlink, -}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd, create_dir, create_file}; +use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_remove_directory, wasi_path_symlink}; unsafe fn test_nofollow_errors(dir_fd: wasi_unstable::Fd) { // Create a directory for the symlink to point to. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/path_filestat.rs b/crates/test-programs/wasi-tests/src/bin/path_filestat.rs similarity index 97% rename from crates/wasi-common/wasi-misc-tests/src/bin/path_filestat.rs rename to crates/test-programs/wasi-tests/src/bin/path_filestat.rs index 2c831466e4..3ff999c3c5 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/path_filestat.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_filestat.rs @@ -1,10 +1,9 @@ -use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd}; -use wasi_misc_tests::wasi_wrappers::{ +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd}; +use wasi_tests::wasi_wrappers::{ wasi_fd_fdstat_get, wasi_path_filestat_get, wasi_path_filestat_set_times, wasi_path_open, }; diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/path_link.rs b/crates/test-programs/wasi-tests/src/bin/path_link.rs similarity index 98% rename from crates/wasi-common/wasi-misc-tests/src/bin/path_link.rs rename to crates/test-programs/wasi-tests/src/bin/path_link.rs index 9da0d0b076..aea328db3d 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/path_link.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_link.rs @@ -1,9 +1,9 @@ use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::{ +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; +use wasi_tests::wasi_wrappers::{ wasi_fd_fdstat_get, wasi_fd_filestat_get, wasi_path_link, wasi_path_open, wasi_path_symlink, }; diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/path_open_dirfd_not_dir.rs b/crates/test-programs/wasi-tests/src/bin/path_open_dirfd_not_dir.rs similarity index 91% rename from crates/wasi-common/wasi-misc-tests/src/bin/path_open_dirfd_not_dir.rs rename to crates/test-programs/wasi-tests/src/bin/path_open_dirfd_not_dir.rs index 2b99971d9c..113c1d6a57 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/path_open_dirfd_not_dir.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_open_dirfd_not_dir.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::close_fd; -use wasi_misc_tests::wasi_wrappers::wasi_path_open; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::close_fd; +use wasi_tests::wasi_wrappers::wasi_path_open; unsafe fn test_dirfd_not_dir(dir_fd: wasi_unstable::Fd) { // Open a file. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/path_rename.rs b/crates/test-programs/wasi-tests/src/bin/path_rename.rs similarity index 96% rename from crates/wasi-common/wasi-misc-tests/src/bin/path_rename.rs rename to crates/test-programs/wasi-tests/src/bin/path_rename.rs index f7e5b7af44..d8d2fd3f22 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/path_rename.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_rename.rs @@ -1,10 +1,9 @@ -use libc; use more_asserts::assert_gt; use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, cleanup_file, close_fd, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::{wasi_path_open, wasi_path_rename}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, cleanup_file, close_fd, create_dir, create_file}; +use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_rename}; unsafe fn test_path_rename(dir_fd: wasi_unstable::Fd) { // First, try renaming a dir to nonexistent path diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/path_rename_trailing_slashes.rs b/crates/test-programs/wasi-tests/src/bin/path_rename_trailing_slashes.rs similarity index 91% rename from crates/wasi-common/wasi-misc-tests/src/bin/path_rename_trailing_slashes.rs rename to crates/test-programs/wasi-tests/src/bin/path_rename_trailing_slashes.rs index 17a9785735..a1b347c683 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/path_rename_trailing_slashes.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_rename_trailing_slashes.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::wasi_path_rename; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; +use wasi_tests::wasi_wrappers::wasi_path_rename; unsafe fn test_path_rename_trailing_slashes(dir_fd: wasi_unstable::Fd) { // Test renaming a file with a trailing slash in the name. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/path_symlink_trailing_slashes.rs b/crates/test-programs/wasi-tests/src/bin/path_symlink_trailing_slashes.rs similarity index 92% rename from crates/wasi-common/wasi-misc-tests/src/bin/path_symlink_trailing_slashes.rs rename to crates/test-programs/wasi-tests/src/bin/path_symlink_trailing_slashes.rs index c10a61c723..7eb4eea2b4 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/path_symlink_trailing_slashes.rs +++ b/crates/test-programs/wasi-tests/src/bin/path_symlink_trailing_slashes.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::wasi_path_symlink; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, cleanup_file, create_dir, create_file}; +use wasi_tests::wasi_wrappers::wasi_path_symlink; unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi_unstable::Fd) { // Link destination shouldn't end with a slash. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/poll_oneoff.rs b/crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs similarity index 99% rename from crates/wasi-common/wasi-misc-tests/src/bin/poll_oneoff.rs rename to crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs index c303c08926..37b51d3985 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/poll_oneoff.rs +++ b/crates/test-programs/wasi-tests/src/bin/poll_oneoff.rs @@ -1,8 +1,7 @@ -use libc; use more_asserts::assert_gt; use std::{env, mem::MaybeUninit, process}; use wasi::wasi_unstable; -use wasi_misc_tests::{ +use wasi_tests::{ open_scratch_directory, utils::{cleanup_file, close_fd}, wasi_wrappers::wasi_path_open, diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/readlink.rs b/crates/test-programs/wasi-tests/src/bin/readlink.rs similarity index 91% rename from crates/wasi-common/wasi-misc-tests/src/bin/readlink.rs rename to crates/test-programs/wasi-tests/src/bin/readlink.rs index 23ee02d56b..11486d1607 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/readlink.rs +++ b/crates/test-programs/wasi-tests/src/bin/readlink.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, create_file}; -use wasi_misc_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, create_file}; +use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink}; unsafe fn test_readlink(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/readlink_no_buffer.rs b/crates/test-programs/wasi-tests/src/bin/readlink_no_buffer.rs similarity index 88% rename from crates/wasi-common/wasi-misc-tests/src/bin/readlink_no_buffer.rs rename to crates/test-programs/wasi-tests/src/bin/readlink_no_buffer.rs index 695aff6951..9886258a05 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/readlink_no_buffer.rs +++ b/crates/test-programs/wasi-tests/src/bin/readlink_no_buffer.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::cleanup_file; -use wasi_misc_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::cleanup_file; +use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink}; unsafe fn test_readlink_no_buffer(dir_fd: wasi_unstable::Fd) { // First create a dangling symlink. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/remove_directory_trailing_slashes.rs b/crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs similarity index 91% rename from crates/wasi-common/wasi-misc-tests/src/bin/remove_directory_trailing_slashes.rs rename to crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs index 85f83eb0fd..a1bc56a82e 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/remove_directory_trailing_slashes.rs +++ b/crates/test-programs/wasi-tests/src/bin/remove_directory_trailing_slashes.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::wasi_path_remove_directory; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, create_dir, create_file}; +use wasi_tests::wasi_wrappers::wasi_path_remove_directory; unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi_unstable::Fd) { // Create a directory in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/remove_nonempty_directory.rs b/crates/test-programs/wasi-tests/src/bin/remove_nonempty_directory.rs similarity index 89% rename from crates/wasi-common/wasi-misc-tests/src/bin/remove_nonempty_directory.rs rename to crates/test-programs/wasi-tests/src/bin/remove_nonempty_directory.rs index 8f990d6958..81f9107dcd 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/remove_nonempty_directory.rs +++ b/crates/test-programs/wasi-tests/src/bin/remove_nonempty_directory.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, create_dir}; -use wasi_misc_tests::wasi_wrappers::wasi_path_remove_directory; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, create_dir}; +use wasi_tests::wasi_wrappers::wasi_path_remove_directory; unsafe fn test_remove_nonempty_directory(dir_fd: wasi_unstable::Fd) { // Create a directory in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/renumber.rs b/crates/test-programs/wasi-tests/src/bin/renumber.rs similarity index 95% rename from crates/wasi-common/wasi-misc-tests/src/bin/renumber.rs rename to crates/test-programs/wasi-tests/src/bin/renumber.rs index 7e4a097c0a..3bab561028 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/renumber.rs +++ b/crates/test-programs/wasi-tests/src/bin/renumber.rs @@ -2,9 +2,9 @@ use libc; use more_asserts::assert_gt; use std::{env, mem, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::close_fd; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::close_fd; +use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open}; unsafe fn test_renumber(dir_fd: wasi_unstable::Fd) { let pre_fd: wasi_unstable::Fd = (libc::STDERR_FILENO + 1) as wasi_unstable::Fd; diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/sched_yield.rs b/crates/test-programs/wasi-tests/src/bin/sched_yield.rs similarity index 100% rename from crates/wasi-common/wasi-misc-tests/src/bin/sched_yield.rs rename to crates/test-programs/wasi-tests/src/bin/sched_yield.rs diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/symlink_loop.rs b/crates/test-programs/wasi-tests/src/bin/symlink_loop.rs similarity index 87% rename from crates/wasi-common/wasi-misc-tests/src/bin/symlink_loop.rs rename to crates/test-programs/wasi-tests/src/bin/symlink_loop.rs index 6972f5ad62..b8d8b34a34 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/symlink_loop.rs +++ b/crates/test-programs/wasi-tests/src/bin/symlink_loop.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::cleanup_file; -use wasi_misc_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::cleanup_file; +use wasi_tests::wasi_wrappers::{wasi_path_open, wasi_path_symlink}; unsafe fn test_symlink_loop(dir_fd: wasi_unstable::Fd) { // Create a self-referencing symlink. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/truncation_rights.rs b/crates/test-programs/wasi-tests/src/bin/truncation_rights.rs similarity index 96% rename from crates/wasi-common/wasi-misc-tests/src/bin/truncation_rights.rs rename to crates/test-programs/wasi-tests/src/bin/truncation_rights.rs index e400c4e2a5..11ba2e77f0 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/truncation_rights.rs +++ b/crates/test-programs/wasi-tests/src/bin/truncation_rights.rs @@ -1,8 +1,8 @@ use std::{env, mem, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_file, close_fd, create_file}; -use wasi_misc_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open}; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_file, close_fd, create_file}; +use wasi_tests::wasi_wrappers::{wasi_fd_fdstat_get, wasi_path_open}; unsafe fn test_truncation_rights(dir_fd: wasi_unstable::Fd) { // Create a file in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/bin/unlink_file_trailing_slashes.rs b/crates/test-programs/wasi-tests/src/bin/unlink_file_trailing_slashes.rs similarity index 90% rename from crates/wasi-common/wasi-misc-tests/src/bin/unlink_file_trailing_slashes.rs rename to crates/test-programs/wasi-tests/src/bin/unlink_file_trailing_slashes.rs index 5d7b3aa69a..14031c5f13 100644 --- a/crates/wasi-common/wasi-misc-tests/src/bin/unlink_file_trailing_slashes.rs +++ b/crates/test-programs/wasi-tests/src/bin/unlink_file_trailing_slashes.rs @@ -1,8 +1,8 @@ use std::{env, process}; use wasi::wasi_unstable; -use wasi_misc_tests::open_scratch_directory; -use wasi_misc_tests::utils::{cleanup_dir, create_dir, create_file}; -use wasi_misc_tests::wasi_wrappers::wasi_path_unlink_file; +use wasi_tests::open_scratch_directory; +use wasi_tests::utils::{cleanup_dir, create_dir, create_file}; +use wasi_tests::wasi_wrappers::wasi_path_unlink_file; unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi_unstable::Fd) { // Create a directory in the scratch directory. diff --git a/crates/wasi-common/wasi-misc-tests/src/lib.rs b/crates/test-programs/wasi-tests/src/lib.rs similarity index 100% rename from crates/wasi-common/wasi-misc-tests/src/lib.rs rename to crates/test-programs/wasi-tests/src/lib.rs diff --git a/crates/wasi-common/wasi-misc-tests/src/utils.rs b/crates/test-programs/wasi-tests/src/utils.rs similarity index 100% rename from crates/wasi-common/wasi-misc-tests/src/utils.rs rename to crates/test-programs/wasi-tests/src/utils.rs diff --git a/crates/wasi-common/wasi-misc-tests/src/wasi_wrappers.rs b/crates/test-programs/wasi-tests/src/wasi_wrappers.rs similarity index 100% rename from crates/wasi-common/wasi-misc-tests/src/wasi_wrappers.rs rename to crates/test-programs/wasi-tests/src/wasi_wrappers.rs diff --git a/crates/wasi-common/Cargo.toml b/crates/wasi-common/Cargo.toml index af72f44e7d..2a1dd54298 100644 --- a/crates/wasi-common/Cargo.toml +++ b/crates/wasi-common/Cargo.toml @@ -10,11 +10,6 @@ repository = "https://github.com/bytecodealliance/wasmtime" readme = "README.md" edition = "2018" -[features] -# this feature requires wasm32-wasi target installed, and it enables wasm32 -# integration tests when run with `cargo test --features wasm_tests` -wasm_tests = [] - [dependencies] wasi-common-cbindgen = { path = "wasi-common-cbindgen" } anyhow = "1.0" @@ -36,21 +31,6 @@ winx = { path = "winx" } winapi = "0.3" cpu-time = "1.0" -[dev-dependencies] -wasmtime-runtime = { path = "../runtime" } -wasmtime-environ = { path = "../environ" } -wasmtime-jit = { path = "../jit" } -wasmtime-wasi = { path = "../wasi" } -wasmtime = { path = "../api" } -cranelift-codegen = "0.50.0" -target-lexicon = "0.9.0" -pretty_env_logger = "0.3.0" -tempfile = "3.1.0" -os_pipe = "0.9" - -[build-dependencies] -cfg-if = "0.1.9" - [lib] name = "wasi_common" crate-type = ["rlib", "staticlib", "cdylib"] diff --git a/crates/wasi-common/build.rs b/crates/wasi-common/build.rs deleted file mode 100644 index 4a19ddb322..0000000000 --- a/crates/wasi-common/build.rs +++ /dev/null @@ -1,204 +0,0 @@ -//! Build program to generate a program which runs all the testsuites. -//! -//! By generating a separate `#[test]` test for each file, we allow cargo test -//! to automatically run the files in parallel. -//! -//! Idea adapted from: https://github.com/bytecodealliance/wasmtime/blob/master/build.rs -//! Thanks @sunfishcode - -fn main() { - #[cfg(feature = "wasm_tests")] - wasm_tests::build_and_generate_tests(); -} - -#[cfg(feature = "wasm_tests")] -mod wasm_tests { - use std::env; - use std::fs::{read_dir, DirEntry, File}; - use std::io::{self, Write}; - use std::path::{Path, PathBuf}; - use std::process::{Command, Stdio}; - - pub(crate) fn build_and_generate_tests() { - // Validate if any of test sources are present and if they changed - // This should always work since there is no submodule to init anymore - let bin_tests = std::fs::read_dir("wasi-misc-tests/src/bin").unwrap(); - for test in bin_tests { - if let Ok(test_file) = test { - let test_file_path = test_file - .path() - .into_os_string() - .into_string() - .expect("test file path"); - println!("cargo:rerun-if-changed={}", test_file_path); - } - } - // Build tests to OUT_DIR (target/*/build/wasi-common-*/out/wasm32-wasi/release/*.wasm) - let out_dir = PathBuf::from( - env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"), - ); - let mut out = File::create(out_dir.join("wasi_misc_tests.rs")) - .expect("error generating test source file"); - build_tests("wasi-misc-tests", &out_dir).expect("building tests"); - test_directory(&mut out, "wasi-misc-tests", &out_dir).expect("generating tests"); - } - - fn build_tests(testsuite: &str, out_dir: &Path) -> io::Result<()> { - let mut cmd = Command::new("cargo"); - cmd.args(&[ - "build", - "--release", - "--target=wasm32-wasi", - "--target-dir", - out_dir.to_str().unwrap(), - ]) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) - .current_dir(testsuite); - let output = cmd.output()?; - - let status = output.status; - if !status.success() { - panic!( - "Building tests failed: exit code: {}", - status.code().unwrap() - ); - } - - Ok(()) - } - - fn test_directory(out: &mut File, testsuite: &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")) - .filter(|dir_entry| { - let p = dir_entry.path(); - if let Some(ext) = p.extension() { - // Only look at wast files. - if ext == "wasm" { - // Ignore files starting with `.`, which could be editor temporary files - if let Some(stem) = p.file_stem() { - if let Some(stemstr) = stem.to_str() { - if !stemstr.starts_with('.') { - return true; - } - } - } - } - } - false - }) - .collect(); - - dir_entries.sort_by_key(|dir| dir.path()); - - writeln!( - out, - "mod {} {{", - Path::new(testsuite) - .file_stem() - .expect("testsuite filename should have a stem") - .to_str() - .expect("testsuite filename should be representable as a string") - .replace("-", "_") - )?; - writeln!(out, " use super::{{runtime, utils, setup_log}};")?; - for dir_entry in dir_entries { - write_testsuite_tests(out, dir_entry, testsuite)?; - } - writeln!(out, "}}")?; - Ok(()) - } - - fn write_testsuite_tests( - out: &mut File, - dir_entry: DirEntry, - testsuite: &str, - ) -> io::Result<()> { - let path = dir_entry.path(); - let stemstr = path - .file_stem() - .expect("file_stem") - .to_str() - .expect("to_str"); - - writeln!(out, " #[test]")?; - if ignore(testsuite, stemstr) { - writeln!(out, " #[ignore]")?; - } - writeln!( - out, - " fn r#{}() -> anyhow::Result<()> {{", - &stemstr.replace("-", "_") - )?; - writeln!(out, " setup_log();")?; - write!( - out, - " let path = std::path::Path::new(r#\"{}\"#);", - path.display() - )?; - writeln!(out, " let data = utils::read_wasm(path)?;")?; - writeln!( - out, - " let bin_name = utils::extract_exec_name_from_path(path)?;" - )?; - let workspace = if no_preopens(testsuite, stemstr) { - "None" - } else { - writeln!( - out, - " let workspace = utils::prepare_workspace(&bin_name)?;" - )?; - "Some(workspace.path())" - }; - writeln!( - out, - " runtime::instantiate(&data, &bin_name, {})", - workspace - )?; - writeln!(out, " }}")?; - writeln!(out)?; - Ok(()) - } - - cfg_if::cfg_if! { - if #[cfg(not(windows))] { - /// Ignore tests that aren't supported yet. - fn ignore(_testsuite: &str, _name: &str) -> bool { - false - } - } else { - /// Ignore tests that aren't supported yet. - fn ignore(testsuite: &str, name: &str) -> bool { - if testsuite == "wasi-misc-tests" { - match name { - "readlink_no_buffer" => true, - "dangling_symlink" => true, - "symlink_loop" => true, - "truncation_rights" => true, - "poll_oneoff" => true, - "path_link" => true, - _ => false, - } - } else { - unreachable!() - } - } - } - } - - /// Mark tests which do not require preopens - fn no_preopens(testsuite: &str, name: &str) -> bool { - if testsuite == "wasi-misc-tests" { - match name { - "big_random_buf" => true, - "clock_time_get" => true, - "sched_yield" => true, - _ => false, - } - } else { - unreachable!() - } - } -} diff --git a/crates/wasi-common/wasi-misc-tests/Cargo.toml b/crates/wasi-common/wasi-misc-tests/Cargo.toml deleted file mode 100644 index 101a850cad..0000000000 --- a/crates/wasi-common/wasi-misc-tests/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "wasi-misc-tests" -version = "0.1.0" -authors = ["The Wasmtime Project Developers"] -readme = "README.md" -edition = "2018" -publish = false - -[dependencies] -libc = "0.2.65" -wasi = "0.7.0" -more-asserts = "0.2.1" diff --git a/crates/wasi-common/wasi-misc-tests/README.md b/crates/wasi-common/wasi-misc-tests/README.md deleted file mode 100644 index ded59fb000..0000000000 --- a/crates/wasi-common/wasi-misc-tests/README.md +++ /dev/null @@ -1,4 +0,0 @@ -This is the `wasi-misc-test` crate, which contains source code for the system-level WASI tests. - -Building these tests requires `wasm32-wasi` target installed -