| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
use std::path::{Path, PathBuf}; |
| 20 |
|
| 21 |
fn dir(rel: &str) -> PathBuf { |
| 22 |
Path::new(env!("CARGO_MANIFEST_DIR")).join(rel) |
| 23 |
} |
| 24 |
|
| 25 |
fn replay(dir: &Path) -> usize { |
| 26 |
let Ok(entries) = std::fs::read_dir(dir) else { |
| 27 |
return 0; |
| 28 |
}; |
| 29 |
|
| 30 |
let mut count = 0; |
| 31 |
for entry in entries { |
| 32 |
let path = entry.expect("readable dir entry").path(); |
| 33 |
if !path.is_file() { |
| 34 |
continue; |
| 35 |
} |
| 36 |
if path.extension().is_some_and(|e| e == "md") { |
| 37 |
continue; |
| 38 |
} |
| 39 |
let bytes = std::fs::read(&path).expect("readable input"); |
| 40 |
let outcome = std::panic::catch_unwind(|| kittygfx::oracle::check_bodies(&bytes)); |
| 41 |
assert!(outcome.is_ok(), "oracle failed on {}", path.display()); |
| 42 |
count += 1; |
| 43 |
} |
| 44 |
count |
| 45 |
} |
| 46 |
|
| 47 |
#[test] |
| 48 |
fn every_seed_holds_the_oracle() { |
| 49 |
let n = replay(&dir("fuzz/seeds/apc")); |
| 50 |
|
| 51 |
|
| 52 |
assert!( |
| 53 |
n >= 30, |
| 54 |
"expected the committed seed corpus, found {n} inputs" |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
#[test] |
| 59 |
fn every_regression_holds_the_oracle() { |
| 60 |
|
| 61 |
|
| 62 |
replay(&dir("fuzz/regressions")); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
#[test] |
| 67 |
fn the_oracle_feeds_the_bodies_it_is_given() { |
| 68 |
let input = b"\x1b_Ga=q,f=24,t=d,i=3;AAAA\x1b\\\x1b_Ga=d,d=A\x1b\\"; |
| 69 |
assert_eq!(kittygfx::oracle::check_bodies(input), 2); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
#[test] |
| 80 |
fn unbounded_transmission_growth_stays_capped() { |
| 81 |
|
| 82 |
|
| 83 |
let mut many = Vec::new(); |
| 84 |
for i in 0..200_000u32 { |
| 85 |
many.extend_from_slice(format!("\x1b_Ga=T,f=32,i={i},m=1;QUJD\x1b\\").as_bytes()); |
| 86 |
} |
| 87 |
kittygfx::oracle::check_bodies(&many); |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
let chunk = "A".repeat(4096); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
let bodies = (kittygfx::MAX_IN_FLIGHT_BYTES / 3072) * 5 / 2; |
| 96 |
let mut one = Vec::new(); |
| 97 |
for _ in 0..bodies { |
| 98 |
one.extend_from_slice(format!("\x1b_Ga=T,f=32,i=1,m=1;{chunk}\x1b\\").as_bytes()); |
| 99 |
} |
| 100 |
kittygfx::oracle::check_bodies(&one); |
| 101 |
} |
| 102 |
|