MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / tuple_result

Function tuple_result

tests/all/component_model/func.rs:638–691  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

636
637#[test]
638fn tuple_result() -> Result<()> {
639 let component = r#"
640 (component
641 (core module $m
642 (memory (export "memory") 1)
643 (func (export "foo") (param i32 i32 f32 f64) (result i32)
644 (local $base i32)
645 (local.set $base (i32.const 8))
646 (i32.store8 offset=0 (local.get $base) (local.get 0))
647 (i32.store16 offset=2 (local.get $base) (local.get 1))
648 (f32.store offset=4 (local.get $base) (local.get 2))
649 (f64.store offset=8 (local.get $base) (local.get 3))
650 local.get $base
651 )
652
653 (func (export "invalid") (result i32)
654 i32.const -8
655 )
656 )
657 (core instance $i (instantiate $m))
658
659 (type $result (tuple s8 u16 float32 float64))
660 (func (export "tuple")
661 (param "a" s8) (param "b" u16) (param "c" float32) (param "d" float64) (result $result)
662 (canon lift (core func $i "foo") (memory $i "memory"))
663 )
664 (func (export "invalid") (result $result)
665 (canon lift (core func $i "invalid") (memory $i "memory"))
666 )
667 )
668 "#;
669
670 let engine = super::engine();
671 let component = Component::new(&engine, component)?;
672 let mut store = Store::new(&engine, ());
673 let instance = Linker::new(&engine).instantiate(&mut store, &component)?;
674
675 let input = (-1, 100, 3.0, 100.0);
676 let output = instance
677 .get_typed_func::<(i8, u16, f32, f64), ((i8, u16, f32, f64),)>(&mut store, "tuple")?
678 .call(&mut store, input)?;
679 assert_eq!((input,), output);
680
681 let invalid_func =
682 instance.get_typed_func::<(), ((i8, u16, f32, f64),)>(&mut store, "invalid")?;
683 let err = invalid_func.call(&mut store, ()).err().unwrap();
684 assert!(
685 err.to_string().contains("pointer out of bounds of memory"),
686 "{}",
687 err
688 );
689
690 Ok(())
691}
692
693#[test]
694fn strings() -> Result<()> {

Callers 14

tuple_resultMethod · 0.85
add_to_linker_instanceFunction · 0.85
add_to_linker_instanceFunction · 0.85
tuple_resultMethod · 0.85
add_to_linker_instanceFunction · 0.85
add_to_linker_instanceFunction · 0.85
tuple_resultMethod · 0.85
add_to_linker_instanceFunction · 0.85
tuple_resultMethod · 0.85
add_to_linker_instanceFunction · 0.85
tuple_resultMethod · 0.85
add_to_linker_instanceFunction · 0.85

Calls 7

OkFunction · 0.85
engineFunction · 0.50
newFunction · 0.50
instantiateMethod · 0.45
callMethod · 0.45
unwrapMethod · 0.45
errMethod · 0.45

Tested by

no test coverage detected