Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wasi-tests to test multiple versions of WASI #1300

Merged
merged 4 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: spectests emtests clean build install lint precommit docs examples
.PHONY: spectests emtests clean build install lint precommit docs examples

# Generate files
generate-spectests:
Expand All @@ -11,15 +11,31 @@ generate-emtests:
&& echo "formatting" \
&& cargo fmt

# To generate WASI tests you'll need to have the correct versions of the Rust nightly
# toolchain installed, see `WasiVersion::get_compiler_toolchain` in
# `lib/wasi-tests/build/wasi_version.rs`
#
# or run `make wasitests-setup-toolchain` or `make wasitests-setup-toolchain-all`
generate-wasitests: wasitests-setup
WASM_WASI_GENERATE_WASITESTS=1 cargo build -p wasmer-wasi-tests --release -vv \
&& echo "formatting" \
&& cargo fmt

generate-wasitests-all: wasitests-setup
WASI_TEST_GENERATE_ALL=1 WASM_WASI_GENERATE_WASITESTS=1 cargo build -p wasmer-wasi-tests --release -vv \
&& echo "formatting" \
&& cargo fmt

spectests-generate: generate-spectests
emtests-generate: generate-emtests
wasitests-generate: generate-wasitests

wasitests-setup-toolchain: wasitests-setup
WASITESTS_SET_UP_TOOLCHAIN=1 cargo build -p wasmer-wasi-tests --release -vv

wasitests-setup-toolchain-all: wasitests-setup
WASI_TEST_GENERATE_ALL=1 WASITESTS_SET_UP_TOOLCHAIN=1 cargo build -p wasmer-wasi-tests --release -vv

generate: generate-spectests generate-emtests generate-wasitests


Expand Down Expand Up @@ -67,6 +83,8 @@ middleware: middleware-singlepass middleware-cranelift middleware-llvm

# Wasitests
wasitests-setup:
# force cargo to rerun the build.rs step
touch lib/wasi-tests/build/mod.rs
rm -rf lib/wasi-tests/wasitests/test_fs/temp
mkdir -p lib/wasi-tests/wasitests/test_fs/temp

Expand Down
1 change: 1 addition & 0 deletions lib/wasi-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ wasmer-llvm-backend = { path = "../llvm-backend", version = "0.16.2", features =

[build-dependencies]
glob = "0.3"
tempfile = "3"

[dev-dependencies]
wasmer-dev-utils = { path = "../dev-utils", version = "0.16.2"}
Expand Down
11 changes: 10 additions & 1 deletion lib/wasi-tests/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use std::env;

mod set_up_toolchain;
mod util;
mod wasi_version;
mod wasitests;

static WASITESTS_ENV_VAR: &str = "WASM_WASI_GENERATE_WASITESTS";
static WASITESTS_SET_UP_TOOLCHAIN: &str = "WASM_WASI_SET_UP_TOOLCHAIN";

fn main() {
let do_all_wasi_tests = util::should_operate_on_all_wasi_tests();
if env::var(WASITESTS_SET_UP_TOOLCHAIN).unwrap_or("0".to_string()) == "1" {
set_up_toolchain::set_it_up(do_all_wasi_tests);
}

if env::var(WASITESTS_ENV_VAR).unwrap_or("0".to_string()) == "1" {
wasitests::build();
wasitests::build(do_all_wasi_tests);
}
}
31 changes: 31 additions & 0 deletions lib/wasi-tests/build/set_up_toolchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::util;
use crate::wasi_version::*;

use std::process::Command;

fn install_toolchain(toolchain_name: &str) {
println!("Installing rustup toolchain: {}", toolchain_name);
let rustup_out = Command::new("rustup")
.arg("toolchain")
.arg("install")
.arg(toolchain_name)
.output()
.expect("Failed to install toolchain with rustup");
util::print_info_on_error(&rustup_out, "TOOLCHAIN INSTALL FAILED");
}

pub fn set_it_up(only_latest: bool) {
println!("Setting up system to generate the WASI tests.");
println!("WARNING: this may use a lot of disk space.");

let wasi_versions = if only_latest {
println!("Only installing the toolchain for the latest WASI version");
LATEST_WASI_VERSION
} else {
println!("Installing the toolchain for all WASI versions");
ALL_WASI_VERSIONS
};
for wasi_version in wasi_versions {
install_toolchain(wasi_version.get_compiler_toolchain());
}
}
22 changes: 22 additions & 0 deletions lib/wasi-tests/build/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pub fn print_info_on_error(output: &std::process::Output, context: &str) {
if !output.status.success() {
println!("{}", context);
println!(
"stdout:\n{}",
std::str::from_utf8(&output.stdout[..]).unwrap()
);
eprintln!(
"stderr:\n{}",
std::str::from_utf8(&output.stderr[..]).unwrap()
);
}
}

/// Whether or not we should operate on all WASI tests or not
pub fn should_operate_on_all_wasi_tests() -> bool {
std::env::var("WASI_TEST_GENERATE_ALL")
.ok()
.and_then(|s| s.parse::<u32>().ok())
.unwrap_or(0)
== 1
}
29 changes: 29 additions & 0 deletions lib/wasi-tests/build/wasi_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub static ALL_WASI_VERSIONS: &[WasiVersion] = &[WasiVersion::Unstable, WasiVersion::Snapshot1];
pub static LATEST_WASI_VERSION: &[WasiVersion] = &[WasiVersion::get_latest()];

#[derive(Debug, Clone, Copy)]
pub enum WasiVersion {
/// A.K.A. Snapshot0
Unstable,
Snapshot1,
}

impl WasiVersion {
pub const fn get_latest() -> Self {
Self::Snapshot1
}

pub fn get_compiler_toolchain(&self) -> &'static str {
match self {
WasiVersion::Unstable => "nightly-2019-09-13",
WasiVersion::Snapshot1 => "nightly-2019-12-18",
}
}

pub fn get_directory_name(&self) -> &'static str {
match self {
WasiVersion::Unstable => "unstable",
WasiVersion::Snapshot1 => "snapshot1",
}
}
}
Loading