Adds a test to ensure that we clear the heap between calls into runtime (#4903)

* Adds a test to ensure that we clear the heap between calls into runtime

The tests shows that we currently not clearing the heap in wasmtime.
For now we don't run the test for wasmtime.

* Fix compilation
This commit is contained in:
Bastian Köcher
2020-02-14 01:42:27 +01:00
committed by GitHub
parent 78b5a06200
commit d3fa8c91af
6 changed files with 81 additions and 4 deletions
@@ -565,3 +565,26 @@ fn restoration_of_globals(wasm_method: WasmExecutionMethod) {
let res = instance.call("allocates_huge_stack_array", &false.encode());
assert!(res.is_ok());
}
#[test_case(WasmExecutionMethod::Interpreted)]
fn heap_is_reset_between_calls(wasm_method: WasmExecutionMethod) {
let mut instance = crate::wasm_runtime::create_wasm_runtime_with_code(
wasm_method,
1024,
&WASM_BINARY[..],
HostFunctions::host_functions(),
true,
).expect("Creates instance");
let heap_base = instance.get_global_val("__heap_base")
.expect("`__heap_base` is valid")
.expect("`__heap_base` exists")
.as_i32()
.expect("`__heap_base` is an `i32`");
let params = (heap_base as u32, 512u32 * 64 * 1024).encode();
instance.call("check_and_set_in_heap", &params).unwrap();
// Cal it a second time to check that the heap was freed.
instance.call("check_and_set_in_heap", &params).unwrap();
}