Vendor asic-rs 0.8.1 (280 crates, offline builds) + wxWidgets 3.3.3 (pristine + patch queue); UI spec + ADR-0003; M1 on asic-rs
This commit is contained in:
Vendored
+64
@@ -0,0 +1,64 @@
|
||||
use arbitrary::{Arbitrary, Result, Unstructured};
|
||||
use std::ops::{
|
||||
Bound, Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo,
|
||||
RangeToInclusive,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum ArbRange<T> {
|
||||
Range(Range<T>),
|
||||
RangeFrom(RangeFrom<T>),
|
||||
RangeInclusive(RangeInclusive<T>),
|
||||
RangeTo(RangeTo<T>),
|
||||
RangeToInclusive(RangeToInclusive<T>),
|
||||
}
|
||||
|
||||
impl<T> RangeBounds<T> for ArbRange<T> {
|
||||
fn start_bound(&self) -> Bound<&T> {
|
||||
match self {
|
||||
ArbRange::Range(range) => range.start_bound(),
|
||||
ArbRange::RangeFrom(range) => range.start_bound(),
|
||||
ArbRange::RangeInclusive(range) => range.start_bound(),
|
||||
ArbRange::RangeTo(range) => range.start_bound(),
|
||||
ArbRange::RangeToInclusive(range) => range.start_bound(),
|
||||
}
|
||||
}
|
||||
|
||||
fn end_bound(&self) -> Bound<&T> {
|
||||
match self {
|
||||
ArbRange::Range(range) => range.end_bound(),
|
||||
ArbRange::RangeFrom(range) => range.end_bound(),
|
||||
ArbRange::RangeInclusive(range) => range.end_bound(),
|
||||
ArbRange::RangeTo(range) => range.end_bound(),
|
||||
ArbRange::RangeToInclusive(range) => range.end_bound(),
|
||||
}
|
||||
}
|
||||
|
||||
fn contains<U: ?Sized>(&self, item: &U) -> bool
|
||||
where
|
||||
T: PartialOrd<U>,
|
||||
U: PartialOrd<T>,
|
||||
{
|
||||
match self {
|
||||
ArbRange::Range(range) => range.contains(item),
|
||||
ArbRange::RangeFrom(range) => range.contains(item),
|
||||
ArbRange::RangeInclusive(range) => range.contains(item),
|
||||
ArbRange::RangeTo(range) => range.contains(item),
|
||||
ArbRange::RangeToInclusive(range) => range.contains(item),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Arbitrary> Arbitrary for ArbRange<T> {
|
||||
fn arbitrary(u: &mut Unstructured) -> Result<Self> {
|
||||
let variant = u8::arbitrary(u)? % 5;
|
||||
Ok(match variant {
|
||||
0 => ArbRange::Range(T::arbitrary(u)?..T::arbitrary(u)?),
|
||||
1 => ArbRange::RangeFrom(T::arbitrary(u)?..),
|
||||
2 => ArbRange::RangeInclusive(T::arbitrary(u)?..=T::arbitrary(u)?),
|
||||
3 => ArbRange::RangeTo(..T::arbitrary(u)?),
|
||||
4 => ArbRange::RangeToInclusive(..=T::arbitrary(u)?),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
use honggfuzz::fuzz;
|
||||
use rutenspitz::arbitrary_stateful_operations;
|
||||
use std::{fmt::Debug, iter::FromIterator, ops::RangeBounds};
|
||||
|
||||
use tinyvec::ArrayVec;
|
||||
use tinyvec_fuzz::ArbRange;
|
||||
|
||||
const CAPACITY: usize = 32;
|
||||
|
||||
arbitrary_stateful_operations! {
|
||||
model = Vec<T>,
|
||||
tested = ArrayVec<[T; CAPACITY]>,
|
||||
|
||||
type_parameters = <
|
||||
T: Default + Clone + Debug + Eq + Ord,
|
||||
R: RangeBounds<usize> + Clone + Debug,
|
||||
>,
|
||||
|
||||
methods {
|
||||
equal {
|
||||
fn as_mut_slice(&mut self) -> &mut [T];
|
||||
fn as_slice(&self) -> &[T];
|
||||
fn clear(&mut self);
|
||||
fn dedup(&mut self);
|
||||
fn extend_from_slice(&mut self, sli: &Box<[T]>);
|
||||
fn insert(&mut self, index: usize, item: T);
|
||||
fn is_empty(&self) -> bool;
|
||||
fn is_full(&self) -> bool;
|
||||
fn len(&self) -> usize;
|
||||
fn pop(&mut self) -> Option<T>;
|
||||
fn push(&mut self, item: T);
|
||||
fn remove(&mut self, index: usize) -> T;
|
||||
fn resize(&mut self, new_len: usize, new_val: T);
|
||||
fn swap_remove(&mut self, index: usize) -> T;
|
||||
fn truncate(&mut self, new_len: usize);
|
||||
}
|
||||
|
||||
equal_with(Vec::from_iter) {
|
||||
fn split_off(&mut self, at: usize) -> impl IntoIterator<Item = T>;
|
||||
fn drain(&self, range: R) -> impl Iterator<Item = T>;
|
||||
fn iter(&self) -> impl Iterator<Item = &T>;
|
||||
fn iter_mut(&self) -> impl Iterator<Item = &mut T>;
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
match self {
|
||||
// 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::extend_from_slice { sli } if model.len().saturating_add(sli.len()) > CAPACITY => {
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
let mut ring = Unstructured::new(&data);
|
||||
|
||||
let mut model = Vec::<u16>::default();
|
||||
let mut tested: ArrayVec<[u16; CAPACITY]> = ArrayVec::new();
|
||||
|
||||
let mut _op_trace = String::new();
|
||||
while let Ok(op) =
|
||||
<op::Op<u16, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring)
|
||||
{
|
||||
#[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);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
better_panic::install();
|
||||
|
||||
loop {
|
||||
fuzz!(|data: &[u8]| {
|
||||
let _ = fuzz_cycle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
use honggfuzz::fuzz;
|
||||
use rutenspitz::arbitrary_stateful_operations;
|
||||
use std::{convert::TryInto, fmt::Debug};
|
||||
|
||||
use tinyvec::{ArrayVec, ArrayVecDrain};
|
||||
use tinyvec_fuzz::ArbRange;
|
||||
|
||||
const CAPACITY: usize = 28;
|
||||
|
||||
arbitrary_stateful_operations! {
|
||||
model = std::vec::Drain<'_, u32>,
|
||||
tested = ArrayVecDrain<'_, u32>,
|
||||
|
||||
methods {
|
||||
equal {
|
||||
fn next(&mut self) -> Option<u32>;
|
||||
fn nth(&mut self, n: usize) -> Option<u32>;
|
||||
fn next_back(&mut self) -> Option<u32>;
|
||||
fn nth_back(&mut self, n: usize) -> Option<u32>;
|
||||
fn size_hint(&self) -> (usize, Option<usize>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn xorshift(x: u32) -> u32 {
|
||||
let x = x ^ (x << 13);
|
||||
let x = x ^ (x >> 17);
|
||||
let x = x ^ (x << 5);
|
||||
return x;
|
||||
}
|
||||
|
||||
fn seed(data: &[u8]) -> u32 {
|
||||
let mut rng = [1u8; 4];
|
||||
let len = if data.len() > 4 { 4 } else { data.len() };
|
||||
rng[..len].copy_from_slice(&data[..len]);
|
||||
u32::from_ne_bytes(rng)
|
||||
}
|
||||
|
||||
fn rand_arrvec(mut x: u32) -> ArrayVec<[u32; CAPACITY]> {
|
||||
let mut tested: ArrayVec<[u32; CAPACITY]> = ArrayVec::new();
|
||||
let len = xorshift(x) as usize % CAPACITY;
|
||||
tested.set_len(len);
|
||||
|
||||
for item in tested.iter_mut() {
|
||||
x = xorshift(x);
|
||||
*item = x;
|
||||
}
|
||||
|
||||
return tested;
|
||||
}
|
||||
|
||||
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
let mut ring = Unstructured::new(&data);
|
||||
|
||||
let rng = seed(data);
|
||||
let mut tested = rand_arrvec(rng);
|
||||
let mut model: Vec<u32> = Vec::from(tested.as_slice());
|
||||
|
||||
let mut tested = tested.drain(..);
|
||||
let mut model = model.drain(..);
|
||||
|
||||
while let Ok(op) = op::Op::arbitrary(&mut ring) {
|
||||
op.execute_and_compare(&mut model, &mut tested);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
better_panic::install();
|
||||
|
||||
loop {
|
||||
fuzz!(|data: &[u8]| {
|
||||
let _ = fuzz_cycle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
use honggfuzz::fuzz;
|
||||
use rutenspitz::{arbitrary_stateful_operations, OutcomePanic};
|
||||
use std::{convert::TryInto, fmt::Debug};
|
||||
|
||||
use tinyvec::{ArrayVec, ArrayVecIterator};
|
||||
use tinyvec_fuzz::ArbRange;
|
||||
|
||||
const CAPACITY: usize = 28;
|
||||
|
||||
arbitrary_stateful_operations! {
|
||||
model = std::vec::IntoIter<u32>,
|
||||
tested = ArrayVecIterator<[u32; CAPACITY]>,
|
||||
|
||||
methods {
|
||||
equal {
|
||||
fn next(&mut self) -> Option<u32>;
|
||||
fn nth(&mut self, n: usize) -> Option<u32>;
|
||||
fn next_back(&mut self) -> Option<u32>;
|
||||
fn nth_back(&mut self, n: usize) -> Option<u32>;
|
||||
fn size_hint(&self) -> (usize, Option<usize>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn xorshift(x: u32) -> u32 {
|
||||
let x = x ^ (x << 13);
|
||||
let x = x ^ (x >> 17);
|
||||
let x = x ^ (x << 5);
|
||||
return x;
|
||||
}
|
||||
|
||||
fn seed(data: &[u8]) -> u32 {
|
||||
let mut rng = [1u8; 4];
|
||||
let len = if data.len() > 4 { 4 } else { data.len() };
|
||||
rng[..len].copy_from_slice(&data[..len]);
|
||||
u32::from_ne_bytes(rng)
|
||||
}
|
||||
|
||||
fn rand_arrvec(mut x: u32) -> ArrayVec<[u32; CAPACITY]> {
|
||||
let mut tested: ArrayVec<[u32; CAPACITY]> = ArrayVec::new();
|
||||
let len = xorshift(x) as usize % CAPACITY;
|
||||
tested.set_len(len);
|
||||
|
||||
for item in tested.iter_mut() {
|
||||
x = xorshift(x);
|
||||
*item = x;
|
||||
}
|
||||
|
||||
return tested;
|
||||
}
|
||||
|
||||
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
let mut ring = Unstructured::new(&data);
|
||||
|
||||
let rng = seed(data);
|
||||
let tested = rand_arrvec(rng);
|
||||
let model: Vec<u32> = Vec::from(tested.as_slice());
|
||||
|
||||
let mut tested = tested.into_iter();
|
||||
let mut model = model.into_iter();
|
||||
|
||||
while let Ok(op) = op::Op::arbitrary(&mut ring) {
|
||||
#[cfg(fuzzing_debug)]
|
||||
eprintln!("{:?}", op);
|
||||
op.execute_and_compare(&mut model, &mut tested);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
//better_panic::install();
|
||||
std::panic::set_hook(Box::new(|panic_info| {
|
||||
if let Some(outpanic) =
|
||||
panic_info.payload().downcast_ref::<rutenspitz::OutcomePanic>()
|
||||
{
|
||||
eprintln!("{}", outpanic.0);
|
||||
std::process::abort();
|
||||
}
|
||||
}));
|
||||
|
||||
loop {
|
||||
fuzz!(|data: &[u8]| {
|
||||
let _ = fuzz_cycle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
use honggfuzz::fuzz;
|
||||
use rutenspitz::arbitrary_stateful_operations;
|
||||
use std::{fmt::Debug, iter::FromIterator, ops::RangeBounds};
|
||||
|
||||
use tinyvec::SliceVec;
|
||||
use tinyvec_fuzz::ArbRange;
|
||||
|
||||
arbitrary_stateful_operations! {
|
||||
model = Vec<T>,
|
||||
tested = SliceVec<'_, T>,
|
||||
|
||||
type_parameters = <
|
||||
T: Default + Clone + Debug + Eq + Ord,
|
||||
R: RangeBounds<usize> + Clone + Debug,
|
||||
>,
|
||||
|
||||
methods {
|
||||
equal {
|
||||
fn as_mut_slice(&mut self) -> &mut [T];
|
||||
fn as_slice(&self) -> &[T];
|
||||
fn clear(&mut self);
|
||||
//fn dedup(&mut self);
|
||||
fn extend_from_slice(&mut self, sli: &Box<[T]>);
|
||||
fn insert(&mut self, index: usize, item: T);
|
||||
fn is_empty(&self) -> bool;
|
||||
fn is_full(&self) -> bool;
|
||||
fn len(&self) -> usize;
|
||||
fn pop(&mut self) -> Option<T>;
|
||||
fn push(&mut self, item: T);
|
||||
fn remove(&mut self, index: usize) -> T;
|
||||
fn resize(&mut self, new_len: usize, new_val: T);
|
||||
fn swap_remove(&mut self, index: usize) -> T;
|
||||
fn truncate(&mut self, new_len: usize);
|
||||
}
|
||||
|
||||
equal_with(Vec::from_iter) {
|
||||
//fn split_off(&mut self, at: usize) -> impl IntoIterator<Item = T>;
|
||||
fn drain(&self, range: R) -> impl Iterator<Item = T>;
|
||||
fn iter(&self) -> impl Iterator<Item = &T>;
|
||||
fn iter_mut(&self) -> impl Iterator<Item = &mut T>;
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
match self {
|
||||
// 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() == model.capacity() => {
|
||||
return;
|
||||
}
|
||||
Self::resize { new_len, .. } if new_len > model.capacity() => {
|
||||
return;
|
||||
}
|
||||
Self::extend_from_slice { sli } if model.len().saturating_add(sli.len()) > model.capacity() => {
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn xorshift(x: u32) -> u32 {
|
||||
let x = x ^ (x << 13);
|
||||
let x = x ^ (x >> 17);
|
||||
let x = x ^ (x << 5);
|
||||
return x;
|
||||
}
|
||||
|
||||
fn seed(data: &[u8]) -> u32 {
|
||||
let mut rng = [1u8; 4];
|
||||
let len = if data.len() > 4 { 4 } else { data.len() };
|
||||
rng[..len].copy_from_slice(&data[..len]);
|
||||
u32::from_ne_bytes(rng)
|
||||
}
|
||||
|
||||
fn rand_array(mut x: u32) -> [u32; 32] {
|
||||
let mut tested = [0u32; 32];
|
||||
|
||||
for item in tested.iter_mut() {
|
||||
x = xorshift(x);
|
||||
*item = x;
|
||||
}
|
||||
|
||||
return tested;
|
||||
}
|
||||
|
||||
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
let mut ring = Unstructured::new(&data);
|
||||
|
||||
let mut array = rand_array(seed(data));
|
||||
let mut model = array.to_vec();
|
||||
let mut tested = SliceVec::from(&mut array);
|
||||
|
||||
while let Ok(op) =
|
||||
<op::Op<u32, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring)
|
||||
{
|
||||
#[cfg(fuzzing_debug)]
|
||||
eprintln!("{:?}", op);
|
||||
op.execute_and_compare(&mut model, &mut tested);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
std::panic::set_hook(Box::new(|panic_info| {
|
||||
if let Some(outpanic) =
|
||||
panic_info.payload().downcast_ref::<rutenspitz::OutcomePanic>()
|
||||
{
|
||||
eprintln!("{}", outpanic.0);
|
||||
std::process::abort();
|
||||
}
|
||||
}));
|
||||
|
||||
loop {
|
||||
fuzz!(|data: &[u8]| {
|
||||
let _ = fuzz_cycle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
use honggfuzz::fuzz;
|
||||
use rutenspitz::arbitrary_stateful_operations;
|
||||
use std::{fmt::Debug, iter::FromIterator, ops::RangeBounds};
|
||||
|
||||
use tinyvec::TinyVec;
|
||||
use tinyvec_fuzz::ArbRange;
|
||||
|
||||
const CAPACITY: usize = 32;
|
||||
|
||||
arbitrary_stateful_operations! {
|
||||
model = Vec<T>,
|
||||
tested = TinyVec<[T; CAPACITY]>,
|
||||
|
||||
type_parameters = <
|
||||
T: Default + Clone + Debug + Eq + Ord,
|
||||
R: RangeBounds<usize> + Clone + Debug,
|
||||
>,
|
||||
|
||||
methods {
|
||||
equal {
|
||||
fn as_mut_slice(&mut self) -> &mut [T];
|
||||
fn as_slice(&self) -> &[T];
|
||||
fn clear(&mut self);
|
||||
fn dedup(&mut self);
|
||||
fn extend_from_slice(&mut self, sli: &Box<[T]>);
|
||||
fn insert(&mut self, index: usize, item: T);
|
||||
fn is_empty(&self) -> bool;
|
||||
fn len(&self) -> usize;
|
||||
fn pop(&mut self) -> Option<T>;
|
||||
fn push(&mut self, item: T);
|
||||
fn remove(&mut self, index: usize) -> T;
|
||||
fn reserve(&mut self, n: usize);
|
||||
fn reserve_exact(&mut self, n: usize);
|
||||
fn resize(&mut self, new_len: usize, new_val: T);
|
||||
fn shrink_to_fit(&mut self);
|
||||
fn swap_remove(&mut self, index: usize) -> T;
|
||||
fn truncate(&mut self, new_len: usize);
|
||||
}
|
||||
|
||||
equal_with(Vec::from_iter) {
|
||||
fn split_off(&mut self, at: usize) -> impl IntoIterator<Item = T>;
|
||||
fn drain(&self, range: R) -> impl Iterator<Item = T>;
|
||||
fn iter(&self) -> impl Iterator<Item = &T>;
|
||||
fn iter_mut(&self) -> impl Iterator<Item = &mut T>;
|
||||
}
|
||||
}
|
||||
|
||||
pre {
|
||||
match self {
|
||||
// Arbitrary limit to avoid allocating too large a buffer
|
||||
Self::resize { new_len, .. } if new_len > 4 * CAPACITY => {
|
||||
return;
|
||||
},
|
||||
Self::reserve { n } if model.capacity().saturating_add(n) > 4 * CAPACITY => {
|
||||
return;
|
||||
},
|
||||
Self::reserve_exact { n } if model.capacity().saturating_add(n) > 4 * CAPACITY => {
|
||||
return;
|
||||
},
|
||||
Self::extend_from_slice { sli } if model.len().saturating_add(sli.len()) > 4 * CAPACITY => {
|
||||
return;
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
let mut ring = Unstructured::new(&data);
|
||||
|
||||
let mut model = Vec::<u16>::default();
|
||||
let mut tested: TinyVec<[u16; CAPACITY]> = TinyVec::new();
|
||||
|
||||
let mut _op_trace = String::new();
|
||||
while let Ok(op) =
|
||||
<op::Op<u16, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring)
|
||||
{
|
||||
#[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);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
better_panic::install();
|
||||
|
||||
loop {
|
||||
fuzz!(|data: &[u8]| {
|
||||
let _ = fuzz_cycle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
use honggfuzz::fuzz;
|
||||
use rutenspitz::arbitrary_stateful_operations;
|
||||
use std::{convert::TryInto, fmt::Debug};
|
||||
|
||||
use tinyvec::{TinyVec, TinyVecDrain};
|
||||
use tinyvec_fuzz::ArbRange;
|
||||
|
||||
const CAPACITY: usize = 28;
|
||||
|
||||
arbitrary_stateful_operations! {
|
||||
model = std::vec::Drain<'_, u32>,
|
||||
tested = TinyVecDrain<'_, [u32; CAPACITY]>,
|
||||
|
||||
methods {
|
||||
equal {
|
||||
fn next(&mut self) -> Option<u32>;
|
||||
fn nth(&mut self, n: usize) -> Option<u32>;
|
||||
fn next_back(&mut self) -> Option<u32>;
|
||||
fn nth_back(&mut self, n: usize) -> Option<u32>;
|
||||
fn size_hint(&self) -> (usize, Option<usize>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn xorshift(x: u32) -> u32 {
|
||||
let x = x ^ (x << 13);
|
||||
let x = x ^ (x >> 17);
|
||||
let x = x ^ (x << 5);
|
||||
return x;
|
||||
}
|
||||
|
||||
fn seed(data: &[u8]) -> u32 {
|
||||
let mut rng = [1u8; 4];
|
||||
let len = if data.len() > 4 { 4 } else { data.len() };
|
||||
rng[..len].copy_from_slice(&data[..len]);
|
||||
u32::from_ne_bytes(rng)
|
||||
}
|
||||
|
||||
fn rand_tinyvec(mut x: u32) -> TinyVec<[u32; CAPACITY]> {
|
||||
let mut tested: TinyVec<[u32; CAPACITY]> = Default::default();
|
||||
let len = xorshift(x) as u8; /* Effectively modulo 256 */
|
||||
|
||||
for _ in 0..len {
|
||||
x = xorshift(x);
|
||||
tested.push(x);
|
||||
}
|
||||
|
||||
return tested;
|
||||
}
|
||||
|
||||
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
|
||||
let mut ring = Unstructured::new(&data);
|
||||
|
||||
let rng = seed(data);
|
||||
let mut tested = rand_tinyvec(rng);
|
||||
let mut model: Vec<u32> = Vec::from(tested.as_slice());
|
||||
|
||||
let mut tested = tested.drain(..);
|
||||
let mut model = model.drain(..);
|
||||
|
||||
while let Ok(op) = op::Op::arbitrary(&mut ring) {
|
||||
op.execute_and_compare(&mut model, &mut tested);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ()> {
|
||||
better_panic::install();
|
||||
|
||||
loop {
|
||||
fuzz!(|data: &[u8]| {
|
||||
let _ = fuzz_cycle(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
mod arb_range;
|
||||
|
||||
pub use arb_range::ArbRange;
|
||||
Reference in New Issue
Block a user