Skip to content

Commit a1b0906

Browse files
authored
Migrate NopExecutor used in tests to ConstExecutor (#3129)
1 parent caf12a6 commit a1b0906

File tree

2 files changed

+13
-62
lines changed

2 files changed

+13
-62
lines changed

libafl/src/executors/mod.rs

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -230,77 +230,28 @@ pub fn common_signals() -> Vec<Signal> {
230230
#[cfg(test)]
231231
/// Tester for executor
232232
pub mod test {
233-
use core::marker::PhantomData;
234-
235-
use libafl_bolts::{AsSlice, Error};
236-
233+
use super::nop::NopExecutor;
237234
use crate::{
238235
events::NopEventManager,
239236
executors::{Executor, ExitKind},
240237
fuzzer::NopFuzzer,
241-
inputs::{BytesInput, HasTargetBytes},
242-
state::{HasExecutions, NopState},
238+
inputs::BytesInput,
239+
state::NopState,
243240
};
244241

245-
/// A simple executor that does nothing.
246-
/// If intput len is 0, `run_target` will return Err
247-
#[derive(Debug)]
248-
pub struct NopExecutor<S> {
249-
phantom: PhantomData<S>,
250-
}
251-
252-
impl<S> NopExecutor<S> {
253-
/// Creates a new [`NopExecutor`]
254-
#[must_use]
255-
pub fn new() -> Self {
256-
Self {
257-
phantom: PhantomData,
258-
}
259-
}
260-
}
261-
262-
impl<S> Default for NopExecutor<S> {
263-
fn default() -> Self {
264-
Self::new()
265-
}
266-
}
267-
268-
impl<EM, I, S, Z> Executor<EM, I, S, Z> for NopExecutor<S>
269-
where
270-
S: HasExecutions,
271-
I: HasTargetBytes,
272-
{
273-
fn run_target(
274-
&mut self,
275-
_fuzzer: &mut Z,
276-
state: &mut S,
277-
_mgr: &mut EM,
278-
input: &I,
279-
) -> Result<ExitKind, Error> {
280-
*state.executions_mut() += 1;
281-
282-
if input.target_bytes().as_slice().is_empty() {
283-
Err(Error::empty("Input Empty"))
284-
} else {
285-
Ok(ExitKind::Ok)
286-
}
287-
}
288-
}
289-
290242
#[test]
291243
fn nop_executor() {
292244
let empty_input = BytesInput::new(vec![]);
293-
let nonempty_input = BytesInput::new(vec![1u8]);
294-
let mut executor = NopExecutor::new();
245+
let mut executor = NopExecutor::ok();
295246
let mut fuzzer = NopFuzzer::new();
296247
let mut mgr: NopEventManager = NopEventManager::new();
297248
let mut state: NopState<BytesInput> = NopState::new();
298249

299-
executor
300-
.run_target(&mut fuzzer, &mut state, &mut mgr, &empty_input)
301-
.unwrap_err();
302-
executor
303-
.run_target(&mut fuzzer, &mut state, &mut mgr, &nonempty_input)
304-
.unwrap();
250+
assert_eq!(
251+
executor
252+
.run_target(&mut fuzzer, &mut state, &mut mgr, &empty_input)
253+
.unwrap(),
254+
ExitKind::Ok
255+
);
305256
}
306257
}

libafl/src/stages/logics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ mod test {
312312
use crate::{
313313
HasMetadata, NopFuzzer,
314314
events::NopEventManager,
315-
executors::test::NopExecutor,
315+
executors::nop::NopExecutor,
316316
stages::{
317317
ClosureStage, CorpusId, HasCurrentCorpusId, IfElseStage, IfStage, Restartable, Stage,
318318
StagesTuple, WhileStage,
@@ -456,7 +456,7 @@ mod test {
456456

457457
pub fn test_resume<ST, S>(completed: &Rc<RefCell<bool>>, state: &mut S, mut stages: ST)
458458
where
459-
ST: StagesTuple<NopExecutor<S>, NopEventManager, S, NopFuzzer>,
459+
ST: StagesTuple<NopExecutor, NopEventManager, S, NopFuzzer>,
460460
S: HasCurrentStageId + HasCurrentCorpusId,
461461
{
462462
#[cfg(any(not(feature = "serdeany_autoreg"), miri))]
@@ -466,7 +466,7 @@ mod test {
466466
}
467467

468468
let mut fuzzer = NopFuzzer::new();
469-
let mut executor = NopExecutor::new();
469+
let mut executor = NopExecutor::ok();
470470
let mut manager = NopEventManager::new();
471471
for _ in 0..2 {
472472
completed.replace(false);

0 commit comments

Comments
 (0)