Migrate NopExecutor used in tests to ConstExecutor (#3129)
This commit is contained in:
parent
caf12a647c
commit
a1b090609d
@ -230,77 +230,28 @@ pub fn common_signals() -> Vec<Signal> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
/// Tester for executor
|
/// Tester for executor
|
||||||
pub mod test {
|
pub mod test {
|
||||||
use core::marker::PhantomData;
|
use super::nop::NopExecutor;
|
||||||
|
|
||||||
use libafl_bolts::{AsSlice, Error};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
events::NopEventManager,
|
events::NopEventManager,
|
||||||
executors::{Executor, ExitKind},
|
executors::{Executor, ExitKind},
|
||||||
fuzzer::NopFuzzer,
|
fuzzer::NopFuzzer,
|
||||||
inputs::{BytesInput, HasTargetBytes},
|
inputs::BytesInput,
|
||||||
state::{HasExecutions, NopState},
|
state::NopState,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A simple executor that does nothing.
|
|
||||||
/// If intput len is 0, `run_target` will return Err
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct NopExecutor<S> {
|
|
||||||
phantom: PhantomData<S>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S> NopExecutor<S> {
|
|
||||||
/// Creates a new [`NopExecutor`]
|
|
||||||
#[must_use]
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S> Default for NopExecutor<S> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<EM, I, S, Z> Executor<EM, I, S, Z> for NopExecutor<S>
|
|
||||||
where
|
|
||||||
S: HasExecutions,
|
|
||||||
I: HasTargetBytes,
|
|
||||||
{
|
|
||||||
fn run_target(
|
|
||||||
&mut self,
|
|
||||||
_fuzzer: &mut Z,
|
|
||||||
state: &mut S,
|
|
||||||
_mgr: &mut EM,
|
|
||||||
input: &I,
|
|
||||||
) -> Result<ExitKind, Error> {
|
|
||||||
*state.executions_mut() += 1;
|
|
||||||
|
|
||||||
if input.target_bytes().as_slice().is_empty() {
|
|
||||||
Err(Error::empty("Input Empty"))
|
|
||||||
} else {
|
|
||||||
Ok(ExitKind::Ok)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn nop_executor() {
|
fn nop_executor() {
|
||||||
let empty_input = BytesInput::new(vec![]);
|
let empty_input = BytesInput::new(vec![]);
|
||||||
let nonempty_input = BytesInput::new(vec![1u8]);
|
let mut executor = NopExecutor::ok();
|
||||||
let mut executor = NopExecutor::new();
|
|
||||||
let mut fuzzer = NopFuzzer::new();
|
let mut fuzzer = NopFuzzer::new();
|
||||||
let mut mgr: NopEventManager = NopEventManager::new();
|
let mut mgr: NopEventManager = NopEventManager::new();
|
||||||
let mut state: NopState<BytesInput> = NopState::new();
|
let mut state: NopState<BytesInput> = NopState::new();
|
||||||
|
|
||||||
executor
|
assert_eq!(
|
||||||
.run_target(&mut fuzzer, &mut state, &mut mgr, &empty_input)
|
executor
|
||||||
.unwrap_err();
|
.run_target(&mut fuzzer, &mut state, &mut mgr, &empty_input)
|
||||||
executor
|
.unwrap(),
|
||||||
.run_target(&mut fuzzer, &mut state, &mut mgr, &nonempty_input)
|
ExitKind::Ok
|
||||||
.unwrap();
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ mod test {
|
|||||||
use crate::{
|
use crate::{
|
||||||
HasMetadata, NopFuzzer,
|
HasMetadata, NopFuzzer,
|
||||||
events::NopEventManager,
|
events::NopEventManager,
|
||||||
executors::test::NopExecutor,
|
executors::nop::NopExecutor,
|
||||||
stages::{
|
stages::{
|
||||||
ClosureStage, CorpusId, HasCurrentCorpusId, IfElseStage, IfStage, Restartable, Stage,
|
ClosureStage, CorpusId, HasCurrentCorpusId, IfElseStage, IfStage, Restartable, Stage,
|
||||||
StagesTuple, WhileStage,
|
StagesTuple, WhileStage,
|
||||||
@ -456,7 +456,7 @@ mod test {
|
|||||||
|
|
||||||
pub fn test_resume<ST, S>(completed: &Rc<RefCell<bool>>, state: &mut S, mut stages: ST)
|
pub fn test_resume<ST, S>(completed: &Rc<RefCell<bool>>, state: &mut S, mut stages: ST)
|
||||||
where
|
where
|
||||||
ST: StagesTuple<NopExecutor<S>, NopEventManager, S, NopFuzzer>,
|
ST: StagesTuple<NopExecutor, NopEventManager, S, NopFuzzer>,
|
||||||
S: HasCurrentStageId + HasCurrentCorpusId,
|
S: HasCurrentStageId + HasCurrentCorpusId,
|
||||||
{
|
{
|
||||||
#[cfg(any(not(feature = "serdeany_autoreg"), miri))]
|
#[cfg(any(not(feature = "serdeany_autoreg"), miri))]
|
||||||
@ -466,7 +466,7 @@ mod test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut fuzzer = NopFuzzer::new();
|
let mut fuzzer = NopFuzzer::new();
|
||||||
let mut executor = NopExecutor::new();
|
let mut executor = NopExecutor::ok();
|
||||||
let mut manager = NopEventManager::new();
|
let mut manager = NopEventManager::new();
|
||||||
for _ in 0..2 {
|
for _ in 0..2 {
|
||||||
completed.replace(false);
|
completed.replace(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user