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

Method arbitrary

crates/fuzzing/src/generators/api.rs:594–1556  ·  view source on GitHub ↗
(input: &mut Unstructured<'a>)

Source from the content-addressed store, hash-verified

592
593impl<'a> Arbitrary<'a> for ApiCalls {
594 fn arbitrary(input: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
595 crate::init_fuzzing();
596
597 let swarm = Swarm::arbitrary(input)?;
598 let mut calls = vec![];
599
600 let config = Config::arbitrary(input)?;
601 let mut scope = Scope {
602 id_counter: 0,
603 stores: BTreeSet::default(),
604 modules: BTreeSet::default(),
605 instances: BTreeMap::default(),
606 global_types: BTreeSet::default(),
607 globals: BTreeMap::default(),
608 table_types: BTreeSet::default(),
609 tables: BTreeMap::default(),
610 memory_types: BTreeSet::default(),
611 memories: BTreeMap::default(),
612 func_types: BTreeSet::default(),
613 funcs: BTreeMap::default(),
614 tag_types: BTreeSet::default(),
615 tags: BTreeMap::default(),
616 struct_types: BTreeSet::default(),
617 struct_ref_pres: BTreeMap::default(),
618 struct_refs: BTreeMap::default(),
619 array_types: BTreeSet::default(),
620 array_ref_pres: BTreeMap::default(),
621 array_refs: BTreeMap::default(),
622 exn_types: BTreeSet::default(),
623 exn_ref_pres: BTreeMap::default(),
624 exn_refs: BTreeMap::default(),
625 config: config.clone(),
626 };
627
628 let store_id = scope.next_id();
629 scope.stores.insert(store_id);
630 calls.push(StoreNew {
631 id: store_id,
632 config,
633 });
634
635 // Total limit on number of API calls we'll generate. This exists to
636 // avoid libFuzzer timeouts.
637 let max_calls = 100;
638
639 let mut choices: Vec<fn(&mut Unstructured<'a>, &mut Scope) -> arbitrary::Result<ApiCall>> =
640 vec![];
641
642 for _ in 0..std::cmp::min(max_calls, input.arbitrary_len::<ApiCall>()?) {
643 choices.clear();
644
645 if swarm.store_new {
646 choices.push(|_input, scope| {
647 let id = scope.next_id();
648 scope.stores.insert(id);
649 Ok(StoreNew {
650 id,
651 config: scope.config.clone(),

Callers 13

generate_optMethod · 0.45
generateMethod · 0.45
runFunction · 0.45
targetFunction · 0.45
wast_testFunction · 0.45
gen_until_passFunction · 0.45
executeFunction · 0.45
mutateFunction · 0.45
arbitrary_valFunction · 0.45
storeFunction · 0.45
static_api_testFunction · 0.45

Calls 15

init_fuzzingFunction · 0.85
OkFunction · 0.85
cFunction · 0.85
collectMethod · 0.80
or_defaultMethod · 0.80
anyMethod · 0.80
cloneMethod · 0.45
next_idMethod · 0.45
insertMethod · 0.45
pushMethod · 0.45
clearMethod · 0.45
lenMethod · 0.45

Tested by 1

gc_access_oracle_passesFunction · 0.36