forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponent_component.rs
More file actions
40 lines (37 loc) · 1.23 KB
/
component_component.rs
File metadata and controls
40 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#![cfg(arc_try_new)]
use wasmtime::component::Component;
use wasmtime::{Config, Engine, Result};
use wasmtime_fuzzing::oom::OomTest;
#[test]
fn component_serialize() -> Result<()> {
let component_bytes = {
let mut config = Config::new();
config.concurrency_support(false);
let engine = Engine::new(&config)?;
Component::new(
&engine,
r#"
(component
(core module $m
(func (export "id") (param i32) (result i32) (local.get 0))
)
(core instance $i (instantiate $m))
(func (export "id") (param "x" s32) (result s32)
(canon lift (core func $i "id"))
)
)
"#,
)?
.serialize()?
};
let mut config = Config::new();
config.enable_compiler(false);
config.concurrency_support(false);
let engine = Engine::new(&config)?;
let component = unsafe { Component::deserialize(&engine, &component_bytes)? };
// Error propagation via anyhow allocates after OOM.
OomTest::new().allow_alloc_after_oom(true).test(|| {
let _bytes = component.serialize()?;
Ok(())
})
}