From 3579d0d445aef963b3934800cee5b395fadd9653 Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 6 Apr 2020 16:47:06 -0700 Subject: [PATCH] Fix emtests and wasitests to use the correct backend --- Makefile | 20 +++++----- tests/emtests/_common.rs | 40 ++++++++++++++++--- .../integration_tests}/cowsay/README.md | 0 .../integration_tests}/cowsay/test.sh | 0 .../integration_tests}/lua/README.md | 0 .../integration_tests}/lua/test.sh | 0 .../integration_tests}/nginx/README.md | 0 .../integration_tests}/nginx/html/index.html | 0 .../integration_tests}/nginx/logs/nginx.pid | 0 .../integration_tests}/nginx/nginx.conf | 0 .../integration_tests}/nginx/test.sh | 0 tests/wasitests/_common.rs | 36 ++++++++++++++++- 12 files changed, 81 insertions(+), 15 deletions(-) rename {integration_tests => tests/integration_tests}/cowsay/README.md (100%) rename {integration_tests => tests/integration_tests}/cowsay/test.sh (100%) rename {integration_tests => tests/integration_tests}/lua/README.md (100%) rename {integration_tests => tests/integration_tests}/lua/test.sh (100%) rename {integration_tests => tests/integration_tests}/nginx/README.md (100%) rename {integration_tests => tests/integration_tests}/nginx/html/index.html (100%) rename {integration_tests => tests/integration_tests}/nginx/logs/nginx.pid (100%) rename {integration_tests => tests/integration_tests}/nginx/nginx.conf (100%) rename {integration_tests => tests/integration_tests}/nginx/test.sh (100%) diff --git a/Makefile b/Makefile index a6b40165a..69b9261ea 100644 --- a/Makefile +++ b/Makefile @@ -53,13 +53,13 @@ spectests: spectests-singlepass spectests-cranelift spectests-llvm # Emscripten tests emtests-singlepass: - cargo test emtest --release --no-default-features --features "wasi backend-singlepass" -- --test-threads=1 + WASMER_TEST_SINGLEPASS=1 cargo test emtest --release --no-default-features --features "wasi backend-singlepass" -- --test-threads=1 emtests-cranelift: - cargo test emtest --release --no-default-features --features "wasi backend-cranelift" -- --test-threads=1 + WASMER_TEST_CRANELIFT=1 cargo test emtest --release --no-default-features --features "wasi backend-cranelift" -- --test-threads=1 emtests-llvm: - cargo test emtest --release --no-default-features --features "wasi backend-llvm" -- --test-threads=1 + WASMER_TEST_LLVM=1 cargo test emtest --release --no-default-features --features "wasi backend-llvm" -- --test-threads=1 emtests-unit: cargo test emscripten --release @@ -86,13 +86,13 @@ wasitests-setup: mkdir -p tests/wasi_test_resources/test_fs/temp wasitests-singlepass: wasitests-setup - cargo test wasitest --release --no-default-features --features "wasi backend-singlepass" -- --test-threads=1 + WASMER_TEST_SINGLEPASS=1 cargo test wasitest --release --no-default-features --features "wasi backend-singlepass" -- --test-threads=1 wasitests-cranelift: wasitests-setup - cargo test wasitest --release --no-default-features --features "wasi backend-cranelift" -- --test-threads=1 --nocapture + WASMER_TEST_CRANELIFT=1 cargo test wasitest --release --no-default-features --features "wasi backend-cranelift" -- --test-threads=1 --nocapture wasitests-llvm: wasitests-setup - cargo test wasitest --release --no-default-features --features "wasi backend-llvm" -- --test-threads=1 + WASMER_TEST_LLVM=1 cargo test wasitest --release --no-default-features --features "wasi backend-llvm" -- --test-threads=1 wasitests-unit: wasitests-setup cargo test --manifest-path lib/wasi/Cargo.toml --release @@ -174,9 +174,9 @@ test-android: # Integration tests integration-tests: release-clif examples echo "Running Integration Tests" - ./integration_tests/lua/test.sh - ./integration_tests/nginx/test.sh - ./integration_tests/cowsay/test.sh + ./tests/integration_tests/lua/test.sh + ./tests/integration_tests/nginx/test.sh + ./tests/integration_tests/cowsay/test.sh examples: cargo run --example plugin @@ -287,12 +287,14 @@ release-llvm: cargo build --release --features backend-llvm,experimental-io-devices bench-singlepass: +# NOTE this will run some benchmarks using clif; TODO: fix this cargo bench --all --no-default-features --features "backend-singlepass" \ --exclude wasmer-clif-backend --exclude wasmer-llvm-backend --exclude wasmer-kernel-loader bench-clif: cargo bench --all --no-default-features --features "backend-cranelift" \ --exclude wasmer-singlepass-backend --exclude wasmer-llvm-backend --exclude wasmer-kernel-loader bench-llvm: +# NOTE this will run some benchmarks using clif; TODO: fix this cargo bench --all --no-default-features --features "backend-llvm" \ --exclude wasmer-singlepass-backend --exclude wasmer-clif-backend --exclude wasmer-kernel-loader diff --git a/tests/emtests/_common.rs b/tests/emtests/_common.rs index 2e6c590d9..d96ed0728 100644 --- a/tests/emtests/_common.rs +++ b/tests/emtests/_common.rs @@ -1,3 +1,35 @@ +use std::env; +use wasmer_runtime::Backend; + +pub fn get_backend() -> Option { + #[cfg(feature = "backend-cranelift")] + { + if let Ok(v) = env::var("WASMER_TEST_CLIF") { + if v == "1" { + return Some(Backend::Cranelift); + } + } + } + #[cfg(feature = "backend-llvm")] + { + if let Ok(v) = env::var("WASMER_TEST_LLVM") { + if v == "1" { + return Some(Backend::LLVM); + } + } + } + #[cfg(feature = "backend-singlepass")] + { + if let Ok(v) = env::var("WASMER_TEST_SINGLEPASS") { + if v == "1" { + return Some(Backend::Singlepass); + } + } + } + + None +} + macro_rules! assert_emscripten_output { ($file:expr, $name:expr, $args:expr, $expected:expr) => {{ @@ -5,16 +37,14 @@ macro_rules! assert_emscripten_output { EmscriptenGlobals, generate_emscripten_env, }; - use wasmer_runtime::compile; use wasmer_dev_utils::stdio::StdioCapturer; let wasm_bytes = include_bytes!($file); + let backend = $crate::emtests::_common::get_backend().expect("Please set one of `WASMER_TEST_CLIF`, `WASMER_TEST_LLVM`, or `WASMER_TEST_SINGELPASS` to `1`."); + let compiler = wasmer_runtime::compiler_for_backend(backend).expect("The desired compiler was not found!"); - let module = compile(&wasm_bytes[..]) - .expect("WASM can't be compiled"); + let module = wasmer_runtime::compile_with_config_with(&wasm_bytes[..], Default::default(), &*compiler).expect("WASM can't be compiled"); -// let module = compile(&wasm_bytes[..]) -// .map_err(|err| format!("Can't create the WebAssembly module: {}", err)).unwrap(); // NOTE: Need to figure what the unwrap is for ?? let mut emscripten_globals = EmscriptenGlobals::new(&module).expect("globals are valid"); let import_object = generate_emscripten_env(&mut emscripten_globals); diff --git a/integration_tests/cowsay/README.md b/tests/integration_tests/cowsay/README.md similarity index 100% rename from integration_tests/cowsay/README.md rename to tests/integration_tests/cowsay/README.md diff --git a/integration_tests/cowsay/test.sh b/tests/integration_tests/cowsay/test.sh similarity index 100% rename from integration_tests/cowsay/test.sh rename to tests/integration_tests/cowsay/test.sh diff --git a/integration_tests/lua/README.md b/tests/integration_tests/lua/README.md similarity index 100% rename from integration_tests/lua/README.md rename to tests/integration_tests/lua/README.md diff --git a/integration_tests/lua/test.sh b/tests/integration_tests/lua/test.sh similarity index 100% rename from integration_tests/lua/test.sh rename to tests/integration_tests/lua/test.sh diff --git a/integration_tests/nginx/README.md b/tests/integration_tests/nginx/README.md similarity index 100% rename from integration_tests/nginx/README.md rename to tests/integration_tests/nginx/README.md diff --git a/integration_tests/nginx/html/index.html b/tests/integration_tests/nginx/html/index.html similarity index 100% rename from integration_tests/nginx/html/index.html rename to tests/integration_tests/nginx/html/index.html diff --git a/integration_tests/nginx/logs/nginx.pid b/tests/integration_tests/nginx/logs/nginx.pid similarity index 100% rename from integration_tests/nginx/logs/nginx.pid rename to tests/integration_tests/nginx/logs/nginx.pid diff --git a/integration_tests/nginx/nginx.conf b/tests/integration_tests/nginx/nginx.conf similarity index 100% rename from integration_tests/nginx/nginx.conf rename to tests/integration_tests/nginx/nginx.conf diff --git a/integration_tests/nginx/test.sh b/tests/integration_tests/nginx/test.sh similarity index 100% rename from integration_tests/nginx/test.sh rename to tests/integration_tests/nginx/test.sh diff --git a/tests/wasitests/_common.rs b/tests/wasitests/_common.rs index d457d0ca4..1f7659f06 100644 --- a/tests/wasitests/_common.rs +++ b/tests/wasitests/_common.rs @@ -1,3 +1,35 @@ +use std::env; +use wasmer_runtime::Backend; + +pub fn get_backend() -> Option { + #[cfg(feature = "backend-cranelift")] + { + if let Ok(v) = env::var("WASMER_TEST_CLIF") { + if v == "1" { + return Some(Backend::Cranelift); + } + } + } + #[cfg(feature = "backend-llvm")] + { + if let Ok(v) = env::var("WASMER_TEST_LLVM") { + if v == "1" { + return Some(Backend::LLVM); + } + } + } + #[cfg(feature = "backend-singlepass")] + { + if let Ok(v) = env::var("WASMER_TEST_SINGLEPASS") { + if v == "1" { + return Some(Backend::Singlepass); + } + } + } + + None +} + macro_rules! assert_wasi_output { ($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{ use wasmer_dev_utils::stdio::StdioCapturer; @@ -5,8 +37,10 @@ macro_rules! assert_wasi_output { use wasmer_wasi::{generate_import_object_for_version, get_wasi_version}; let wasm_bytes = include_bytes!($file); + let backend = $crate::wasitests::_common::get_backend().expect("Please set one of `WASMER_TEST_CLIF`, `WASMER_TEST_LLVM`, or `WASMER_TEST_SINGELPASS` to `1`."); + let compiler = wasmer_runtime::compiler_for_backend(backend).expect("The desired compiler was not found!"); - let module = wasmer_runtime::compile(&wasm_bytes[..]).expect("WASM can't be compiled"); + let module = wasmer_runtime::compile_with_config_with(&wasm_bytes[..], Default::default(), &*compiler).expect("WASM can't be compiled"); let wasi_version = get_wasi_version(&module, true).expect("WASI module");