1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
pub mod queue;
pub use queue::QueueScheduler;
pub mod probabilistic_sampling;
pub use probabilistic_sampling::ProbabilitySamplingScheduler;
pub mod accounting;
pub use accounting::CoverageAccountingScheduler;
pub mod testcase_score;
pub use testcase_score::{LenTimeMulTestcaseScore, TestcaseScore};
pub mod minimizer;
pub use minimizer::{
IndexesLenTimeMinimizerScheduler, LenTimeMinimizerScheduler, MinimizerScheduler,
};
pub mod weighted;
pub use weighted::{StdWeightedScheduler, WeightedScheduler};
pub mod powersched;
use alloc::borrow::ToOwned;
pub use powersched::PowerQueueScheduler;
use crate::{
bolts::rands::Rand,
corpus::{Corpus, Testcase},
inputs::Input,
state::{HasCorpus, HasRand},
Error,
};
pub trait Scheduler<I, S>
where
I: Input,
{
fn on_add(&self, _state: &mut S, _idx: usize) -> Result<(), Error> {
Ok(())
}
fn on_replace(
&self,
_state: &mut S,
_idx: usize,
_testcase: &Testcase<I>,
) -> Result<(), Error> {
Ok(())
}
fn on_remove(
&self,
_state: &mut S,
_idx: usize,
_testcase: &Option<Testcase<I>>,
) -> Result<(), Error> {
Ok(())
}
fn next(&self, state: &mut S) -> Result<usize, Error>;
}
#[derive(Debug, Clone)]
pub struct RandScheduler;
impl<I, S> Scheduler<I, S> for RandScheduler
where
S: HasCorpus<I> + HasRand,
I: Input,
{
fn next(&self, state: &mut S) -> Result<usize, Error> {
if state.corpus().count() == 0 {
Err(Error::empty("No entries in corpus".to_owned()))
} else {
let len = state.corpus().count();
let id = state.rand_mut().below(len as u64) as usize;
*state.corpus_mut().current_mut() = Some(id);
Ok(id)
}
}
}
impl RandScheduler {
#[must_use]
pub fn new() -> Self {
Self
}
}
impl Default for RandScheduler {
fn default() -> Self {
Self::new()
}
}
pub type StdScheduler = RandScheduler;