Reorganize wasi-misc-tests. (#575)

* Reorganize wasi-misc-tests.

Move wasi-misc-tests out of wasi-common, to break a dependency cycle;
previously, wasmtime-* depended on wasi-common, but wasi-common
dev-dependended on wasmtime-*.

Now, wasi-common no longer dev-depends on wasmtime-*; instead, the
tests are in their own crate which depends on wasi-common and on
wasmtime-*.

Also, rename wasi-misc-tests to wasi-tests for simplicity.

This also removes the "wasm_tests" feature; it's replaced by the
"test-programs" feature.

* Update the CI script to use the new feature name.

* Update the CI script to use the new feature name in one more place.

* Change a `write!` to a `writeln!`.
This commit is contained in:
Dan Gohman
2019-11-15 08:03:43 -08:00
committed by GitHub
parent b0f558aa10
commit d4fd229e5e
49 changed files with 328 additions and 337 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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"

View File

@@ -0,0 +1,2 @@
This is the `test-programs` crate, which builds and runs whole programs
compiled to wasm32-wasi.

View File

@@ -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!()
}
}

View File

@@ -0,0 +1,2 @@
// This crate doesn't contain any code; it just exists to run tests for
// other crates in the workspace.

View File

@@ -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"));

View File

@@ -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]

View File

@@ -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.

View File

@@ -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

View File

@@ -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;

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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;

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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,
};

View File

@@ -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.

View File

@@ -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.

View File

@@ -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,
};

View File

@@ -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,
};

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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,

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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;

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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"]

View File

@@ -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!()
}
}
}

View File

@@ -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"

View File

@@ -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