From 07bb8ae18305a45d4b2649d2dcb0fd2a81d4d5f6 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Wed, 28 Oct 2020 22:45:21 +0100 Subject: [PATCH] fixed warnings, added testcase --- src/corpus/mod.rs | 4 ++-- src/executors/mod.rs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/corpus/mod.rs b/src/corpus/mod.rs index 6bd144b373..f14c936bce 100644 --- a/src/corpus/mod.rs +++ b/src/corpus/mod.rs @@ -147,7 +147,7 @@ impl QueueCorpus<'_, RandT> { } #[derive(Debug, Default)] -struct SimpleTestcase { +pub struct SimpleTestcase { is_on_disk: bool, filename: String, metadatas: HashMap>, @@ -173,7 +173,7 @@ impl Testcase for SimpleTestcase { } impl SimpleTestcase { - fn new(filename: &str) -> Self { + pub fn new(filename: &str) -> Self { SimpleTestcase { filename: filename.to_owned(), is_on_disk: false, diff --git a/src/executors/mod.rs b/src/executors/mod.rs index 1a5fff341d..c6b792a4a0 100644 --- a/src/executors/mod.rs +++ b/src/executors/mod.rs @@ -119,7 +119,6 @@ use unix_signals as os_signals; compile_error!("InMemoryExecutor not yet supported on this OS"); impl Executor for InMemoryExecutor { - fn run_target(&mut self) -> Result { let bytes = match self.base.cur_input.as_ref() { Some(i) => i.serialize(), @@ -165,7 +164,7 @@ impl Executor for InMemoryExecutor { } impl InMemoryExecutor { - fn new(harness_fn: HarnessFunction) -> InMemoryExecutor { + pub fn new(harness_fn: HarnessFunction) -> InMemoryExecutor { InMemoryExecutor { base: ExecutorBase { observers: vec![], @@ -180,8 +179,18 @@ impl InMemoryExecutor { mod tests { use crate::executors::{Executor, ExitKind, InMemoryExecutor}; use crate::observers::Observer; + use crate::inputs::Input; use crate::AflError; + struct NopInput {} + impl Input for NopInput{ + fn serialize(&self) -> Result<&[u8], AflError> {Ok("NOP".as_bytes())} + fn deserialize(&mut self, _buf: &[u8]) -> Result<(), AflError> { + Ok(()) + } + } + + struct Nopserver {} impl Observer for Nopserver { @@ -209,8 +218,8 @@ mod tests { #[test] fn test_inmem_exec() { let mut in_mem_executor = InMemoryExecutor::new(test_harness_fn_nop); - let nopserver = Nopserver {}; - in_mem_executor.add_observer(Box::new(nopserver)); - assert_eq!(in_mem_executor.post_exec_observers().is_err(), true); + let input = NopInput{}; + assert!(in_mem_executor.place_input(Box::new(input)).is_ok()); + assert!(in_mem_executor.run_target().is_ok()); } }