wasmer/lib/runtime/tests/semantics.rs

40 lines
1.4 KiB
Rust
Raw Normal View History

2019-01-12 19:07:11 +00:00
#[cfg(test)]
mod tests {
use wabt::wat2wasm;
use wasmer_clif_backend::CraneliftCompiler;
use wasmer_runtime::import::Imports;
// The semantics of stack overflow are documented at:
// https://webassembly.org/docs/semantics/#stack-overflow
#[test]
#[ignore]
fn test_stack_overflow() {
let module_str = r#"(module
(type (;0;) (func))
(func (;0;) (type 0)
i32.const 0
2019-01-12 19:07:11 +00:00
call_indirect (type 0))
(table (;0;) 1 anyfunc)
(export "stack-overflow" (func 0))
(elem (;0;) (i32.const 0) 0))
"#;
2019-01-12 19:07:11 +00:00
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");
let mut instance = module
2019-01-13 21:44:14 +00:00
.instantiate(&mut Imports::new())
2019-01-12 19:07:11 +00:00
.expect("WASM can't be instantiated");
let result = instance.call("stack-overflow", &[]);
2019-01-12 19:07:11 +00:00
assert!(
result.is_err(),
"should fail with error due to stack overflow"
);
// TODO The kind of error and message needs to be defined, not spec defined, maybe RuntimeError or RangeError
if let Err(message) = result {
assert!(!message.contains("segmentation violation"));
assert!(!message.contains("bus error"));
}
}
}