Skip to content

Commit eb451e5

Browse files
committed
reenabled testcases
1 parent 447e5e0 commit eb451e5

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

libafl/src/mutators/scheduled.rs

+35-31
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ where
270270
}
271271
}
272272

273-
/*
274273
#[cfg(test)]
275274
mod tests {
276275
use crate::{
@@ -287,28 +286,23 @@ mod tests {
287286
#[test]
288287
fn test_mut_scheduled() {
289288
// With the current impl, seed of 1 will result in a split at pos 2.
290-
let mut rand = XKCDRand::new();
291-
let mut corpus: InMemoryCorpus<BytesInput, _> = InMemoryCorpus::new();
292-
corpus.add(Testcase::new(vec!['a' as u8, 'b' as u8, 'c' as u8]).into());
293-
corpus.add(Testcase::new(vec!['d' as u8, 'e' as u8, 'f' as u8]).into());
294-
295-
let (testcase, _) = corpus
296-
.next(&mut rand)
297-
.expect("Corpus did not contain entries");
289+
let mut rand = XKCDRand::with_seed(5);
290+
let mut corpus: InMemoryCorpus<BytesInput> = InMemoryCorpus::new();
291+
corpus
292+
.add(Testcase::new(vec!['a' as u8, 'b' as u8, 'c' as u8]).into())
293+
.unwrap();
294+
corpus
295+
.add(Testcase::new(vec!['d' as u8, 'e' as u8, 'f' as u8]).into())
296+
.unwrap();
297+
298+
let testcase = corpus.get(0).expect("Corpus did not contain entries");
298299
let mut input = testcase.borrow_mut().load_input().unwrap().clone();
299300

300-
let mut state = State::new(corpus, (), InMemoryCorpus::new(), ());
301+
let mut state = State::new(rand, corpus, (), InMemoryCorpus::new(), ());
301302

302303
rand.set_seed(5);
303304

304-
let mut mutator = StdScheduledMutator::<
305-
InMemoryCorpus<BytesInput, XKCDRand>,
306-
_,
307-
_,
308-
State<_, (), _, InMemoryCorpus<BytesInput, XKCDRand>, (), _>,
309-
>::new();
310-
311-
mutation_splice(&mut mutator, &mut rand, &mut state, &mut input).unwrap();
305+
mutation_splice(&mut state, &mut input).unwrap();
312306

313307
#[cfg(feature = "std")]
314308
println!("{:?}", input.bytes());
@@ -321,27 +315,37 @@ mod tests {
321315
#[test]
322316
fn test_havoc() {
323317
// With the current impl, seed of 1 will result in a split at pos 2.
324-
let mut rand = StdRand::new(0x1337);
325-
let mut corpus: InMemoryCorpus<BytesInput, StdRand> = InMemoryCorpus::new();
326-
corpus.add(Testcase::new(vec!['a' as u8, 'b' as u8, 'c' as u8]).into());
327-
corpus.add(Testcase::new(vec!['d' as u8, 'e' as u8, 'f' as u8]).into());
328-
329-
let (testcase, _) = corpus
330-
.next(&mut rand)
331-
.expect("Corpus did not contain entries");
318+
let rand = StdRand::with_seed(0x1337);
319+
let mut corpus: InMemoryCorpus<BytesInput> = InMemoryCorpus::new();
320+
corpus
321+
.add(Testcase::new(vec!['a' as u8, 'b' as u8, 'c' as u8]).into())
322+
.unwrap();
323+
corpus
324+
.add(Testcase::new(vec!['d' as u8, 'e' as u8, 'f' as u8]).into())
325+
.unwrap();
326+
327+
let testcase = corpus.get(0).expect("Corpus did not contain entries");
332328
let mut input = testcase.borrow_mut().load_input().unwrap().clone();
333329
let input_prior = input.clone();
334330

335-
let mut state = State::new(corpus, (), InMemoryCorpus::new(), ());
331+
let mut state = State::new(rand, corpus, (), InMemoryCorpus::new(), ());
336332

337-
let mut havoc = HavocBytesMutator::new(StdScheduledMutator::new());
333+
let havoc = HavocBytesMutator::new(StdScheduledMutator::new());
338334

339335
assert_eq!(input, input_prior);
340336

337+
let mut equal_in_a_row = 0;
338+
341339
for i in 0..42 {
342-
havoc.mutate(&mut rand, &mut state, &mut input, i).unwrap();
343-
assert_ne!(input, input_prior);
340+
havoc.mutate(&mut state, &mut input, i).unwrap();
341+
342+
// Make sure we actually mutate something, at least sometimes
343+
equal_in_a_row = if input == input_prior {
344+
equal_in_a_row + 1
345+
} else {
346+
0
347+
};
348+
assert_ne!(equal_in_a_row, 5);
344349
}
345350
}
346351
}
347-
*/

0 commit comments

Comments
 (0)