Skip to content

Commit

Permalink
Cover more ops with repairs
Browse files Browse the repository at this point in the history
  • Loading branch information
diondokter committed Dec 29, 2023
1 parent ccbb670 commit 66280c0
Showing 1 changed file with 60 additions and 7 deletions.
67 changes: 60 additions & 7 deletions fuzz/fuzz_targets/queue_with_shutoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,26 @@ fn fuzz(ops: Input) {
Op::Push(op) => {
let val: Vec<u8> = (0..op.value_len as usize % 16).map(|_| rng.gen()).collect();

let max_fit =
sequential_storage::queue::find_max_fit(&mut flash, FLASH_RANGE).unwrap();
let max_fit = match sequential_storage::queue::find_max_fit(
&mut flash,
FLASH_RANGE,
) {
Ok(val) => val,
Err(Error::Corrupted {
backtrace: _backtrace,
}) if !corruption_repaired => {
#[cfg(fuzzing_repro)]
eprintln!(
"### Encountered curruption while finding max fit! Repairing now. Originated from:\n{_backtrace:#}"
);

sequential_storage::queue::try_repair(&mut flash, FLASH_RANGE).unwrap();
corruption_repaired = true;
retry = true;
continue;
}
Err(e) => panic!("Error while finding max fit: {e:?}"),
};

match sequential_storage::queue::push(&mut flash, FLASH_RANGE, &val, false) {
Ok(_) => {
Expand Down Expand Up @@ -157,8 +175,26 @@ fn fuzz(ops: Input) {
}
}
Op::PopMany(n) => {
let mut popper =
sequential_storage::queue::pop_many(&mut flash, FLASH_RANGE).unwrap();
let mut popper = match sequential_storage::queue::pop_many(
&mut flash,
FLASH_RANGE,
) {
Ok(val) => val,
Err(Error::Corrupted {
backtrace: _backtrace,
}) if !corruption_repaired => {
#[cfg(fuzzing_repro)]
eprintln!(
"### Encountered curruption while creating popper! Repairing now. Originated from:\n{_backtrace:#}"
);

sequential_storage::queue::try_repair(&mut flash, FLASH_RANGE).unwrap();
corruption_repaired = true;
retry = true;
continue;
}
Err(e) => panic!("Error while creating popper: {e:?}"),
};

for i in 0..*n {
match popper.next(&mut buf) {
Expand Down Expand Up @@ -208,7 +244,6 @@ fn fuzz(ops: Input) {
}
}
}

Op::Peek => {
match sequential_storage::queue::peek(&mut flash, FLASH_RANGE, &mut buf) {
Ok(value) => {
Expand All @@ -233,8 +268,26 @@ fn fuzz(ops: Input) {
}
}
Op::PeekMany(n) => {
let mut peeker =
sequential_storage::queue::peek_many(&mut flash, FLASH_RANGE).unwrap();
let mut peeker = match sequential_storage::queue::peek_many(
&mut flash,
FLASH_RANGE,
) {
Ok(val) => val,
Err(Error::Corrupted {
backtrace: _backtrace,
}) if !corruption_repaired => {
#[cfg(fuzzing_repro)]
eprintln!(
"### Encountered curruption while creating peeker! Repairing now. Originated from:\n{_backtrace:#}"
);

sequential_storage::queue::try_repair(&mut flash, FLASH_RANGE).unwrap();
corruption_repaired = true;
retry = true;
continue;
}
Err(e) => panic!("Error while creating peeker: {e:?}"),
};

for i in 0..*n {
match peeker.next(&mut buf) {
Expand Down

0 comments on commit 66280c0

Please sign in to comment.