Allow setting max iterations for stages (#1436)

* Allow setting the max iterations

* Rename API

* Fix baby_fuzzer_grimoire

* Relax bound

* Also add a new API for transforming

* Revert back grimoire fix

* Revert bound relax
This commit is contained in:
lazymio 2023-08-24 15:59:11 +08:00 committed by GitHub
parent 20cee8cd33
commit c84c105fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -158,6 +158,7 @@ pub static DEFAULT_MUTATIONAL_MAX_ITERATIONS: u64 = 128;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct StdMutationalStage<E, EM, I, M, Z> { pub struct StdMutationalStage<E, EM, I, M, Z> {
mutator: M, mutator: M,
max_iterations: u64,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
phantom: PhantomData<(E, EM, I, Z)>, phantom: PhantomData<(E, EM, I, Z)>,
} }
@ -185,7 +186,7 @@ where
/// Gets the number of iterations as a random number /// Gets the number of iterations as a random number
fn iterations(&self, state: &mut Z::State, _corpus_idx: CorpusId) -> Result<u64, Error> { fn iterations(&self, state: &mut Z::State, _corpus_idx: CorpusId) -> Result<u64, Error> {
Ok(1 + state.rand_mut().below(DEFAULT_MUTATIONAL_MAX_ITERATIONS)) Ok(1 + state.rand_mut().below(self.max_iterations))
} }
} }
@ -238,7 +239,12 @@ where
{ {
/// Creates a new default mutational stage /// Creates a new default mutational stage
pub fn new(mutator: M) -> Self { pub fn new(mutator: M) -> Self {
Self::transforming(mutator) Self::transforming_with_max_iterations(mutator, DEFAULT_MUTATIONAL_MAX_ITERATIONS)
}
/// Creates a new mutational stage with the given max iterations
pub fn with_max_iterations(mutator: M, max_iterations: u64) -> Self {
Self::transforming_with_max_iterations(mutator, max_iterations)
} }
} }
@ -250,10 +256,16 @@ where
Z: Evaluator<E, EM>, Z: Evaluator<E, EM>,
Z::State: HasClientPerfMonitor + HasCorpus + HasRand, Z::State: HasClientPerfMonitor + HasCorpus + HasRand,
{ {
/// Creates a new transforming mutational stage /// Creates a new transforming mutational stage with the default max iterations
pub fn transforming(mutator: M) -> Self { pub fn transforming(mutator: M) -> Self {
Self::transforming_with_max_iterations(mutator, DEFAULT_MUTATIONAL_MAX_ITERATIONS)
}
/// Creates a new transforming mutational stage with the given max iterations
pub fn transforming_with_max_iterations(mutator: M, max_iterations: u64) -> Self {
Self { Self {
mutator, mutator,
max_iterations,
phantom: PhantomData, phantom: PhantomData,
} }
} }