| 592 | |
| 593 | impl<'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(), |