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

Function test_roundtrip

tests/all/component_model/strings.rs:101–193  ·  view source on GitHub ↗
(engine: &Engine, src: &str, dst: &str)

Source from the content-addressed store, hash-verified

99}
100
101fn test_roundtrip(engine: &Engine, src: &str, dst: &str) -> Result<()> {
102 println!("src={src} dst={dst}");
103
104 let mk_echo = |name: &str, encoding: &str| {
105 format!(
106 r#"
107(component {name}
108 (import "echo" (func $echo (param "a" string) (result string)))
109 (core instance $libc (instantiate $libc))
110 (core func $echo (canon lower (func $echo)
111 (memory $libc "memory")
112 (realloc (func $libc "realloc"))
113 string-encoding={encoding}
114 ))
115 (core instance $echo (instantiate $echo
116 (with "libc" (instance $libc))
117 (with "" (instance (export "echo" (func $echo))))
118 ))
119 (func (export "echo2") (param "a" string) (result string)
120 (canon lift
121 (core func $echo "echo")
122 (memory $libc "memory")
123 (realloc (func $libc "realloc"))
124 string-encoding={encoding}
125 )
126 )
127)
128 "#
129 )
130 };
131
132 let src = mk_echo("$src", src);
133 let dst = mk_echo("$dst", dst);
134 let component = format!(
135 r#"
136(component
137 (import "host" (func $host (param "a" string) (result string)))
138
139 (core module $libc
140 (memory (export "memory") 1)
141 {REALLOC_AND_FREE}
142 )
143 (core module $echo
144 (import "" "echo" (func $echo (param i32 i32 i32)))
145 (import "libc" "memory" (memory 0))
146 (import "libc" "realloc" (func $realloc (param i32 i32 i32 i32) (result i32)))
147
148 (func (export "echo") (param i32 i32) (result i32)
149 (local $retptr i32)
150 (local.set $retptr
151 (call $realloc
152 (i32.const 0)
153 (i32.const 0)
154 (i32.const 4)
155 (i32.const 8)))
156 (call $echo
157 (local.get 0)
158 (local.get 1)

Callers 1

roundtripFunction · 0.85

Calls 8

OkFunction · 0.85
newFunction · 0.50
func_wrapMethod · 0.45
rootMethod · 0.45
instantiateMethod · 0.45
data_mutMethod · 0.45
to_stringMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected