DefaultRand, tidied up imports
This commit is contained in:
parent
538ad8edde
commit
1533c87775
@ -1,16 +1,17 @@
|
||||
extern crate alloc;
|
||||
|
||||
pub mod testcase;
|
||||
pub use testcase::{Testcase, TestcaseMetadata};
|
||||
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::{HasRand, Rand};
|
||||
use crate::AflError;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use core::marker::PhantomData;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::{HasRand, Rand};
|
||||
use crate::AflError;
|
||||
|
||||
pub trait HasEntriesVec<I>
|
||||
where
|
||||
I: Input,
|
||||
@ -307,14 +308,14 @@ mod tests {
|
||||
use crate::corpus::Testcase;
|
||||
use crate::corpus::{OnDiskCorpus, QueueCorpus};
|
||||
use crate::inputs::bytes::BytesInput;
|
||||
use crate::utils::Xoshiro256StarRand;
|
||||
use crate::utils::DefaultRand;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[test]
|
||||
|
||||
fn test_queuecorpus() {
|
||||
let rand = Xoshiro256StarRand::preseeded_rr();
|
||||
let rand = DefaultRand::preseeded_rr();
|
||||
let mut q = QueueCorpus::new(OnDiskCorpus::new(&rand, PathBuf::from("fancy/path")));
|
||||
let i = BytesInput::new(vec![0; 4]);
|
||||
let t = Testcase::with_filename_rr(i, PathBuf::from("fancyfile"));
|
||||
|
@ -1,4 +1,5 @@
|
||||
extern crate alloc;
|
||||
|
||||
use crate::inputs::Input;
|
||||
use crate::AflError;
|
||||
|
||||
|
@ -1,15 +1,15 @@
|
||||
//! The engine is the core piece of every good fuzzer
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::corpus::Corpus;
|
||||
use crate::feedbacks::Feedback;
|
||||
use crate::inputs::Input;
|
||||
use crate::stages::Stage;
|
||||
use crate::AflError;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
pub trait Engine<C, I>
|
||||
where
|
||||
C: Corpus<I>,
|
||||
@ -89,6 +89,10 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::corpus::{Corpus, InMemoryCorpus, Testcase};
|
||||
use crate::engines::{DefaultEngine, Engine};
|
||||
use crate::executors::inmemory::InMemoryExecutor;
|
||||
@ -98,10 +102,7 @@ mod tests {
|
||||
mutation_bitflip, ComposedByMutations, DefaultScheduledMutator,
|
||||
};
|
||||
use crate::stages::mutational::DefaultMutationalStage;
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::utils::Xoshiro256StarRand;
|
||||
use crate::utils::DefaultRand;
|
||||
|
||||
fn harness<I>(_executor: &dyn Executor<I>, _buf: &[u8]) -> ExitKind {
|
||||
ExitKind::Ok
|
||||
@ -109,7 +110,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_engine() {
|
||||
let rand = Xoshiro256StarRand::preseeded_rr();
|
||||
let rand = DefaultRand::preseeded_rr();
|
||||
|
||||
let mut corpus = InMemoryCorpus::<BytesInput, _>::new(&rand);
|
||||
let testcase = Testcase::new_rr(BytesInput::new(vec![0; 4]));
|
||||
|
@ -1,15 +1,15 @@
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
use crate::feedbacks::Feedback;
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::Observer;
|
||||
use crate::AflError;
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
|
||||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
|
||||
type HarnessFunction<I> = fn(&dyn Executor<I>, &[u8]) -> ExitKind;
|
||||
|
||||
|
@ -1,14 +1,15 @@
|
||||
extern crate alloc;
|
||||
pub mod inmemory;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
use crate::corpus::Testcase;
|
||||
use crate::corpus::TestcaseMetadata;
|
||||
use crate::feedbacks::Feedback;
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::Observer;
|
||||
use crate::AflError;
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
pub enum ExitKind {
|
||||
Ok,
|
||||
|
@ -1,14 +1,14 @@
|
||||
extern crate alloc;
|
||||
extern crate num;
|
||||
|
||||
use crate::corpus::TestcaseMetadata;
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::MapObserver;
|
||||
|
||||
use core::cell::RefCell;
|
||||
use core::marker::PhantomData;
|
||||
use num::Integer;
|
||||
|
||||
use crate::corpus::TestcaseMetadata;
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::MapObserver;
|
||||
|
||||
pub trait Feedback<I>
|
||||
where
|
||||
I: Input,
|
||||
|
@ -1,4 +1,5 @@
|
||||
extern crate alloc;
|
||||
|
||||
use crate::inputs::{HasBytesVec, HasTargetBytes, Input};
|
||||
use crate::AflError;
|
||||
|
||||
@ -43,11 +44,11 @@ impl BytesInput {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::{next_pow2, Rand, Xoshiro256StarRand};
|
||||
use crate::utils::{next_pow2, DefaultRand, Rand};
|
||||
|
||||
#[test]
|
||||
fn test_input() {
|
||||
let mut rand = Xoshiro256StarRand::preseeded();
|
||||
let mut rand = DefaultRand::preseeded();
|
||||
assert_ne!(rand.next(), rand.next());
|
||||
assert!(rand.below(100) < 100);
|
||||
assert_eq!(rand.below(1), 0);
|
||||
|
@ -1,8 +1,9 @@
|
||||
extern crate alloc;
|
||||
|
||||
pub mod bytes;
|
||||
pub use bytes::BytesInput;
|
||||
|
||||
use std::clone::Clone;
|
||||
use core::clone::Clone;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
|
@ -1,6 +1,4 @@
|
||||
extern crate alloc;
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod corpus;
|
||||
pub mod engines;
|
||||
@ -13,6 +11,9 @@ pub mod observers;
|
||||
pub mod stages;
|
||||
pub mod utils;
|
||||
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum AflError {
|
||||
#[error("Error in Serialization: `{0}`")]
|
||||
|
@ -1,11 +1,12 @@
|
||||
extern crate alloc;
|
||||
|
||||
pub mod scheduled;
|
||||
use crate::corpus::Corpus;
|
||||
pub use scheduled::ComposedByMutations;
|
||||
pub use scheduled::DefaultScheduledMutator;
|
||||
pub use scheduled::HavocBytesMutator;
|
||||
pub use scheduled::ScheduledMutator;
|
||||
|
||||
use crate::corpus::Corpus;
|
||||
use crate::inputs::Input;
|
||||
use crate::utils::HasRand;
|
||||
use crate::AflError;
|
||||
|
@ -1,4 +1,5 @@
|
||||
extern crate alloc;
|
||||
|
||||
use crate::inputs::{HasBytesVec, Input};
|
||||
use crate::mutators::Corpus;
|
||||
use crate::mutators::Mutator;
|
||||
@ -326,12 +327,12 @@ mod tests {
|
||||
use crate::corpus::{Corpus, InMemoryCorpus};
|
||||
use crate::inputs::{BytesInput, HasBytesVec};
|
||||
use crate::mutators::scheduled::mutation_splice;
|
||||
use crate::utils::{DefaultHasRand, Xoshiro256StarRand};
|
||||
use crate::utils::{DefaultHasRand, DefaultRand};
|
||||
|
||||
#[test]
|
||||
fn test_mut_splice() {
|
||||
// With the current impl, seed of 1 will result in a split at pos 2.
|
||||
let rand = &Xoshiro256StarRand::new_rr(1);
|
||||
let rand = &DefaultRand::new_rr(1);
|
||||
let mut has_rand = DefaultHasRand::new(&rand);
|
||||
let mut corpus = InMemoryCorpus::new(&rand);
|
||||
corpus.add_input(BytesInput::new(vec!['a' as u8, 'b' as u8, 'c' as u8]));
|
||||
|
@ -1,8 +1,8 @@
|
||||
extern crate alloc;
|
||||
extern crate num;
|
||||
|
||||
use core::slice::from_raw_parts_mut;
|
||||
use num::Integer;
|
||||
use std::slice::from_raw_parts_mut;
|
||||
|
||||
use crate::AflError;
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
extern crate alloc;
|
||||
|
||||
pub mod mutational;
|
||||
use crate::corpus::Corpus;
|
||||
pub use mutational::DefaultMutationalStage;
|
||||
|
||||
use crate::corpus::Corpus;
|
||||
use crate::inputs::Input;
|
||||
use crate::AflError;
|
||||
|
||||
|
@ -1,4 +1,9 @@
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use crate::corpus::testcase::Testcase;
|
||||
use crate::executors::Executor;
|
||||
use crate::inputs::Input;
|
||||
@ -8,10 +13,6 @@ use crate::stages::Stage;
|
||||
use crate::utils::{HasRand, Rand};
|
||||
use crate::AflError;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
// TODO create HasMutatorsVec trait
|
||||
|
||||
pub trait MutationalStage<C, I, M, E>: Stage<C, I> + HasRand
|
||||
|
15
src/utils.rs
15
src/utils.rs
@ -3,12 +3,13 @@ extern crate alloc;
|
||||
|
||||
use alloc::rc::Rc;
|
||||
use core::cell::RefCell;
|
||||
use std::debug_assert;
|
||||
use std::fmt::Debug;
|
||||
use core::debug_assert;
|
||||
use core::fmt::Debug;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use xxhash_rust::xxh3::xxh3_64_with_seed;
|
||||
|
||||
pub type DefaultRand = Xoshiro256StarRand;
|
||||
|
||||
/// Ways to get random around here
|
||||
pub trait Rand: Debug {
|
||||
// Sets the seed of this Rand
|
||||
@ -171,7 +172,7 @@ where
|
||||
}
|
||||
|
||||
/// Get the next higher power of two
|
||||
pub fn next_pow2(val: u64) -> u64 {
|
||||
pub const fn next_pow2(val: u64) -> u64 {
|
||||
let mut out = val.wrapping_sub(1);
|
||||
out |= out >> 1;
|
||||
out |= out >> 2;
|
||||
@ -183,11 +184,11 @@ pub fn next_pow2(val: u64) -> u64 {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::{next_pow2, DefaultHasRand, HasRand, Rand, Xoshiro256StarRand};
|
||||
use crate::utils::{next_pow2, DefaultHasRand, DefaultRand, HasRand, Rand};
|
||||
|
||||
#[test]
|
||||
fn test_rand() {
|
||||
let mut rand = Xoshiro256StarRand::preseeded();
|
||||
let mut rand = DefaultRand::preseeded();
|
||||
assert_ne!(rand.next(), rand.next());
|
||||
assert!(rand.below(100) < 100);
|
||||
assert_eq!(rand.below(1), 0);
|
||||
@ -197,7 +198,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_has_rand() {
|
||||
let rand = Xoshiro256StarRand::preseeded_rr();
|
||||
let rand = DefaultRand::preseeded_rr();
|
||||
let has_rand = DefaultHasRand::new(&rand);
|
||||
|
||||
assert!(has_rand.rand_below(100) < 100);
|
||||
|
Loading…
x
Reference in New Issue
Block a user