From 447e5e0e5916f87c3d54986772c8f47055b255bc Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Wed, 3 Mar 2021 17:17:47 +0100 Subject: [PATCH] fixed queuecorpus test --- libafl/src/corpus/queue.rs | 53 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/libafl/src/corpus/queue.rs b/libafl/src/corpus/queue.rs index 3bd3727ff8..3edb0f0833 100644 --- a/libafl/src/corpus/queue.rs +++ b/libafl/src/corpus/queue.rs @@ -70,48 +70,51 @@ where } } -/* #[cfg(test)] #[cfg(feature = "std")] mod tests { - use std::path::PathBuf; + use std::{fs, path::PathBuf}; use crate::{ - corpus::{Corpus, OnDiskCorpus, QueueCorpus, Testcase}, + corpus::{Corpus, CorpusScheduler, OnDiskCorpus, QueueCorpusScheduler, Testcase}, inputs::bytes::BytesInput, + state::{HasCorpus, State}, utils::StdRand, }; #[test] fn test_queuecorpus() { - let mut rand = StdRand::new(0); - let mut q = QueueCorpus::new(OnDiskCorpus::::new(PathBuf::from( - "fancy/path", - ))); - let t = Testcase::with_filename(BytesInput::new(vec![0 as u8; 4]), "fancyfile".into()); - q.add(t); - let filename = q - .next(&mut rand) + let rand = StdRand::with_seed(4); + let scheduler = QueueCorpusScheduler::new(); + + let mut q = + OnDiskCorpus::::new(PathBuf::from("target/.test/fancy/path")).unwrap(); + let t = Testcase::with_filename( + BytesInput::new(vec![0 as u8; 4]), + "target/.test/fancy/path/fancyfile".into(), + ); + q.add(t).unwrap(); + + let objective_q = + OnDiskCorpus::::new(PathBuf::from("target/.test/fancy/objective/path")) + .unwrap(); + + let mut state = State::new(rand, q, (), objective_q, ()); + + let next_idx = scheduler.next(&mut state).unwrap(); + let filename = state + .corpus() + .get(next_idx) .unwrap() - .0 .borrow() .filename() .as_ref() .unwrap() .to_owned(); - assert_eq!( - filename, - q.next(&mut rand) - .unwrap() - .0 - .borrow() - .filename() - .as_ref() - .unwrap() - .to_owned() - ); - assert_eq!(filename, "fancyfile"); + + assert_eq!(filename, "target/.test/fancy/path/fancyfile"); + + fs::remove_dir_all("target/.test/fancy").unwrap(); } } -*/