Add StdState::nop() for simple state creation, make CI happy again on latest nightly. (#2521)

* Make CI happy again on latest nightly

* Fix build

* Unneeded comment

* fix tests

* clippy
This commit is contained in:
Dominik Maier 2024-09-12 00:33:55 +02:00 committed by GitHub
parent 25624d8eec
commit 8ccff4b77f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 99 additions and 102 deletions

View File

@ -258,7 +258,7 @@ impl Context {
max_len: usize,
nt: NTermId,
p_include_short_rules: usize,
) -> impl Iterator<Item = &RuleId> + 'a {
) -> impl Iterator<Item = &'a RuleId> + 'a {
self.nts_to_rules[&nt]
.iter()
.take_while(move |r| self.rules_to_min_size[*r] <= max_len)

View File

@ -620,7 +620,7 @@ mod tests {
command::{CommandExecutor, InputLocation},
Executor,
},
fuzzer::test::NopFuzzer,
fuzzer::NopFuzzer,
inputs::BytesInput,
monitors::SimpleMonitor,
state::NopState,

View File

@ -394,7 +394,7 @@ mod tests {
hooks::inprocess_fork::InChildProcessHooks,
inprocess_fork::GenericInProcessForkExecutor,
},
fuzzer::test::NopFuzzer,
fuzzer::NopFuzzer,
state::NopState,
};

View File

