| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
use std::path::Path; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
fn decode(bytes: &[u8]) -> Option<(u64, u64)> { |
| 31 |
if bytes.len() < 16 { |
| 32 |
return None; |
| 33 |
} |
| 34 |
let total = u64::from_le_bytes(bytes[0..8].try_into().ok()?); |
| 35 |
let part = u64::from_le_bytes(bytes[8..16].try_into().ok()?); |
| 36 |
Some((total, part)) |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
fn replay(dir: &Path) -> usize { |
| 44 |
let Ok(entries) = std::fs::read_dir(dir) else { |
| 45 |
return 0; |
| 46 |
}; |
| 47 |
|
| 48 |
let mut count = 0; |
| 49 |
for entry in entries { |
| 50 |
let path = entry.expect("readable dir entry").path(); |
| 51 |
if !path.is_file() { |
| 52 |
continue; |
| 53 |
} |
| 54 |
|
| 55 |
if path.extension().is_some_and(|e| e == "md") { |
| 56 |
continue; |
| 57 |
} |
| 58 |
let bytes = std::fs::read(&path).expect("readable input"); |
| 59 |
let Some((total_size, raw_part)) = decode(&bytes) else { |
| 60 |
continue; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
let outcome = std::panic::catch_unwind(|| { |
| 66 |
s3_storage::oracle::check_plan(total_size, raw_part as usize); |
| 67 |
const MIN_PART: u64 = 5 * 1024 * 1024; |
| 68 |
const MAX_PART: u64 = 5 * 1024 * 1024 * 1024; |
| 69 |
let shaped = MIN_PART + (raw_part % (MAX_PART - MIN_PART + 1)); |
| 70 |
s3_storage::oracle::check_plan(total_size, shaped as usize); |
| 71 |
s3_storage::oracle::check_auto(total_size); |
| 72 |
}); |
| 73 |
assert!( |
| 74 |
outcome.is_ok(), |
| 75 |
"oracle failed on {} (total_size {total_size}, part_size {raw_part})", |
| 76 |
path.display() |
| 77 |
); |
| 78 |
count += 1; |
| 79 |
} |
| 80 |
count |
| 81 |
} |
| 82 |
|
| 83 |
#[test] |
| 84 |
fn plan_seeds_satisfy_the_oracle() { |
| 85 |
let n = replay( |
| 86 |
Path::new(env!("CARGO_MANIFEST_DIR")) |
| 87 |
.join("fuzz/seeds/plan") |
| 88 |
.as_path(), |
| 89 |
); |
| 90 |
assert!(n > 0, "no plan seeds found; the corpus is the point"); |
| 91 |
println!("replayed {n} seeds"); |
| 92 |
} |
| 93 |
|
| 94 |
#[test] |
| 95 |
fn every_past_crash_stays_fixed() { |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
let n = replay( |
| 100 |
Path::new(env!("CARGO_MANIFEST_DIR")) |
| 101 |
.join("fuzz/regressions") |
| 102 |
.as_path(), |
| 103 |
); |
| 104 |
println!("replayed {n} regression inputs"); |
| 105 |
} |
| 106 |
|