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

Compiler tests #997

Merged
merged 10 commits into from
Nov 22, 2019
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
5 changes: 2 additions & 3 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions lib/emscripten-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ build = "build/mod.rs"

[dependencies]
wasmer-emscripten = { path = "../emscripten", version = "0.10.2" }
wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" }
wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" }
wasmer-runtime = { path = "../runtime", version = "0.10.2", default-features = false }
wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true}
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true }

Expand All @@ -23,6 +23,6 @@ wasmer-dev-utils = { path = "../dev-utils", version = "0.10.2"}
glob = "0.3"

[features]
clif = []
llvm = ["wasmer-llvm-backend"]
singlepass = ["wasmer-singlepass-backend"]
clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"]
singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"]
llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"]
34 changes: 3 additions & 31 deletions lib/emscripten-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,13 @@ mod tests {
use std::sync::Arc;
use wabt::wat2wasm;
use wasmer_emscripten::is_emscripten_module;
use wasmer_runtime_core::backend::Compiler;
use wasmer_runtime_core::compile_with;

#[cfg(feature = "clif")]
fn get_compiler() -> impl Compiler {
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

#[cfg(feature = "llvm")]
fn get_compiler() -> impl Compiler {
use wasmer_llvm_backend::LLVMCompiler;
LLVMCompiler::new()
}

#[cfg(feature = "singlepass")]
fn get_compiler() -> impl Compiler {
use wasmer_singlepass_backend::SinglePassCompiler;
SinglePassCompiler::new()
}

#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))]
fn get_compiler() -> impl Compiler {
panic!("compiler not specified, activate a compiler via features");
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}
use wasmer_runtime::compile;

#[test]
fn should_detect_emscripten_files() {
const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_true.wast");
let wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm");
let module =
compile_with(&wasm_binary[..], &get_compiler()).expect("WASM can't be compiled");
let module = compile(&wasm_binary[..]).expect("WASM can't be compiled");
let module = Arc::new(module);
assert!(is_emscripten_module(&module));
}
Expand All @@ -45,8 +18,7 @@ mod tests {
fn should_detect_non_emscripten_files() {
const WAST_BYTES: &[u8] = include_bytes!("tests/is_emscripten_false.wast");
let wasm_binary = wat2wasm(WAST_BYTES.to_vec()).expect("Can't convert to wasm");
let module =
compile_with(&wasm_binary[..], &get_compiler()).expect("WASM can't be compiled");
let module = compile(&wasm_binary[..]).expect("WASM can't be compiled");
let module = Arc::new(module);
assert!(!is_emscripten_module(&module));
}
Expand Down
31 changes: 2 additions & 29 deletions lib/emscripten-tests/tests/emtests/_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,12 @@ macro_rules! assert_emscripten_output {
EmscriptenGlobals,
generate_emscripten_env,
};
use wasmer_runtime_core::{
backend::Compiler,
};
use wasmer_runtime::compile;
use wasmer_dev_utils::stdio::StdioCapturer;

#[cfg(feature = "clif")]
fn get_compiler() -> impl Compiler {
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

#[cfg(feature = "llvm")]
fn get_compiler() -> impl Compiler {
use wasmer_llvm_backend::LLVMCompiler;
LLVMCompiler::new()
}

#[cfg(feature = "singlepass")]
fn get_compiler() -> impl Compiler {
use wasmer_singlepass_backend::SinglePassCompiler;
SinglePassCompiler::new()
}

#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))]
fn get_compiler() -> impl Compiler {
panic!("compiler not specified, activate a compiler via features");
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

let wasm_bytes = include_bytes!($file);

let module = wasmer_runtime_core::compile_with(&wasm_bytes[..], &get_compiler())
let module = compile(&wasm_bytes[..])
.expect("WASM can't be compiled");

// let module = compile(&wasm_bytes[..])
Expand Down
11 changes: 8 additions & 3 deletions lib/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@
//! [`wasmer-clif-backend`]: https://crates.io/crates/wasmer-clif-backend
//! [`compile_with`]: fn.compile_with.html

pub use wasmer_runtime_core::backend::Backend;
pub use wasmer_runtime_core::backend::{Backend, Features};
pub use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
pub use wasmer_runtime_core::export::Export;
pub use wasmer_runtime_core::global::Global;
pub use wasmer_runtime_core::import::ImportObject;
pub use wasmer_runtime_core::import::{ImportObject, LikeNamespace};
pub use wasmer_runtime_core::instance::{DynFunc, Instance};
pub use wasmer_runtime_core::memory::ptr::{Array, Item, WasmPtr};
pub use wasmer_runtime_core::memory::Memory;
Expand Down Expand Up @@ -131,9 +131,14 @@ pub mod units {
pub use wasmer_runtime_core::units::{Bytes, Pages};
}

pub mod types {
//! Various types.
pub use wasmer_runtime_core::types::*;
}

pub mod cache;

use wasmer_runtime_core::backend::{Compiler, CompilerConfig};
pub use wasmer_runtime_core::backend::{Compiler, CompilerConfig};

/// Compile WebAssembly binary code into a [`Module`].
/// This function is useful if it is necessary to
Expand Down
10 changes: 5 additions & 5 deletions lib/spectests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ edition = "2018"

[dependencies]
glob = "0.3"
wasmer-runtime-core = { path = "../runtime-core", version = "0.10.2" }
wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2" }
wasmer-runtime = { path = "../runtime", version = "0.10.2", default-features = false}
wasmer-clif-backend = { path = "../clif-backend", version = "0.10.2", optional = true}
wasmer-llvm-backend = { path = "../llvm-backend", version = "0.10.2", optional = true }
wasmer-singlepass-backend = { path = "../singlepass-backend", version = "0.10.2", optional = true }

Expand All @@ -23,6 +23,6 @@ wabt = "0.9.1"
[features]
default = ["fast-tests"]
fast-tests = []
clif = []
llvm = ["wasmer-llvm-backend"]
singlepass = ["wasmer-singlepass-backend"]
clif = ["wasmer-clif-backend", "wasmer-runtime/default-backend-cranelift"]
singlepass = ["wasmer-singlepass-backend", "wasmer-runtime/default-backend-singlepass"]
llvm = ["wasmer-llvm-backend", "wasmer-runtime/default-backend-llvm"]
41 changes: 6 additions & 35 deletions lib/spectests/examples/simple/main.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,17 @@
use wabt::wat2wasm;
use wasmer_runtime_core::{
backend::Compiler,
error,
global::Global,
memory::Memory,
prelude::*,
table::Table,
use wasmer_runtime::{
compile, error, func, imports,
types::{ElementType, MemoryDescriptor, TableDescriptor, Value},
units::Pages,
Ctx, Global, Memory, Table,
};

#[cfg(feature = "clif")]
fn get_compiler() -> impl Compiler {
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

#[cfg(feature = "llvm")]
fn get_compiler() -> impl Compiler {
use wasmer_llvm_backend::LLVMCompiler;
LLVMCompiler::new()
}

#[cfg(feature = "singlepass")]
fn get_compiler() -> impl Compiler {
use wasmer_singlepass_backend::SinglePassCompiler;
SinglePassCompiler::new()
}

#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))]
fn get_compiler() -> impl Compiler {
panic!("compiler not specified, activate a compiler via features");
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm");

fn main() -> error::Result<()> {
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed");

let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &get_compiler())?;
let inner_module = compile(&wasm_binary)?;

let memory_desc = MemoryDescriptor::new(Pages(1), Some(Pages(1)), false).unwrap();
let memory = Memory::new(memory_desc).unwrap();
Expand Down Expand Up @@ -71,15 +42,15 @@ fn main() -> error::Result<()> {
"env" => inner_instance,
};

let outer_module = wasmer_runtime_core::compile_with(EXAMPLE_WASM, &get_compiler())?;
let outer_module = compile(EXAMPLE_WASM)?;
let outer_instance = outer_module.instantiate(&outer_imports)?;
let ret = outer_instance.call("main", &[Value::I32(42)])?;
println!("ret: {:?}", ret);

Ok(())
}

fn print_num(ctx: &mut vm::Ctx, n: i32) -> Result<i32, ()> {
fn print_num(ctx: &mut Ctx, n: i32) -> Result<i32, ()> {
println!("print_num({})", n);

let memory: &Memory = ctx.memory(0);
Expand Down
33 changes: 3 additions & 30 deletions lib/spectests/examples/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use wabt::wat2wasm;
use wasmer_runtime_core::{backend::Compiler, import::ImportObject, Instance};
use wasmer_runtime::{compile, ImportObject, Instance};

fn main() {
let instance = create_module_1();
Expand All @@ -23,38 +23,12 @@ fn create_module_1() -> Instance {
(elem (;1;) (i32.const 9) 1))
"#;
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &get_compiler())
.expect("WASM can't be compiled");
let module = compile(&wasm_binary[..]).expect("WASM can't be compiled");
module
.instantiate(&generate_imports())
.expect("WASM can't be instantiated")
}

#[cfg(feature = "clif")]
fn get_compiler() -> impl Compiler {
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

#[cfg(feature = "llvm")]
fn get_compiler() -> impl Compiler {
use wasmer_llvm_backend::LLVMCompiler;
LLVMCompiler::new()
}

#[cfg(feature = "singlepass")]
fn get_compiler() -> impl Compiler {
use wasmer_singlepass_backend::SinglePassCompiler;
SinglePassCompiler::new()
}

#[cfg(not(any(feature = "llvm", feature = "clif", feature = "singlepass")))]
fn get_compiler() -> impl Compiler {
panic!("compiler not specified, activate a compiler via features");
use wasmer_clif_backend::CraneliftCompiler;
CraneliftCompiler::new()
}

static IMPORT_MODULE: &str = r#"
(module
(type $t0 (func (param i32)))
Expand All @@ -68,8 +42,7 @@ static IMPORT_MODULE: &str = r#"

pub fn generate_imports() -> ImportObject {
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed");
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &get_compiler())
.expect("WASM can't be compiled");
let module = compile(&wasm_binary[..]).expect("WASM can't be compiled");
let instance = module
.instantiate(&ImportObject::new())
.expect("WASM can't be instantiated");
Expand Down
8 changes: 3 additions & 5 deletions lib/spectests/tests/semantics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#[cfg(test)]
mod tests {
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime_core::{
use wasmer_runtime::{
error::{CallError, RuntimeError},
import::ImportObject,
ImportObject,
};

// The semantics of stack overflow are documented at:
Expand All @@ -22,8 +21,7 @@ mod tests {
(elem (;0;) (i32.const 0) 0))
"#;
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new())
.expect("WASM can't be compiled");
let module = wasmer_runtime::compile(&wasm_binary[..]).expect("WASM can't be compiled");
let instance = module
.instantiate(&ImportObject::new())
.expect("WASM can't be instantiated");
Expand Down
Loading