From a1b090609ddbdd38a8a3f3a97b280c8bf2b7b970 Mon Sep 17 00:00:00 2001 From: lazymio Date: Fri, 4 Apr 2025 20:55:33 +0800 Subject: [PATCH] Migrate NopExecutor used in tests to ConstExecutor (#3129) --- libafl/src/executors/mod.rs | 69 ++++++------------------------------- libafl/src/stages/logics.rs | 6 ++-- 2 files changed, 13 insertions(+), 62 deletions(-) diff --git a/libafl/src/executors/mod.rs b/libafl/src/executors/mod.rs index 3754e5c156..184e1079a7 100644 --- a/libafl/src/executors/mod.rs +++ b/libafl/src/executors/mod.rs @@ -230,77 +230,28 @@ pub fn common_signals() -> Vec { #[cfg(test)] /// Tester for executor pub mod test { - use core::marker::PhantomData; - - use libafl_bolts::{AsSlice, Error}; - + use super::nop::NopExecutor; use crate::{ events::NopEventManager, executors::{Executor, ExitKind}, fuzzer::NopFuzzer, - inputs::{BytesInput, HasTargetBytes}, - state::{HasExecutions, NopState}, + inputs::BytesInput, + state::NopState, }; - /// A simple executor that does nothing. - /// If intput len is 0, `run_target` will return Err - #[derive(Debug)] - pub struct NopExecutor { - phantom: PhantomData, - } - - impl NopExecutor { - /// Creates a new [`NopExecutor`] - #[must_use] - pub fn new() -> Self { - Self { - phantom: PhantomData, - } - } - } - - impl Default for NopExecutor { - fn default() -> Self { - Self::new() - } - } - - impl Executor for NopExecutor - where - S: HasExecutions, - I: HasTargetBytes, - { - fn run_target( - &mut self, - _fuzzer: &mut Z, - state: &mut S, - _mgr: &mut EM, - input: &I, - ) -> Result { - *state.executions_mut() += 1; - - if input.target_bytes().as_slice().is_empty() { - Err(Error::empty("Input Empty")) - } else { - Ok(ExitKind::Ok) - } - } - } - #[test] fn nop_executor() { let empty_input = BytesInput::new(vec![]); - let nonempty_input = BytesInput::new(vec![1u8]); - let mut executor = NopExecutor::new(); + let mut executor = NopExecutor::ok(); let mut fuzzer = NopFuzzer::new(); let mut mgr: NopEventManager = NopEventManager::new(); let mut state: NopState = NopState::new(); - executor - .run_target(&mut fuzzer, &mut state, &mut mgr, &empty_input) - .unwrap_err(); - executor - .run_target(&mut fuzzer, &mut state, &mut mgr, &nonempty_input) - .unwrap(); + assert_eq!( + executor + .run_target(&mut fuzzer, &mut state, &mut mgr, &empty_input) + .unwrap(), + ExitKind::Ok + ); } } diff --git a/libafl/src/stages/logics.rs b/libafl/src/stages/logics.rs index 7decb3a78b..a5f0c22f63 100644 --- a/libafl/src/stages/logics.rs +++ b/libafl/src/stages/logics.rs @@ -312,7 +312,7 @@ mod test { use crate::{ HasMetadata, NopFuzzer, events::NopEventManager, - executors::test::NopExecutor, + executors::nop::NopExecutor, stages::{ ClosureStage, CorpusId, HasCurrentCorpusId, IfElseStage, IfStage, Restartable, Stage, StagesTuple, WhileStage, @@ -456,7 +456,7 @@ mod test { pub fn test_resume(completed: &Rc>, state: &mut S, mut stages: ST) where - ST: StagesTuple, NopEventManager, S, NopFuzzer>, + ST: StagesTuple, S: HasCurrentStageId + HasCurrentCorpusId, { #[cfg(any(not(feature = "serdeany_autoreg"), miri))] @@ -466,7 +466,7 @@ mod test { } let mut fuzzer = NopFuzzer::new(); - let mut executor = NopExecutor::new(); + let mut executor = NopExecutor::ok(); let mut manager = NopEventManager::new(); for _ in 0..2 { completed.replace(false);