1 use arbitrary::{Arbitrary, Unstructured}; 2 use std::time::Duration; 3 4 /// Configuration for async support within a store. 5 /// 6 /// Note that the `Arbitrary` implementation for this type always returns 7 /// `Disabled` because this is something that is statically chosen if the fuzzer 8 /// has support for async. 9 #[derive(Clone, Debug, Eq, Hash, PartialEq)] 10 pub enum AsyncConfig { 11 /// No async support enabled. 12 Disabled, 13 /// Async support is enabled and cooperative yielding is done with fuel. 14 YieldWithFuel(u64), 15 /// Async support is enabled and cooperative yielding is done with epochs. 16 YieldWithEpochs { 17 /// Duration between epoch ticks. 18 dur: Duration, 19 /// Number of ticks between yields. 20 ticks: u64, 21 }, 22 } 23 24 impl AsyncConfig { 25 /// Applies this async configuration to the `wasmtime::Config` provided to 26 /// ensure it's ready to execute with the resulting modules. 27 pub fn configure(&self, config: &mut wasmtime::Config) { 28 match self { 29 AsyncConfig::Disabled => {} 30 AsyncConfig::YieldWithFuel(_) => { 31 config.consume_fuel(true); 32 } 33 AsyncConfig::YieldWithEpochs { .. } => { 34 config.epoch_interruption(true); 35 } 36 } 37 } 38 } 39 40 impl<'a> Arbitrary<'a> for AsyncConfig { 41 fn arbitrary(_: &mut Unstructured<'a>) -> arbitrary::Result<AsyncConfig> { 42 Ok(AsyncConfig::Disabled) 43 } 44 } 45