Skip to content

Commit 96b5b82

Browse files
authored
Add support for collecting garbage to the public API fuzzer (bytecodealliance#13457)
1 parent 64ef80c commit 96b5b82

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

crates/fuzzing/src/generators/api.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl FuzzValType {
4545
struct Swarm {
4646
store_new: bool,
4747
store_drop: bool,
48+
store_gc: bool,
4849
module_new: bool,
4950
module_drop: bool,
5051
instance_new: bool,
@@ -148,6 +149,9 @@ pub enum ApiCall {
148149
StoreDrop {
149150
id: usize,
150151
},
152+
StoreGc {
153+
id: usize,
154+
},
151155
ModuleNew {
152156
id: usize,
153157
wasm: Vec<u8>,
@@ -668,6 +672,13 @@ impl<'a> Arbitrary<'a> for ApiCalls {
668672
Ok(StoreDrop { id })
669673
});
670674
}
675+
if swarm.store_gc && !scope.stores.is_empty() {
676+
choices.push(|input, scope| {
677+
let stores: Vec<_> = scope.stores.iter().collect();
678+
let id = **input.choose(&stores)?;
679+
Ok(StoreGc { id })
680+
});
681+
}
671682
if swarm.module_new {
672683
choices.push(|input, scope| {
673684
let id = scope.next_id();

crates/fuzzing/src/oracles/api.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ pub fn make_api_calls(api: ApiCalls) {
6565
stores.remove(&id);
6666
}
6767

68+
ApiCall::StoreGc { id } => {
69+
log::trace!("collecting garbage in store {id}");
70+
let st = match stores.get_mut(&id) {
71+
Some(s) => s,
72+
None => continue,
73+
};
74+
let _ = st.gc(None);
75+
}
76+
6877
ApiCall::ModuleNew { id, wasm } => {
6978
log::debug!("creating module: {id}");
7079
log_wasm(&wasm);

0 commit comments

Comments
 (0)