mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-15 07:05:41 +00:00
86 lines
2.4 KiB
Rust
86 lines
2.4 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/break_drop.wast
|
|
#![allow(
|
|
warnings,
|
|
dead_code
|
|
)]
|
|
use wabt::wat2wasm;
|
|
use std::{f32, f64};
|
|
|
|
use wasmer_runtime::types::Value;
|
|
use wasmer_runtime::{Instance, module::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))
|
|
(func (;0;) (type 0)
|
|
block ;; label = @1
|
|
br 0 (;@1;)
|
|
end)
|
|
(func (;1;) (type 0)
|
|
block ;; label = @1
|
|
i32.const 1
|
|
br_if 0 (;@1;)
|
|
end)
|
|
(func (;2;) (type 0)
|
|
block ;; label = @1
|
|
i32.const 0
|
|
br_table 0 (;@1;)
|
|
end)
|
|
(export \"br\" (func 0))
|
|
(export \"br_if\" (func 1))
|
|
(export \"br_table\" (func 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_1(instance: &mut Instance) {
|
|
// TODO Review is explicit start needed? Start now called in runtime::Instance::new()
|
|
//instance.start();
|
|
}
|
|
|
|
// Line 7
|
|
fn c1_l7_action_invoke(instance: &mut Instance) -> Result<(), String> {
|
|
println!("Executing function {}", "c1_l7_action_invoke");
|
|
let result = instance.call("br", &[]);
|
|
assert_eq!(result, Ok(None));
|
|
result.map(|_| ())
|
|
}
|
|
|
|
// Line 8
|
|
fn c2_l8_action_invoke(instance: &mut Instance) -> Result<(), String> {
|
|
println!("Executing function {}", "c2_l8_action_invoke");
|
|
let result = instance.call("br_if", &[]);
|
|
assert_eq!(result, Ok(None));
|
|
result.map(|_| ())
|
|
}
|
|
|
|
// Line 9
|
|
fn c3_l9_action_invoke(instance: &mut Instance) -> Result<(), String> {
|
|
println!("Executing function {}", "c3_l9_action_invoke");
|
|
let result = instance.call("br_table", &[]);
|
|
assert_eq!(result, Ok(None));
|
|
result.map(|_| ())
|
|
}
|
|
|
|
#[test]
|
|
fn test_module_1() {
|
|
let mut instance = create_module_1();
|
|
// We group the calls together
|
|
start_module_1(&mut instance);
|
|
c1_l7_action_invoke(&mut instance);
|
|
c2_l8_action_invoke(&mut instance);
|
|
c3_l9_action_invoke(&mut instance);
|
|
}
|