Skip to content

Commit 3085e4f

Browse files
committed
rust: Add host function test in rust
1 parent 9ae449c commit 3085e4f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

bindings/rust/src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,4 +1310,31 @@ mod tests {
13101310
"invalid offset or size"
13111311
);
13121312
}
1313+
1314+
#[test]
1315+
fn execute_host_function() {
1316+
/* wat2wasm
1317+
(module
1318+
(func $adler32 (import "env" "adler32") (param i32 i32) (result i32))
1319+
(memory (export "memory") 1)
1320+
(data (i32.const 0) "abcd")
1321+
(func (export "test") (result i32)
1322+
i32.const 0
1323+
i32.const 4
1324+
call $adler32
1325+
)
1326+
)
1327+
*/
1328+
let input = hex::decode(
1329+
"0061736d01000000010b0260027f7f017f6000017f020f0103656e760761646c657233320000030201010503010001071102066d656d6f72790200047465737400010a0a0108004100410410000b0b0a010041000b0461626364").unwrap();
1330+
1331+
let module = parse(&input);
1332+
assert!(module.is_ok());
1333+
let instance = module.unwrap().instantiate();
1334+
assert!(instance.is_err());
1335+
assert_eq!(
1336+
instance.err().unwrap(),
1337+
"module requires 1 imported functions, 0 provided"
1338+
);
1339+
}
13131340
}

0 commit comments

Comments
 (0)