2019-01-12 19:07:11 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use wabt::wat2wasm;
|
|
|
|
use wasmer_clif_backend::CraneliftCompiler;
|
2019-01-22 19:02:06 +00:00
|
|
|
use wasmer_runtime_core::{
|
2019-01-18 18:54:16 +00:00
|
|
|
error::{CallError, RuntimeError},
|
2019-01-21 22:43:04 +00:00
|
|
|
import::ImportObject,
|
2019-01-18 18:54:16 +00:00
|
|
|
};
|
2019-01-12 19:07:11 +00:00
|
|
|
|
|
|
|
// The semantics of stack overflow are documented at:
|
|
|
|
// https://webassembly.org/docs/semantics/#stack-overflow
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn test_stack_overflow() {
|
2019-01-12 21:45:32 +00:00
|
|
|
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))
|
2019-01-12 21:45:32 +00:00
|
|
|
(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");
|
2019-01-22 19:02:06 +00:00
|
|
|
let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new())
|
2019-01-12 19:07:11 +00:00
|
|
|
.expect("WASM can't be compiled");
|
2019-01-29 18:16:39 +00:00
|
|
|
let instance = module
|
2019-02-04 23:00:57 +00:00
|
|
|
.instantiate(&ImportObject::new())
|
2019-01-12 19:07:11 +00:00
|
|
|
.expect("WASM can't be instantiated");
|
2019-01-12 21:45:32 +00:00
|
|
|
let result = instance.call("stack-overflow", &[]);
|
2019-01-18 18:54:16 +00:00
|
|
|
|
|
|
|
match result {
|
2019-02-04 23:01:12 +00:00
|
|
|
Err(err) => match err {
|
2019-03-04 20:57:26 +00:00
|
|
|
CallError::Runtime(RuntimeError::Trap { msg }) => {
|
2019-01-18 18:54:16 +00:00
|
|
|
assert!(!msg.contains("segmentation violation"));
|
|
|
|
assert!(!msg.contains("bus error"));
|
|
|
|
}
|
|
|
|
_ => unimplemented!(),
|
|
|
|
},
|
|
|
|
Ok(_) => panic!("should fail with error due to stack overflow"),
|
2019-01-12 19:07:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|