Skip to content

Commit

Permalink
Begin readding WASI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark McCaskey committed Jun 18, 2020
1 parent 6a9d0fa commit c5a8791
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 4 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand All @@ -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 \
Expand All @@ -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 #
#############
Expand Down
28 changes: 28 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
5 changes: 4 additions & 1 deletion lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))?
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 @@ -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())
Expand Down

0 comments on commit c5a8791

Please sign in to comment.