Only run runtime_core tests on Android

This commit is contained in:
Mark McCaskey
2020-04-06 14:13:54 -07:00
parent 9d312f4500
commit b6011d5dc4
3 changed files with 241 additions and 235 deletions

View File

@ -169,7 +169,7 @@ test: spectests emtests middleware wasitests test-rest examples
test-android:
ci/run-docker.sh x86_64-linux-android --manifest-path=lib/singlepass-backend/Cargo.toml
ci/run-docker.sh x86_64-linux-android
ci/run-docker.sh x86_64-linux-android runtime_core
# Integration tests
integration-tests: release-clif examples

View File

@ -1,10 +1,11 @@
mod runtime_core_tests;
use runtime_core_tests::{get_compiler, wat2wasm};
use wasmer_runtime_core::{compile_with, imports};
pub mod runtime_core_exception_handling {
use super::runtime_core_tests::{get_compiler, wat2wasm};
use wasmer_runtime_core::{compile_with, imports};
#[test]
fn exception_handling_works() {
#[test]
fn exception_handling_works() {
const MODULE: &str = r#"
(module
(func (export "throw_trap")
@ -20,4 +21,5 @@ fn exception_handling_works() {
let instance = module.instantiate(&imports).unwrap();
assert!(instance.call("throw_trap", &[]).is_err());
}
}
}

View File

@ -1,8 +1,11 @@
mod runtime_core_tests;
use runtime_core_tests::{get_compiler, wat2wasm};
use std::{convert::TryInto, sync::Arc};
use wasmer_runtime_core::{
#[cfg(test)]
pub mod runtime_core_imports {
use super::runtime_core_tests::{get_compiler, wat2wasm};
use std::{convert::TryInto, sync::Arc};
use wasmer_runtime_core::{
compile_with,
error::RuntimeError,
global::Global,
@ -12,10 +15,10 @@ use wasmer_runtime_core::{
types::{FuncSig, MemoryDescriptor, Type, Value},
units::Pages,
vm, DynFunc, Instance,
};
};
#[test]
fn new_api_works() {
#[test]
fn runtime_core_new_api_works() {
let wasm = r#"
(module
(type $type (func (param i32) (result i32)))
@ -40,9 +43,9 @@ fn new_api_works() {
assert_eq!(add_one.call(&[Value::I32(5)]).unwrap(), &[Value::I32(6)]);
let add_one_memory: Result<DynFunc, _> = instance.exports.get("my_global");
assert!(add_one_memory.is_err());
}
}
macro_rules! call_and_assert {
macro_rules! call_and_assert {
($instance:ident, $function:ident( $( $inputs:ty ),* ) -> $output:ty, ( $( $arguments:expr ),* ) == $expected_value:expr) => {
#[allow(unused_parens)]
let $function: Func<( $( $inputs ),* ), $output> = $instance.exports.get(stringify!($function)).expect(concat!("Failed to get the `", stringify!($function), "` export function."));
@ -89,19 +92,19 @@ macro_rules! call_and_assert {
};
}
/// The shift that is set in the instance memory. The value is part of
/// the result returned by the imported functions if the memory is
/// read properly.
const SHIFT: i32 = 10;
/// The shift that is set in the instance memory. The value is part of
/// the result returned by the imported functions if the memory is
/// read properly.
const SHIFT: i32 = 10;
/// The shift that is captured in the environment of a closure. The
/// value is part of the result returned by the imported function if
/// the closure captures its environment properly.
#[allow(non_upper_case_globals)]
const shift: i32 = 100;
/// The shift that is captured in the environment of a closure. The
/// value is part of the result returned by the imported function if
/// the closure captures its environment properly.
#[allow(non_upper_case_globals)]
const shift: i32 = 100;
#[cfg(all(unix, target_arch = "x86_64"))]
fn imported_functions_forms(test: &dyn Fn(&Instance)) {
#[cfg(all(unix, target_arch = "x86_64"))]
fn imported_functions_forms(test: &dyn Fn(&Instance)) {
const MODULE: &str = r#"
(module
(type $type (func (param i32) (result i32)))
@ -355,42 +358,42 @@ fn imported_functions_forms(test: &dyn Fn(&Instance)) {
let instance = module.instantiate(&import_object).unwrap();
test(&instance);
}
}
fn callback_fn(n: i32) -> Result<i32, ()> {
fn callback_fn(n: i32) -> Result<i32, ()> {
Ok(n + 1)
}
}
fn callback_fn_dynamic(_: &mut vm::Ctx, inputs: &[Value]) -> Vec<Value> {
fn callback_fn_dynamic(_: &mut vm::Ctx, inputs: &[Value]) -> Vec<Value> {
match inputs[0] {
Value::I32(x) => vec![Value::I32(x + 1)],
_ => unreachable!(),
}
}
}
fn callback_fn_dynamic_panic(_: &mut vm::Ctx, _: &[Value]) -> Vec<Value> {
fn callback_fn_dynamic_panic(_: &mut vm::Ctx, _: &[Value]) -> Vec<Value> {
panic!("test");
}
}
fn callback_fn_with_vmctx(vmctx: &mut vm::Ctx, n: i32) -> Result<i32, ()> {
fn callback_fn_with_vmctx(vmctx: &mut vm::Ctx, n: i32) -> Result<i32, ()> {
let memory = vmctx.memory(0);
let shift_: i32 = memory.view()[0].get();
Ok(shift_ + n + 1)
}
}
fn callback_fn_trap(n: i32) -> Result<i32, String> {
fn callback_fn_trap(n: i32) -> Result<i32, String> {
Err(format!("foo {}", n + 1))
}
}
fn callback_fn_trap_with_vmctx(vmctx: &mut vm::Ctx, n: i32) -> Result<i32, String> {
fn callback_fn_trap_with_vmctx(vmctx: &mut vm::Ctx, n: i32) -> Result<i32, String> {
let memory = vmctx.memory(0);
let shift_: i32 = memory.view()[0].get();
Err(format!("baz {}", shift_ + n + 1))
}
}
macro_rules! test {
macro_rules! test {
($test_name:ident, $function:ident( $( $inputs:ty ),* ) -> $output:ty, ( $( $arguments:expr ),* ) == $expected_value:expr) => {
#[cfg(all(unix, target_arch = "x86_64"))]
#[test]
@ -402,73 +405,74 @@ macro_rules! test {
};
}
test!(test_fn, function_fn(i32) -> i32, (1) == Ok(2));
test!(test_closure, function_closure(i32) -> i32, (1) == Ok(2));
test!(test_fn_dynamic, function_fn_dynamic(i32) -> i32, (1) == Ok(2));
test!(test_fn_dynamic_panic, function_fn_dynamic_panic(i32) -> i32, (1) == Err(RuntimeError(Box::new("test"))));
test!(
test!(test_fn, function_fn(i32) -> i32, (1) == Ok(2));
test!(test_closure, function_closure(i32) -> i32, (1) == Ok(2));
test!(test_fn_dynamic, function_fn_dynamic(i32) -> i32, (1) == Ok(2));
test!(test_fn_dynamic_panic, function_fn_dynamic_panic(i32) -> i32, (1) == Err(RuntimeError(Box::new("test"))));
test!(
test_closure_dynamic_0,
function_closure_dynamic_0(()) -> (),
() == Ok(())
);
test!(
test!(
test_closure_dynamic_1,
function_closure_dynamic_1(i32) -> i32,
(1) == Ok(1 + shift + SHIFT)
);
test!(
test!(
test_closure_dynamic_2,
function_closure_dynamic_2(i32, i64) -> i64,
(1, 2) == Ok(1 + 2 + shift as i64 + SHIFT as i64)
);
test!(
test!(
test_closure_dynamic_3,
function_closure_dynamic_3(i32, i64, f32) -> f32,
(1, 2, 3.) == Ok(1. + 2. + 3. + shift as f32 + SHIFT as f32)
);
test!(
test!(
test_closure_dynamic_4,
function_closure_dynamic_4(i32, i64, f32, f64) -> f64,
(1, 2, 3., 4.) == Ok(1. + 2. + 3. + 4. + shift as f64 + SHIFT as f64)
);
test!(
test!(
test_closure_with_env,
function_closure_with_env(i32) -> i32,
(1) == Ok(2 + shift + SHIFT)
);
test!(test_fn_with_vmctx, function_fn_with_vmctx(i32) -> i32, (1) == Ok(2 + SHIFT));
test!(
test!(test_fn_with_vmctx, function_fn_with_vmctx(i32) -> i32, (1) == Ok(2 + SHIFT));
test!(
test_closure_with_vmctx,
function_closure_with_vmctx(i32) -> i32,
(1) == Ok(2 + SHIFT)
);
test!(
test!(
test_closure_with_vmctx_and_env,
function_closure_with_vmctx_and_env(i32) -> i32,
(1) == Ok(2 + shift + SHIFT)
);
test!(
test!(
test_fn_trap,
function_fn_trap(i32) -> i32,
(1) == Err(RuntimeError(Box::new(format!("foo {}", 2))))
);
test!(
test!(
test_closure_trap,
function_closure_trap(i32) -> i32,
(1) == Err(RuntimeError(Box::new(format!("bar {}", 2))))
);
test!(
test!(
test_fn_trap_with_vmctx,
function_fn_trap_with_vmctx(i32) -> i32,
(1) == Err(RuntimeError(Box::new(format!("baz {}", 2 + SHIFT))))
);
test!(
test!(
test_closure_trap_with_vmctx,
function_closure_trap_with_vmctx(i32) -> i32,
(1) == Err(RuntimeError(Box::new(format!("qux {}", 2 + SHIFT))))
);
test!(
test!(
test_closure_trap_with_vmctx_and_env,
function_closure_trap_with_vmctx_and_env(i32) -> i32,
(1) == Err(RuntimeError(Box::new(format!("! {}", 2 + shift + SHIFT))))
);
}