Fix WASM executor without instance reuse; cleanups and refactoring (#10313)

* Fix WASM executor without instance reuse; cleanups and refactoring

* Align to review comments

* Move the functions for reading/writing memory to `util.rs`

* Only `#[ignore]` the test in debug builds

* More review comments and minor extra comments
This commit is contained in:
Koute
2021-11-23 15:35:19 +09:00
committed by GitHub
parent a47f0243e0
commit e5108606eb
7 changed files with 394 additions and 376 deletions
@@ -310,3 +310,39 @@ fn test_max_memory_pages() {
)
.unwrap();
}
// This test takes quite a while to execute in a debug build (over 6 minutes on a TR 3970x)
// so it's ignored by default unless it was compiled with `--release`.
#[cfg_attr(build_type = "debug", ignore)]
#[test]
fn test_instances_without_reuse_are_not_leaked() {
use sp_wasm_interface::HostFunctions;
let runtime = crate::create_runtime(
RuntimeBlob::uncompress_if_needed(&wasm_binary_unwrap()[..]).unwrap(),
crate::Config {
heap_pages: 2048,
max_memory_size: None,
allow_missing_func_imports: true,
cache_path: None,
semantics: crate::Semantics {
fast_instance_reuse: false,
deterministic_stack_limit: None,
canonicalize_nans: false,
parallel_compilation: true,
},
},
sp_io::SubstrateHostFunctions::host_functions(),
)
.unwrap();
// As long as the `wasmtime`'s `Store` lives the instances spawned through it
// will live indefinitely. Currently it has a maximum limit of 10k instances,
// so let's spawn 10k + 1 of them to make sure our code doesn't keep the `Store`
// alive longer than it is necessary. (And since we disabled instance reuse
// a new instance will be spawned on each call.)
let mut instance = runtime.new_instance().unwrap();
for _ in 0..10001 {
instance.call_export("test_empty_return", &[0]).unwrap();
}
}