started reworking Testcases
This commit is contained in:
parent
0cb5c33a29
commit
397099f0be
@ -18,7 +18,7 @@ where
|
||||
I: Input,
|
||||
{
|
||||
/// Get the entries vector field
|
||||
fn entries(&self) -> &Vec<Rc<RefCell<Testcase<I>>>>;
|
||||
fn entries(&self) -> &[Rc<RefCell<Testcase<I>>>];
|
||||
|
||||
/// Get the entries vector field (mutable)
|
||||
fn entries_mut(&mut self) -> &mut Vec<Rc<RefCell<Testcase<I>>>>;
|
||||
@ -89,7 +89,7 @@ where
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
fn entries(&self) -> &Vec<Rc<RefCell<Testcase<I>>>> {
|
||||
fn entries(&self) -> &[Rc<RefCell<Testcase<I>>>] {
|
||||
&self.entries
|
||||
}
|
||||
fn entries_mut(&mut self) -> &mut Vec<Rc<RefCell<Testcase<I>>>> {
|
||||
@ -147,7 +147,7 @@ where
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
fn entries(&self) -> &Vec<Rc<RefCell<Testcase<I>>>> {
|
||||
fn entries(&self) -> &[Rc<RefCell<Testcase<I>>>] {
|
||||
&self.entries
|
||||
}
|
||||
fn entries_mut(&mut self) -> &mut Vec<Rc<RefCell<Testcase<I>>>> {
|
||||
@ -220,7 +220,7 @@ where
|
||||
I: Input,
|
||||
C: Corpus<I>,
|
||||
{
|
||||
fn entries(&self) -> &Vec<Rc<RefCell<Testcase<I>>>> {
|
||||
fn entries(&self) -> &[Rc<RefCell<Testcase<I>>>] {
|
||||
self.corpus.entries()
|
||||
}
|
||||
fn entries_mut(&mut self) -> &mut Vec<Rc<RefCell<Testcase<I>>>> {
|
||||
|
@ -24,23 +24,26 @@ pub trait TestcaseMetadata {
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
/*
|
||||
pub trait Testcase<I, T>
|
||||
pub trait TestcaseTraitTODO<I, T>
|
||||
where
|
||||
I: Input,
|
||||
T: TestcaseMetadata,
|
||||
{
|
||||
/// The input associated with this testcase
|
||||
fn input(&self) -> &Option<I>;
|
||||
|
||||
fn input(&mut self) -> Option<I>
|
||||
/// The input associated with this testcase (mutable)
|
||||
fn input_mut(&mut self) -> &mut Option<I>;
|
||||
|
||||
input: Option<I>,
|
||||
/// Filename, if this testcase is backed by a file in the filesystem
|
||||
filename: Option<String>,
|
||||
/// Map of metadatas associated with this testcase
|
||||
metadatas: HashMap<&'static str, Box<dyn TestcaseMetadata>>,
|
||||
fn filename(&self) -> &Option<String>;
|
||||
|
||||
/// Map of metadatas associated with this testcase
|
||||
fn metadatas(&self) -> &HashMap<&'static str, Box<dyn TestcaseMetadata>>;
|
||||
|
||||
/// Map of metadatas associated with this testcase
|
||||
fn metadatas_mut(&mut self) -> &mut HashMap<&'static str, Box<dyn TestcaseMetadata>>;
|
||||
}
|
||||
*/
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub enum FileBackedTestcase<I, P> {
|
||||
@ -49,10 +52,18 @@ pub enum FileBackedTestcase<I, P> {
|
||||
|
||||
/// A testcase that has been loaded, and not yet dirtied.
|
||||
/// The input should be equal to the on-disk state.
|
||||
Loaded { input: I, filename: P },
|
||||
Loaded {
|
||||
input: I,
|
||||
filename: P,
|
||||
//metadatas: HashMap<&'static str, Box<dyn TestcaseMetadata>>,
|
||||
},
|
||||
|
||||
/// A testcase that has been mutated, but not yet written to disk
|
||||
Dirty { input: I, filename: P },
|
||||
Dirty {
|
||||
input: I,
|
||||
filename: P,
|
||||
//metadatas: HashMap<&'static str, Box<dyn TestcaseMetadata>>,
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
@ -69,7 +80,10 @@ where
|
||||
match self {
|
||||
Self::Stored { filename } => {
|
||||
let input = I::from_file(&filename)?;
|
||||
Ok(Self::Loaded { filename, input })
|
||||
Ok(Self::Loaded {
|
||||
filename,
|
||||
input,
|
||||
})
|
||||
}
|
||||
Self::Loaded {
|
||||
input: _,
|
||||
@ -171,25 +185,18 @@ where
|
||||
pub fn input_mut(&mut self) -> &mut Option<I> {
|
||||
&mut self.input
|
||||
}
|
||||
/// Set the input
|
||||
pub fn set_input(&mut self, input: Option<I>) {
|
||||
self.input = input;
|
||||
}
|
||||
|
||||
/// Get the filename, if any
|
||||
pub fn filename(&self) -> &Option<String> {
|
||||
&self.filename
|
||||
}
|
||||
|
||||
/// Get the filename, if any (mutable)
|
||||
pub fn filename_mut(&mut self) -> &mut Option<String> {
|
||||
&mut self.filename
|
||||
}
|
||||
/// Set the filename
|
||||
pub fn set_filename(&mut self, filename: Option<String>) {
|
||||
self.filename = filename;
|
||||
}
|
||||
|
||||
/// Get all the metadatas into an HashMap
|
||||
/// Get all the metadatas into an HashMap (mutable)
|
||||
pub fn metadatas(&mut self) -> &mut HashMap<&'static str, Box<dyn TestcaseMetadata>> {
|
||||
&mut self.metadatas
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::rc::Rc;
|
||||
use alloc::vec::Vec;
|
||||
@ -201,13 +199,13 @@ compile_error!("InMemoryExecutor not yet supported on this OS");
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use crate::executors::inmemory::InMemoryExecutor;
|
||||
use crate::executors::{Executor, ExitKind};
|
||||
use crate::inputs::Input;
|
||||
use crate::observers::Observer;
|
||||
use crate::AflError;
|
||||
use alloc::boxed::Box;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct NopInput {}
|
||||
@ -233,7 +231,7 @@ mod tests {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn test_harness_fn_nop(_executor: &dyn Executor<NopInput>, buf: &[u8]) -> ExitKind {
|
||||
println! {"Fake exec with buf of len {}", buf.len()};
|
||||
println!("Fake exec with buf of len {}", buf.len());
|
||||
ExitKind::Ok
|
||||
}
|
||||
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -22,15 +22,24 @@ use std::io;
|
||||
/// Main error struct for AFL
|
||||
#[derive(Debug)]
|
||||
pub enum AflError {
|
||||
/// Serialization error
|
||||
Serialize(String),
|
||||
/// File related error
|
||||
#[cfg(feature = "std")]
|
||||
File(io::Error),
|
||||
/// Optional val was supposed to be set, but isn't.
|
||||
EmptyOptional(String),
|
||||
/// Key not in Map
|
||||
KeyNotFound(String),
|
||||
/// No elements in the current item
|
||||
Empty(String),
|
||||
/// End of iteration
|
||||
IteratorEnd(String),
|
||||
/// This is not supported (yet)
|
||||
NotImplemented(String),
|
||||
/// You're holding it wrong
|
||||
IllegalState(String),
|
||||
/// Something else happened
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
@ -53,6 +62,7 @@ impl fmt::Display for AflError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an AFL Error from io Error
|
||||
#[cfg(feature = "std")]
|
||||
impl From<io::Error> for AflError {
|
||||
fn from(err: io::Error) -> Self {
|
||||
|
13
src/utils.rs
13
src/utils.rs
@ -231,6 +231,19 @@ mod tests {
|
||||
assert!(rand.between(11, 20) > 10);
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[test]
|
||||
fn test_rand_preseeded() {
|
||||
let mut rand_fixed = DefaultRand::new(0);
|
||||
let mut rand = DefaultRand::preseeded();
|
||||
assert_ne!(rand.next(), rand_fixed.next());
|
||||
assert_ne!(rand.next(), rand.next());
|
||||
assert!(rand.below(100) < 100);
|
||||
assert_eq!(rand.below(1), 0);
|
||||
assert_eq!(rand.between(10, 10), 10);
|
||||
assert!(rand.between(11, 20) > 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_rand() {
|
||||
let rand = DefaultRand::new(0).into();
|
||||
|
Loading…
x
Reference in New Issue
Block a user