-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for calling exported functions with lots of params and …
…results (#958) add e2e tests with lots of params and results
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{Engine, Func, Linker, Module, Store, Value}; | ||
use std::vec::Vec; | ||
|
||
/// Converts the given `.wat` into `.wasm`. | ||
fn wat2wasm(wat: &str) -> Vec<u8> { | ||
wat::parse_str(wat).unwrap() | ||
} | ||
|
||
/// Common routine to setup the tests. | ||
fn setup_test(wat: &str) -> (Store<()>, Func) { | ||
let wasm = wat2wasm(wat); | ||
let engine = Engine::default(); | ||
let mut store = <Store<()>>::new(&engine, ()); | ||
let linker = <Linker<()>>::new(&engine); | ||
let module = Module::new(&engine, &wasm[..]).unwrap(); | ||
let instance = linker | ||
.instantiate(&mut store, &module) | ||
.unwrap() | ||
.ensure_no_start(&mut store) | ||
.unwrap(); | ||
let func = instance.get_func(&store, "test").unwrap(); | ||
(store, func) | ||
} | ||
|
||
#[test] | ||
fn many_params() { | ||
let wat = include_str!("wat/many_params.wat"); | ||
let (mut store, func) = setup_test(wat); | ||
func.call(&mut store, &[0; 150].map(Value::I32), &mut []) | ||
.unwrap(); | ||
} | ||
|
||
#[test] | ||
fn many_results() { | ||
let wat = include_str!("wat/many_results.wat"); | ||
let (mut store, func) = setup_test(wat); | ||
let mut results = [0; 150].map(Value::I32); | ||
func.call(&mut store, &[], &mut results).unwrap(); | ||
for (i, result) in results.iter().enumerate() { | ||
let &Value::I32(result) = result else { | ||
panic!("unexpected result type at index {i}: {result:?}"); | ||
}; | ||
assert!(result as usize == i % 10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod host_calls; | ||
mod many_inout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
(module | ||
(func (export "test") | ||
(param | ||
;; Define 150 i32 params | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
) | ||
;; do nothing | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(module | ||
(func (export "test") | ||
(result | ||
;; Define 150 i32 results | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 | ||
) | ||
(call $return10) (call $return10) (call $return10) (call $return10) (call $return10) | ||
(call $return10) (call $return10) (call $return10) (call $return10) (call $return10) | ||
(call $return10) (call $return10) (call $return10) (call $return10) (call $return10) | ||
) | ||
|
||
(func $return10 | ||
(result i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) | ||
(i32.const 0) (i32.const 1) (i32.const 2) (i32.const 3) (i32.const 4) | ||
(i32.const 5) (i32.const 6) (i32.const 7) (i32.const 8) (i32.const 9) | ||
) | ||
) |