wasmer/lib/runtime/tests/spectests/forward.rs

104 lines
3.1 KiB
Rust
Raw Normal View History

2019-01-09 06:06:24 +00:00
// Rust test file autogenerated with cargo build (build/spectests.rs).
// Please do NOT modify it by hand, as it will be reset on next build.
// Test based on spectests/forward.wast
#![allow(
warnings,
dead_code
)]
use wabt::wat2wasm;
use std::{f32, f64};
use wasmer_runtime::types::Value;
use wasmer_runtime::{Instance, Module};
use wasmer_clif_backend::CraneliftCompiler;
use crate::spectests::_common::{
spectest_importobject,
NaNCheck,
};
// Line 1
fn create_module_1() -> Box<Instance> {
let module_str = "(module
(type (;0;) (func (param i32) (result i32)))
(func (;0;) (type 0) (param i32) (result i32)
get_local 0
i32.const 0
i32.eq
if (result i32) ;; label = @1
i32.const 1
else
get_local 0
i32.const 1
i32.sub
call 1
end)
(func (;1;) (type 0) (param i32) (result i32)
get_local 0
i32.const 0
i32.eq
if (result i32) ;; label = @1
i32.const 0
else
get_local 0
i32.const 1
i32.sub
call 0
end)
(export \"even\" (func 0))
(export \"odd\" (func 1)))
";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
let module = wasmer_runtime::compile(&wasm_binary[..], &CraneliftCompiler::new()).expect("WASM can't be compiled");
module.instantiate(&spectest_importobject()).expect("WASM can't be instantiated")
}
fn start_module_1(instance: &mut Instance) {
// TODO Review is explicit start needed? Start now called in runtime::Instance::new()
//instance.start();
}
// Line 17
fn c1_l17_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c1_l17_action_invoke");
let result = instance.call("even", &[Value::I32(13 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(0 as i32))));
result.map(|_| ())
}
// Line 18
fn c2_l18_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c2_l18_action_invoke");
let result = instance.call("even", &[Value::I32(20 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 19
fn c3_l19_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c3_l19_action_invoke");
let result = instance.call("odd", &[Value::I32(13 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 20
fn c4_l20_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c4_l20_action_invoke");
let result = instance.call("odd", &[Value::I32(20 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(0 as i32))));
result.map(|_| ())
}
#[test]
fn test_module_1() {
let mut instance = create_module_1();
// We group the calls together
start_module_1(&mut instance);
c1_l17_action_invoke(&mut instance);
c2_l18_action_invoke(&mut instance);
c3_l19_action_invoke(&mut instance);
c4_l20_action_invoke(&mut instance);
}