@ -165,7 +165,7 @@ pub fn common_signals() -> Vec<Signal> {
}
#[cfg(test)]
pub mod test {
mod test {
use core::marker::PhantomData;
use libafl_bolts::{AsSlice, Error};
@ -173,7 +173,7 @@ pub mod test {
use crate::{
events::NopEventManager,
executors::{Executor, ExitKind},
fuzzer::test::NopFuzzer,
fuzzer::NopFuzzer,
inputs::{BytesInput, HasTargetBytes},
state::{HasExecutions, NopState, State, UsesState},
};
@ -186,6 +186,7 @@ pub mod test {
}
impl<S> NopExecutor<S> {
/// Creates a new [`NopExecutor`]
#[must_use]
pub fn new() -> Self {
Self {

View File

@ -1,7 +1,7 @@
//! The `Fuzzer` is the main struct for a fuzz campaign.
use alloc::{string::ToString, vec::Vec};
use core::{fmt::Debug, time::Duration};
use core::{fmt::Debug, marker::PhantomData, time::Duration};
use libafl_bolts::current_time;
use serde::{de::DeserializeOwned, Serialize};
@ -19,7 +19,7 @@ use crate::{
start_timer,
state::{
HasCorpus, HasCurrentTestcase, HasExecutions, HasLastFoundTime, HasLastReportTime,
HasSolutions, Stoppable, UsesState,
HasSolutions, State, Stoppable, UsesState,
},
Error, HasMetadata,
};
@ -931,26 +931,14 @@ where
}
}
#[cfg(test)]
pub mod test {
use core::marker::PhantomData;
use libafl_bolts::Error;
use crate::{
corpus::CorpusId,
events::{EventProcessor, ProgressReporter},
stages::{HasCurrentStageId, StagesTuple},
state::{HasExecutions, HasLastReportTime, State, UsesState},
Fuzzer, HasMetadata,
};
/// A [`NopFuzzer`] that does nothing
#[derive(Clone, Debug)]
pub struct NopFuzzer<S> {
phantom: PhantomData<S>,
}
impl<S> NopFuzzer<S> {
/// Creates a new [`NopFuzzer`]
#[must_use]
pub fn new() -> Self {
Self {
@ -986,7 +974,6 @@ pub mod test {
_state: &mut EM::State,
_manager: &mut EM,
) -> Result<CorpusId, Error> {
unimplemented!()
}
unimplemented!("NopFuzzer cannot fuzz");
}
}

View File

@ -699,7 +699,7 @@ impl ExecutionCountRestartHelper {
}
#[cfg(test)]
pub mod test {
mod test {
use alloc::borrow::Cow;
use core::marker::PhantomData;
@ -710,15 +710,17 @@ pub mod test {
corpus::{Corpus, HasCurrentCorpusId, Testcase},
inputs::NopInput,
stages::{RetryCountRestartHelper, Stage},
state::{test::test_std_state, HasCorpus, State, UsesState},
state::{HasCorpus, State, StdState, UsesState},
HasMetadata,
};
/// A stage that succeeds to resume
#[derive(Debug)]
pub struct ResumeSucceededStage<S> {
phantom: PhantomData<S>,
}
/// A progress state for testing
#[derive(Serialize, Deserialize, Debug)]
pub struct TestProgress {
count: usize,
@ -790,6 +792,7 @@ pub mod test {
}
}
/// Test to test retries in stages
#[test]
fn test_tries_progress() -> Result<(), Error> {
// # Safety
@ -808,7 +811,7 @@ pub mod test {
}
}
let mut state = test_std_state();
let mut state = StdState::nop()?;
let stage = StageWithOneTry;
let corpus_id = state.corpus_mut().add(Testcase::new(NopInput {}))?;

View File

@ -31,12 +31,12 @@ use crate::monitors::ClientPerfMonitor;
#[cfg(feature = "scalability_introspection")]
use crate::monitors::ScalabilityMonitor;
use crate::{
corpus::{Corpus, CorpusId, HasCurrentCorpusId, HasTestcase, Testcase},
corpus::{Corpus, CorpusId, HasCurrentCorpusId, HasTestcase, InMemoryCorpus, Testcase},
events::{Event, EventFirer, LogSeverity},
feedbacks::Feedback,
fuzzer::{Evaluator, ExecuteInputResult},
generators::Generator,
inputs::{Input, UsesInput},
inputs::{Input, NopInput, UsesInput},
stages::{HasCurrentStageId, HasNestedStageStatus, StageId},
Error, HasMetadata, HasNamedMetadata,
};
@ -1165,6 +1165,23 @@ where
}
}
impl StdState<NopInput, InMemoryCorpus<NopInput>, StdRand, InMemoryCorpus<NopInput>> {
/// Create an empty [`StdState`] that has very minimal uses.
/// Potentially good for testing.
pub fn nop<I>() -> Result<StdState<I, InMemoryCorpus<I>, StdRand, InMemoryCorpus<I>>, Error>
where
I: Input,
{
StdState::new(
StdRand::with_seed(0),
InMemoryCorpus::<I>::new(),
InMemoryCorpus::new(),
&mut (),
&mut (),
)
}
}
#[cfg(feature = "introspection")]
impl<I, C, R, SC> HasClientPerfMonitor for StdState<I, C, R, SC> {
fn introspection_monitor(&self) -> &ClientPerfMonitor {
@ -1337,22 +1354,11 @@ impl<I> HasScalabilityMonitor for NopState<I> {
}
#[cfg(test)]
pub mod test {
use libafl_bolts::rands::StdRand;
mod test {
use crate::{inputs::BytesInput, state::StdState};
use super::StdState;
use crate::{corpus::InMemoryCorpus, inputs::Input};
#[must_use]
pub fn test_std_state<I: Input>() -> StdState<I, InMemoryCorpus<I>, StdRand, InMemoryCorpus<I>>
{
StdState::new(
StdRand::with_seed(0),
InMemoryCorpus::<I>::new(),
InMemoryCorpus::new(),
&mut (),
&mut (),
)
.expect("couldn't instantiate the test state")
#[test]
fn test_std_state() {
StdState::nop::<BytesInput>().expect("couldn't instantiate the test state");
}
}

View File

@ -3778,7 +3778,7 @@ mod tests {
#[test]
#[serial]
#[cfg_attr(miri, ignore)]
pub fn test_llmp_connection() {
fn test_llmp_connection() {
#[allow(unused_variables)]
let shmem_provider = StdShMemProvider::new().unwrap();
let mut broker = match LlmpConnection::on_port(shmem_provider.clone(), 1337).unwrap() {

View File

@ -1163,7 +1163,7 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore)]
pub fn test_dump_registers() {
fn test_dump_registers() {
let ucontext = ucontext().unwrap();
let mut writer = BufWriter::new(stdout());
dump_registers(&mut writer, &ucontext).unwrap();
@ -1193,7 +1193,7 @@ mod tests {
#[test]
#[cfg_attr(miri, ignore)]
pub fn test_dump_registers() {
fn test_dump_registers() {
let (tx, rx) = mpsc::channel();
let (evt_tx, evt_rx) = mpsc::channel();
let t = std::thread::spawn(move || {

View File

@ -824,22 +824,6 @@ macro_rules! tuple_for_each_mut {
};
}
#[cfg(test)]
#[cfg(feature = "std")]
#[test]
#[allow(clippy::items_after_statements)]
pub fn test_macros() {
let mut t = tuple_list!(1, "a");
tuple_for_each!(f1, std::fmt::Display, t, |x| {
log::info!("{x}");
});
tuple_for_each_mut!(f2, std::fmt::Display, t, |x| {
log::info!("{x}");
});
}
/*
// Define trait and implement it for several primitive types.
@ -944,4 +928,20 @@ mod test {
#[allow(clippy::no_effect_underscore_binding)]
let _type_assert: tuple_list_type!(W<A>, W<B>, W<C>) = mapped;
}
/// Function that tests the tuple macros
#[test]
#[cfg(feature = "std")]
#[allow(clippy::items_after_statements)]
fn test_macros() {
let mut t = tuple_list!(1, "a");
tuple_for_each!(f1, std::fmt::Display, t, |x| {
log::info!("{x}");
});
tuple_for_each_mut!(f2, std::fmt::Display, t, |x| {
log::info!("{x}");
});
}
}