Begin readding WASI tests

This commit is contained in:
Mark McCaskey
2020-06-18 14:44:33 -07:00
parent 6a9d0faaad
commit c5a879146a
7 changed files with 69 additions and 4 deletions

11
Cargo.lock generated
View File

@ -1993,6 +1993,16 @@ version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi-test-generator"
version = "0.17.0"
dependencies = [
"glob",
"serde",
"serde_json",
"tempfile",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.63"
@ -2099,6 +2109,7 @@ dependencies = [
"structopt",
"test-generator",
"test-utils",
"wasi-test-generator",
"wasm-common",
"wasmer",
"wasmer-cache",

View File

@ -56,6 +56,7 @@ members = [
[build-dependencies]
test-generator = { path = "tests/lib/test-generator" }
wasi-test-generator = { path = "tests/lib/wasi-test-generator" }
anyhow = "1.0"
glob = "0.3"
rustc_version = "0.2"

View File

@ -91,6 +91,24 @@ build-capi-llvm:
cargo build --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features jit,llvm,wasi
###################
# Test Generation #
###################
generate-wasitests:
WASM_WASI_GENERATE_WASITESTS=1 cargo build --release -vv \
&& echo "formatting" \
&& cargo fmt
generate-wasitests-all:
WASI_TEST_GENERATE_ALL=1 WASM_WASI_GENERATE_WASITESTS=1 cargo build --release -vv \
&& echo "formatting" \
&& cargo fmt
wasitests-setup-toolchain: wasitests-setup
WASM_WASI_SET_UP_TOOLCHAIN=1 cargo build --release -vv
generate: generate-wasitests
###########
# Testing #
@ -111,6 +129,7 @@ test-packages:
cargo test -p wasmer --release
cargo test -p wasmer-runtime --release
cargo test -p wasm-common --release
cargo test -p wasmer-wasi --release
test-capi-singlepass: build-capi-singlepass
cargo test --manifest-path lib/c-api/Cargo.toml --release \
@ -126,6 +145,9 @@ test-capi-llvm: build-capi-llvm
test-capi: test-capi-singlepass test-capi-cranelift test-capi-llvm test-capi-emscripten
test-wasi-unit:
cargo test --manifest-path lib/wasi/Cargo.toml --release
#############
# Packaging #
#############

View File

@ -12,10 +12,38 @@ use test_generator::{
build_ignores_from_textfile, test_directory, test_directory_module, wast_processor,
with_features, with_test_module, Testsuite,
};
use wasi_test_generator;
static WASITESTS_ENV_VAR: &str = "WASM_WASI_GENERATE_WASITESTS";
static WASITESTS_SET_UP_TOOLCHAIN: &str = "WASM_WASI_SET_UP_TOOLCHAIN";
static WASITESTS_GENERATE_ALL: &str = "WASI_TEST_GENERATE_ALL";
fn is_truthy_env(name: &str) -> bool {
env::var(name).map(|n| n == "1").unwrap_or_default()
}
fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=tests/ignores.txt");
println!("cargo:rerun-if-env-changed={}", WASITESTS_ENV_VAR);
println!("cargo:rerun-if-env-changed={}", WASITESTS_SET_UP_TOOLCHAIN);
println!("cargo:rerun-if-env-changed={}", WASITESTS_GENERATE_ALL);
let wasi_versions = if is_truthy_env(WASITESTS_GENERATE_ALL) {
wasi_test_generator::ALL_WASI_VERSIONS
} else {
wasi_test_generator::LATEST_WASI_VERSION
};
// Install the Rust WASI toolchains for each of the versions
if is_truthy_env(WASITESTS_SET_UP_TOOLCHAIN) {
wasi_test_generator::install_toolchains(wasi_versions);
}
// Generate the WASI Wasm files
if is_truthy_env(WASITESTS_ENV_VAR) {
wasi_test_generator::build(wasi_versions);
}
let out_dir = PathBuf::from(
env::var_os("OUT_DIR").expect("The OUT_DIR environment variable must be set"),

View File

@ -21,7 +21,10 @@ mod utils;
use crate::syscalls::*;
pub use crate::state::{Fd, WasiFile, WasiFs, WasiFsError, WasiState, ALL_RIGHTS, VIRTUAL_ROOT_FD};
pub use crate::state::{
Fd, WasiFile, WasiFs, WasiFsError, WasiState, WasiStateCreationError, ALL_RIGHTS,
VIRTUAL_ROOT_FD,
};
pub use crate::syscalls::types;
pub use crate::utils::{get_wasi_version, is_wasi_module, WasiVersion};

View File

@ -20,7 +20,7 @@ pub(crate) fn create_wasi_state(program_name: &str) -> WasiStateBuilder {
///
/// Usage:
/// ```no_run
/// # use wasmer_wasi::state::{WasiState, WasiStateCreationError};
/// # use wasmer_wasi::{WasiState, WasiStateCreationError};
/// # fn main() -> Result<(), WasiStateCreationError> {
/// let mut state_builder = WasiState::new("wasi-prog-name");
/// state_builder
@ -196,7 +196,7 @@ impl WasiStateBuilder {
/// Usage:
///
/// ```no_run
/// # use wasmer_wasi::state::{WasiState, WasiStateCreationError};
/// # use wasmer_wasi::{WasiState, WasiStateCreationError};
/// # fn main() -> Result<(), WasiStateCreationError> {
/// WasiState::new("program_name")
/// .preopen(|p| p.directory("src").read(true).write(true).create(true))?

View File

@ -1452,7 +1452,7 @@ impl WasiFs {
/// Usage:
///
/// ```no_run
/// # use wasmer_wasi::state::{WasiState, WasiStateCreationError};
/// # use wasmer_wasi::{WasiState, WasiStateCreationError};
/// # fn main() -> Result<(), WasiStateCreationError> {
/// WasiState::new("program_name")
/// .env(b"HOME", "/home/home".to_string())