1 #![cfg(arc_try_new)]
2 
3 use wasmtime::{Config, Engine, Linker, Module, Result, Store};
4 use wasmtime_fuzzing::oom::OomTest;
5 
6 #[test]
7 fn call_exported_func() -> Result<()> {
8     let module_bytes = {
9         let mut config = Config::new();
10         config.concurrency_support(false);
11         let engine = Engine::new(&config)?;
12         let module = Module::new(
13             &engine,
14             r#"
15                 (module
16                     (func (export "add") (param i32 i32) (result i32)
17                         (i32.add (local.get 0) (local.get 1))
18                     )
19                 )
20             "#,
21         )?;
22         module.serialize()?
23     };
24 
25     let mut config = Config::new();
26     config.enable_compiler(false);
27     config.concurrency_support(false);
28     let engine = Engine::new(&config)?;
29 
30     let module = unsafe { Module::deserialize(&engine, &module_bytes)? };
31     let linker = Linker::<()>::new(&engine);
32     let instance_pre = linker.instantiate_pre(&module)?;
33 
34     OomTest::new().test(|| {
35         let mut store = Store::try_new(&engine, ())?;
36         let instance = instance_pre.instantiate(&mut store)?;
37         let add = instance.get_typed_func::<(i32, i32), i32>(&mut store, "add")?;
38         let result = add.call(&mut store, (1, 2))?;
39         assert_eq!(result, 3);
40         Ok(())
41     })
42 }
43