Fuzz: drop workarounds for operations that may panic (#92)

Fuzz: drop workarounds for operations that may panic now that rutenspitz compares panic behavior
This commit is contained in:
Sergey "Shnatsel" Davidoff
2020-07-29 15:40:12 +02:00
committed by GitHub
parent 7e57ee3a07
commit 12054cc899
3 changed files with 11 additions and 55 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ publish = false
[dependencies]
tinyvec = { path = "..", features = ["alloc", "nightly_slice_partition_dedup"] }
rutenspitz = "0.2"
rutenspitz = "0.2.1"
honggfuzz = "0.5.45"
arbitrary = { version = "0.4.5", features = ["derive"] }
better-panic = "0.2.0"
+7 -27
View File
@@ -2,7 +2,7 @@ use honggfuzz::fuzz;
use std::{
fmt::Debug,
iter::FromIterator,
ops::{Bound, RangeBounds},
ops::RangeBounds,
};
use rutenspitz::arbitrary_stateful_operations;
@@ -47,37 +47,16 @@ arbitrary_stateful_operations! {
pre {
match self {
Self::insert { index, .. } | Self::split_off { at: index } if index > model.len() => {
// TODO: Should test that these identically panic
return;
}
Self::remove { index } | Self::swap_remove { index } if index >= model.len() => {
// TODO: Should test that these identically panic
return;
}
// We are comparing ArrayVec with a limited capacity against
// Vec to which you can push indefinitely. This is a behavior mismatch.
// To compensate we skip adding any elements if it would exceed capacity.
Self::insert { .. } | Self::push { .. } if model.len() == CAPACITY => {
return;
}
Self::resize { new_len, .. } if new_len > CAPACITY => {
return;
}
Self::drain { ref range } => {
// TODO: Should test that these identically panic
let start = match range.start_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n + 1,
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
// If it's already usize::max, doesn't really matter about adding 1
Bound::Included(&n) => n.checked_add(1).unwrap_or(n),
Bound::Excluded(&n) => n,
Bound::Unbounded => model.len(),
};
if start > end || end > model.len() {
return;
}
}
_ => {}
}
}
@@ -89,7 +68,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
let mut ring = Unstructured::new(&data);
let mut model = Vec::<u16>::default();
let mut tested: ArrayVec<[u16; 32]> = ArrayVec::new();
let mut tested: ArrayVec<[u16; CAPACITY]> = ArrayVec::new();
let mut _op_trace = String::new();
while let Ok(op) =
@@ -97,6 +76,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
{
#[cfg(fuzzing_debug)]
_op_trace.push_str(&format!("{}\n", op.to_string()));
// println!("Operations trace:\n{}", _op_trace);
op.execute_and_compare(&mut model, &mut tested);
}
+3 -27
View File
@@ -2,7 +2,7 @@ use honggfuzz::fuzz;
use std::{
fmt::Debug,
iter::FromIterator,
ops::{Bound, RangeBounds},
ops::RangeBounds,
};
use rutenspitz::arbitrary_stateful_operations;
@@ -47,35 +47,10 @@ arbitrary_stateful_operations! {
pre {
match self {
Self::insert { index, .. } | Self::split_off { at: index } if index > model.len() => {
// TODO: Should test that these identically panic
return;
}
Self::remove { index } | Self::swap_remove { index } if index >= model.len() => {
// TODO: Should test that these identically panic
return;
}
// Arbitrary limit to avoid allocating too large a buffer
Self::resize { new_len, .. } if new_len > 4 * CAPACITY => {
return;
}
Self::drain { ref range } => {
// TODO: Should test that these identically panic
let start = match range.start_bound() {
Bound::Included(&n) => n,
Bound::Excluded(&n) => n + 1,
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
// If it's already usize::max, doesn't really matter about adding 1
Bound::Included(&n) => n.checked_add(1).unwrap_or(n),
Bound::Excluded(&n) => n,
Bound::Unbounded => model.len(),
};
if start > end || end > model.len() {
return;
}
}
_ => {}
}
}
@@ -87,7 +62,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
let mut ring = Unstructured::new(&data);
let mut model = Vec::<u16>::default();
let mut tested: TinyVec<[u16; 32]> = TinyVec::new();
let mut tested: TinyVec<[u16; CAPACITY]> = TinyVec::new();
let mut _op_trace = String::new();
while let Ok(op) =
@@ -95,6 +70,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
{
#[cfg(fuzzing_debug)]
_op_trace.push_str(&format!("{}\n", op.to_string()));
// println!("Operations trace:\n{}", _op_trace);
op.execute_and_compare(&mut model, &mut tested);
}