wasmer/lib/runtime/tests/spectests/func_ptrs.rs
2019-01-09 01:06:24 -05:00

471 lines
16 KiB
Rust

// 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/func_ptrs.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))
(type (;1;) (func))
(type (;2;) (func))
(type (;3;) (func (result i32)))
(type (;4;) (func (result i32)))
(type (;5;) (func (param i32) (result i32)))
(type (;6;) (func (param i32)))
(import \"spectest\" \"print_i32\" (func (;0;) (type 6)))
(func (;1;) (type 0))
(func (;2;) (type 1))
(func (;3;) (type 4) (result i32)
i32.const 13)
(func (;4;) (type 5) (param i32) (result i32)
get_local 0
i32.const 1
i32.add)
(func (;5;) (type 5) (param i32) (result i32)
get_local 0
i32.const 2
i32.sub)
(func (;6;) (type 6) (param i32)
get_local 0
call 0)
(export \"one\" (func 3))
(export \"two\" (func 4))
(export \"three\" (func 5))
(export \"four\" (func 6)))
";
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 27
fn c1_l27_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c1_l27_action_invoke");
let result = instance.call("one", &[]);
assert_eq!(result, Ok(Some(Value::I32(13 as i32))));
result.map(|_| ())
}
// Line 28
fn c2_l28_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c2_l28_action_invoke");
let result = instance.call("two", &[Value::I32(13 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(14 as i32))));
result.map(|_| ())
}
// Line 29
fn c3_l29_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c3_l29_action_invoke");
let result = instance.call("three", &[Value::I32(13 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(11 as i32))));
result.map(|_| ())
}
// Line 30
fn c4_l30_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c4_l30_action_invoke");
let result = instance.call("four", &[Value::I32(83 as i32)]);
result.map(|_| ())
}
// Line 32
#[test]
fn c5_l32_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 9, 6, 1, 0, 65, 0, 11, 0];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 33
#[test]
fn c6_l33_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 9, 7, 1, 0, 65, 0, 11, 1, 0, 10, 4, 1, 2, 0, 11];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 36
#[test]
fn c7_l36_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 6, 1, 0, 66, 0, 11, 0];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 40
#[test]
fn c8_l40_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 104, 11, 0];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 44
#[test]
fn c9_l44_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 5, 1, 0, 1, 11, 0];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 48
#[test]
fn c10_l48_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 3, 2, 1, 42, 10, 4, 1, 2, 0, 11];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 49
#[test]
fn c11_l49_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 22, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 9, 112, 114, 105, 110, 116, 95, 105, 51, 50, 0, 43];
let module = wasmer_runtime::compile(&wasm_binary, &CraneliftCompiler::new());
assert!(module.is_err(), "WASM should not compile as is invalid");
}
// Line 51
#[test]
fn test_module_1() {
let mut instance = create_module_1();
// We group the calls together
start_module_1(&mut instance);
c1_l27_action_invoke(&mut instance);
c2_l28_action_invoke(&mut instance);
c3_l29_action_invoke(&mut instance);
c4_l30_action_invoke(&mut instance);
}
fn create_module_2() -> Box<Instance> {
let module_str = "(module
(type (;0;) (func (result i32)))
(type (;1;) (func (result i32)))
(type (;2;) (func (param i32) (result i32)))
(func (;0;) (type 0) (result i32)
i32.const 1)
(func (;1;) (type 0) (result i32)
i32.const 2)
(func (;2;) (type 0) (result i32)
i32.const 3)
(func (;3;) (type 1) (result i32)
i32.const 4)
(func (;4;) (type 1) (result i32)
i32.const 5)
(func (;5;) (type 2) (param i32) (result i32)
get_local 0
call_indirect (type 0))
(func (;6;) (type 2) (param i32) (result i32)
get_local 0
call_indirect (type 1))
(table (;0;) 7 7 anyfunc)
(export \"callt\" (func 5))
(export \"callu\" (func 6))
(elem (;0;) (i32.const 0) 0 1 2 3 4 0 2))
";
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_2(instance: &mut Instance) {
// TODO Review is explicit start needed? Start now called in runtime::Instance::new()
//instance.start();
}
// Line 71
fn c13_l71_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c13_l71_action_invoke");
let result = instance.call("callt", &[Value::I32(0 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 72
fn c14_l72_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c14_l72_action_invoke");
let result = instance.call("callt", &[Value::I32(1 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(2 as i32))));
result.map(|_| ())
}
// Line 73
fn c15_l73_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c15_l73_action_invoke");
let result = instance.call("callt", &[Value::I32(2 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(3 as i32))));
result.map(|_| ())
}
// Line 74
fn c16_l74_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c16_l74_action_invoke");
let result = instance.call("callt", &[Value::I32(3 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(4 as i32))));
result.map(|_| ())
}
// Line 75
fn c17_l75_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c17_l75_action_invoke");
let result = instance.call("callt", &[Value::I32(4 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(5 as i32))));
result.map(|_| ())
}
// Line 76
fn c18_l76_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c18_l76_action_invoke");
let result = instance.call("callt", &[Value::I32(5 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 77
fn c19_l77_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c19_l77_action_invoke");
let result = instance.call("callt", &[Value::I32(6 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(3 as i32))));
result.map(|_| ())
}
// Line 78
fn c20_l78_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c20_l78_action_invoke");
let result = instance.call("callt", &[Value::I32(7 as i32)]);
result.map(|_| ())
}
#[test]
fn c20_l78_assert_trap() {
let mut instance = create_module_2();
let result = c20_l78_action_invoke(&mut*instance);
assert!(result.is_err());
}
// Line 79
fn c21_l79_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c21_l79_action_invoke");
let result = instance.call("callt", &[Value::I32(100 as i32)]);
result.map(|_| ())
}
#[test]
fn c21_l79_assert_trap() {
let mut instance = create_module_2();
let result = c21_l79_action_invoke(&mut*instance);
assert!(result.is_err());
}
// Line 80
fn c22_l80_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c22_l80_action_invoke");
let result = instance.call("callt", &[Value::I32(-1 as i32)]);
result.map(|_| ())
}
#[test]
fn c22_l80_assert_trap() {
let mut instance = create_module_2();
let result = c22_l80_action_invoke(&mut*instance);
assert!(result.is_err());
}
// Line 82
fn c23_l82_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c23_l82_action_invoke");
let result = instance.call("callu", &[Value::I32(0 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 83
fn c24_l83_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c24_l83_action_invoke");
let result = instance.call("callu", &[Value::I32(1 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(2 as i32))));
result.map(|_| ())
}
// Line 84
fn c25_l84_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c25_l84_action_invoke");
let result = instance.call("callu", &[Value::I32(2 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(3 as i32))));
result.map(|_| ())
}
// Line 85
fn c26_l85_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c26_l85_action_invoke");
let result = instance.call("callu", &[Value::I32(3 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(4 as i32))));
result.map(|_| ())
}
// Line 86
fn c27_l86_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c27_l86_action_invoke");
let result = instance.call("callu", &[Value::I32(4 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(5 as i32))));
result.map(|_| ())
}
// Line 87
fn c28_l87_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c28_l87_action_invoke");
let result = instance.call("callu", &[Value::I32(5 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 88
fn c29_l88_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c29_l88_action_invoke");
let result = instance.call("callu", &[Value::I32(6 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(3 as i32))));
result.map(|_| ())
}
// Line 89
fn c30_l89_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c30_l89_action_invoke");
let result = instance.call("callu", &[Value::I32(7 as i32)]);
result.map(|_| ())
}
#[test]
fn c30_l89_assert_trap() {
let mut instance = create_module_2();
let result = c30_l89_action_invoke(&mut*instance);
assert!(result.is_err());
}
// Line 90
fn c31_l90_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c31_l90_action_invoke");
let result = instance.call("callu", &[Value::I32(100 as i32)]);
result.map(|_| ())
}
#[test]
fn c31_l90_assert_trap() {
let mut instance = create_module_2();
let result = c31_l90_action_invoke(&mut*instance);
assert!(result.is_err());
}
// Line 91
fn c32_l91_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c32_l91_action_invoke");
let result = instance.call("callu", &[Value::I32(-1 as i32)]);
result.map(|_| ())
}
#[test]
fn c32_l91_assert_trap() {
let mut instance = create_module_2();
let result = c32_l91_action_invoke(&mut*instance);
assert!(result.is_err());
}
// Line 93
#[test]
fn test_module_2() {
let mut instance = create_module_2();
// We group the calls together
start_module_2(&mut instance);
c13_l71_action_invoke(&mut instance);
c14_l72_action_invoke(&mut instance);
c15_l73_action_invoke(&mut instance);
c16_l74_action_invoke(&mut instance);
c17_l75_action_invoke(&mut instance);
c18_l76_action_invoke(&mut instance);
c19_l77_action_invoke(&mut instance);
c23_l82_action_invoke(&mut instance);
c24_l83_action_invoke(&mut instance);
c25_l84_action_invoke(&mut instance);
c26_l85_action_invoke(&mut instance);
c27_l86_action_invoke(&mut instance);
c28_l87_action_invoke(&mut instance);
c29_l88_action_invoke(&mut instance);
}
fn create_module_3() -> Box<Instance> {
let module_str = "(module
(type (;0;) (func (result i32)))
(type (;1;) (func (param i32) (result i32)))
(func (;0;) (type 0) (result i32)
i32.const 1)
(func (;1;) (type 0) (result i32)
i32.const 2)
(func (;2;) (type 1) (param i32) (result i32)
get_local 0
call_indirect (type 0))
(table (;0;) 2 2 anyfunc)
(export \"callt\" (func 2))
(elem (;0;) (i32.const 0) 0 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_3(instance: &mut Instance) {
// TODO Review is explicit start needed? Start now called in runtime::Instance::new()
//instance.start();
}
// Line 105
fn c34_l105_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c34_l105_action_invoke");
let result = instance.call("callt", &[Value::I32(0 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(1 as i32))));
result.map(|_| ())
}
// Line 106
fn c35_l106_action_invoke(instance: &mut Instance) -> Result<(), String> {
println!("Executing function {}", "c35_l106_action_invoke");
let result = instance.call("callt", &[Value::I32(1 as i32)]);
assert_eq!(result, Ok(Some(Value::I32(2 as i32))));
result.map(|_| ())
}
#[test]
fn test_module_3() {
let mut instance = create_module_3();
// We group the calls together
start_module_3(&mut instance);
c34_l105_action_invoke(&mut instance);
c35_l106_action_invoke(&mut instance);
}