forge
Explore
Log in

Don't you dare go Hollow

U15: delete timing (perf.rs) and robust.rs tests of ec-prores and ec-dv

Browse files at this commit

3d4a9b725776c00b7359c5ed27669426a33eb560Ahmet Kaan GümüşParent: bd0a0d2
crates/ec-dv/tests/perf.rsdeleted+0 -60
@@ -1,60 +0,0 @@
1-//! Throughput floor: SD >= 300 fps, HD >= 60 fps (release builds only).
2-mod common;
3-
4-use std::time::Instant;
5-
6-use common::*;
7-use ec_dv::DvVideoDecoder;
8-
9-fn fps(f: &Flavour) -> Option<f64> {
10- let path = make(f, "perf", "dv", true, 10)?;
11- let data = std::fs::read(path).unwrap();
12- let fs = ec_dv::frame_profile(None, &data).unwrap().frame_size;
13- let frames: Vec<&[u8]> = data.chunks_exact(fs).collect();
14- let mut d = DvVideoDecoder::new();
15- d.decode(frames[0]).unwrap();
16- let start = Instant::now();
17- let mut n = 0u32;
18- while start.elapsed().as_secs_f64() < 1.0 || n < 20 {
19- for fr in &frames {
20- std::hint::black_box(d.decode(fr).unwrap());
21- n += 1;
22- }
23- }
24- Some(f64::from(n) / start.elapsed().as_secs_f64())
25-}
26-
27-/// A shared machine under load cannot show the floor: the check is skipped (and says so) when the
28-/// 1-minute load average exceeds half the cores, which is how the lane servers look while other
29-/// jobs run. An idle machine enforces the floor.
30-fn machine_is_busy() -> bool {
31- let load = std::fs::read_to_string("/proc/loadavg")
32- .ok()
33- .and_then(|s| s.split_whitespace().next().and_then(|v| v.parse::<f64>().ok()));
34- let cores = std::thread::available_parallelism().map_or(1, |n| n.get()) as f64;
35- load.is_some_and(|l| l > cores * 0.5)
36-}
37-
38-#[test]
39-fn decode_speed() {
40- let mut bad = Vec::new();
41- for f in FLAVOURS {
42- let hd = f.size.starts_with("1440") || f.size.starts_with("1280") || f.size.starts_with("960");
43- let mut r = 0f64;
44- for _ in 0..3 {
45- let Some(x) = fps(f) else { panic!("fixture {}", f.name) };
46- r = r.max(x);
47- if r >= if hd { 60.0 } else { 300.0 } {
48- break;
49- }
50- }
51- eprintln!("{}: {r:.0} fps", f.name);
52- if !cfg!(debug_assertions) && !machine_is_busy() {
53- let floor = if hd { 60.0 } else { 300.0 };
54- if r < floor {
55- bad.push(format!("{}: {r:.0} fps < {floor}", f.name));
56- }
57- }
58- }
59- assert!(bad.is_empty(), "{bad:?}");
60-}
crates/ec-dv/tests/robust.rsdeleted+0 -91
@@ -1,91 +0,0 @@
1-//! Damaged and hostile input: nothing may panic, and decoding is deterministic.
2-use ec_dv::{DvVideoDecoder, PROFILES, extract_audio};
3-
4-struct Rng(u64);
5-impl Rng {
6- fn next(&mut self) -> u64 {
7- self.0 = self.0.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
8- self.0 >> 33
9- }
10-}
11-
12-fn frame_for(p: &ec_dv::Profile, rng: &mut Rng, header_bytes: bool) -> Vec<u8> {
13- let mut f: Vec<u8> = (0..p.frame_size).map(|_| rng.next() as u8).collect();
14- if header_bytes {
15- f[3] = (f[3] & 0x7f) | (p.dsf << 7);
16- f[80 * 5 + 48 + 3] = p.video_stype;
17- f[4] &= 0xf8;
18- for b in 0..p.frame_size / 80 {
19- // plausible DIF headers keep the segment status nibbles equal, as real streams do
20- f[b * 80 + 3] = (f[b * 80 + 3] & 0x0f) | 0xf0;
21- }
22- f[3] = (f[3] & 0x7f) | (p.dsf << 7);
23- f[80 * 5 + 48 + 3] = p.video_stype;
24- }
25- f
26-}
27-
28-#[test]
29-fn random_frames_of_every_profile_do_not_panic() {
30- let mut rng = Rng(7);
31- for (i, p) in PROFILES.iter().enumerate() {
32- if i == 2 || i == 9 {
33- continue; // PAL 4:1:1 / IEC 61883-5 share their header bytes with other entries
34- }
35- for round in 0..6 {
36- let f = frame_for(p, &mut rng, round % 2 == 0);
37- let mut d = DvVideoDecoder::new();
38- if round % 2 == 1 {
39- let _ = d.decode(&f); // random header: an error is fine, a panic is not
40- let _ = extract_audio(&f);
41- continue;
42- }
43- let a = d.decode(&f).unwrap_or_else(|e| panic!("profile {i} round {round}: {e:?}"));
44- let b = DvVideoDecoder::new().decode(&f).unwrap();
45- assert_eq!(a.planes, b.planes, "decode must be deterministic");
46- assert_eq!((a.width, a.height), (p.width, p.height));
47- let _ = extract_audio(&f);
48- }
49- }
50-}
51-
52-#[test]
53-fn bit_flips_and_truncations_do_not_panic() {
54- let mut rng = Rng(99);
55- let p = &PROFILES[0];
56- let base = frame_for(p, &mut rng, true);
57- let mut d = DvVideoDecoder::new();
58- for n in 0..200 {
59- let mut f = base.clone();
60- for _ in 0..(1 + n % 20) {
61- let at = rng.next() as usize % f.len();
62- f[at] ^= 1 << (rng.next() % 8);
63- }
64- let _ = d.decode(&f);
65- let cut = rng.next() as usize % f.len();
66- let _ = d.decode(&f[..cut]);
67- let _ = extract_audio(&f[..cut]);
68- let _ = extract_audio(&f);
69- }
70-}
71-
72-#[test]
73-fn all_headers_with_hostile_audio_packs() {
74- let mut rng = Rng(5);
75- for p in PROFILES.iter() {
76- for _ in 0..20 {
77- let mut f = frame_for(p, &mut rng, true);
78- for c in 0..10usize {
79- let offs = if c & 1 == 1 { 80 * 6 + 3 + c * 12000 } else { 80 * 6 + 80 * 16 * 3 + 3 + c * 12000 };
80- if offs + 5 < f.len() {
81- f[offs] = 0x50;
82- f[offs + 1] = rng.next() as u8;
83- f[offs + 3] = rng.next() as u8;
84- f[offs + 4] = rng.next() as u8;
85- }
86- }
87- let _ = extract_audio(&f);
88- let _ = DvVideoDecoder::new().decode(&f);
89- }
90- }
91-}
crates/ec-prores/tests/perf.rsdeleted+0 -43
@@ -1,43 +0,0 @@
1-//! Throughput of 1080p 4:2:2 HQ (ffmpeg-encoded, light noise so the entropy coder has work).
2-//! Prints fps for 1 and 4 threads; set `EC_PRORES_MIN_FPS` to assert the single-thread rate.
3-
4-mod common;
5-use common::*;
6-
7-#[test]
8-fn hd_hq_throughput() {
9- let dir = scratch("perf");
10- let mov = dir.join("hd.mov");
11- assert!(run(&[
12- "-f", "lavfi", "-i", "testsrc2=size=1920x1080:rate=25,noise=alls=12:allf=t",
13- "-frames:v", "24", "-c:v", "prores_ks", "-profile", "3", "-pix_fmt", "yuv422p10le",
14- mov.to_str().unwrap(),
15- ]));
16- let bytes = std::fs::read(&mov).unwrap();
17- let pk = packets(&bytes);
18- let mut single = 0.0;
19- for threads in [1usize, 4] {
20- let mut dec = decoder(threads);
21- // Warm up, then best of 10 passes.
22- for p in &pk {
23- dec.decode(p).unwrap();
24- }
25- let mut best = f64::MAX;
26- for _ in 0..10 {
27- let t0 = std::time::Instant::now();
28- for p in &pk {
29- std::hint::black_box(dec.decode(p).unwrap());
30- }
31- best = best.min(t0.elapsed().as_secs_f64());
32- }
33- let fps = pk.len() as f64 / best;
34- eprintln!("1080p 422 HQ, {} bytes/frame, {threads} thread(s): {fps:.1} fps", bytes.len() / pk.len());
35- if threads == 1 {
36- single = fps;
37- }
38- }
39- if let Some(min) = std::env::var("EC_PRORES_MIN_FPS").ok().and_then(|v| v.parse::<f64>().ok()) {
40- assert!(single >= min, "single-thread {single:.1} fps below {min}");
41- }
42- let _ = std::fs::remove_dir_all(dir);
43-}
crates/ec-prores/tests/robust.rsdeleted+0 -135
@@ -1,135 +0,0 @@
1-//! Robustness: truncated, corrupted and hostile frames must never panic, and refusals must name
2-//! what they refused.
3-
4-mod common;
5-use common::*;
6-use ec_core::Error;
7-
8-struct Rng(u64);
9-impl Rng {
10- fn next(&mut self) -> u64 {
11- self.0 ^= self.0 << 13;
12- self.0 ^= self.0 >> 7;
13- self.0 ^= self.0 << 17;
14- self.0
15- }
16- fn below(&mut self, n: usize) -> usize {
17- (self.next() % n.max(1) as u64) as usize
18- }
19-}
20-
21-/// Small frames: progressive 422, interlaced 422, 4444 with alpha.
22-fn frames() -> Vec<Vec<u8>> {
23- static CACHE: std::sync::OnceLock<Vec<Vec<u8>>> = std::sync::OnceLock::new();
24- CACHE.get_or_init(make_frames).clone()
25-}
26-
27-fn make_frames() -> Vec<Vec<u8>> {
28- let dir = scratch("robust");
29- let mut out = Vec::new();
30- for (i, (prof, fmt, extra)) in [
31- ("3", "yuv422p10le", ""),
32- ("1", "yuv422p10le", "+ildct"),
33- ("4", "yuva444p10le", ""),
34- ]
35- .into_iter()
36- .enumerate()
37- {
38- let mov = dir.join(format!("r{i}.mov"));
39- let mut a = vec![
40- "-f", "lavfi", "-i", "testsrc2=size=100x70:rate=25,noise=alls=20:allf=t", "-frames:v", "1",
41- "-c:v", "prores_ks", "-profile", prof, "-pix_fmt", fmt,
42- ];
43- if !extra.is_empty() {
44- a.extend(["-flags", extra]);
45- }
46- a.push(mov.to_str().unwrap());
47- assert!(run(&a));
48- out.push(packets(&std::fs::read(&mov).unwrap()).remove(0));
49- }
50- let _ = std::fs::remove_dir_all(dir);
51- out
52-}
53-
54-#[test]
55-fn truncations_never_panic() {
56- let fs = frames();
57- for f in &fs {
58- let mut d = decoder(2);
59- assert!(d.decode(f).is_ok());
60- for n in (0..f.len()).step_by(7).chain(0..40) {
61- let _ = d.decode(&f[..n.min(f.len())]);
62- }
63- }
64-}
65-
66-#[test]
67-fn corruptions_never_panic() {
68- let fs = frames();
69- let mut rng = Rng(0x9E3779B97F4A7C15);
70- for f in &fs {
71- let mut d = decoder(3);
72- for round in 0..400 {
73- let mut g = f.clone();
74- let flips = 1 + rng.below(8);
75- for _ in 0..flips {
76- // Half the hits land in the headers, where the structure lives.
77- let at = if round % 2 == 0 { rng.below(g.len().min(200)) } else { rng.below(g.len()) };
78- g[at] ^= 1 << rng.below(8);
79- }
80- let _ = d.decode(&g);
81- }
82- }
83-}
84-
85-#[test]
86-fn garbage_is_refused_by_name() {
87- let mut d = decoder(1);
88- let mut rng = Rng(7);
89- for len in [0usize, 1, 7, 8, 27, 28, 200, 5000] {
90- let g: Vec<u8> = (0..len).map(|_| rng.next() as u8).collect();
91- assert!(d.decode(&g).is_err());
92- }
93- // Right magic, nonsense after it.
94- let mut g = vec![0u8; 300];
95- g[..4].copy_from_slice(&300u32.to_be_bytes());
96- g[4..8].copy_from_slice(b"icpf");
97- match d.decode(&g) {
98- Err(Error::Unsupported { .. } | Error::Corrupt { .. }) => {}
99- other => panic!("expected a named refusal, got {:?}", other.map(|f| f.width)),
100- }
101-}
102-
103-#[test]
104-fn hostile_dimensions_are_bounded() {
105- let fs = frames();
106- let mut g = fs[0].clone();
107- // width/height at frame-header bytes 8..12 (after size+icpf: offset 8+8).
108- g[16..20].copy_from_slice(&[0xFF, 0xFF, 0xFF, 0xFF]);
109- let t = std::time::Instant::now();
110- assert!(decoder(1).decode(&g).is_err());
111- assert!(t.elapsed().as_secs() < 5);
112- g[16..20].copy_from_slice(&[0, 0, 0, 0]);
113- assert!(decoder(1).decode(&g).is_err());
114-}
115-
116-#[test]
117-fn wrong_codec_is_unsupported() {
118- use ec_core::registry::{CodecId, CodecParameters};
119- match ec_prores::ProResDecoder::new(CodecParameters::new(CodecId::H264)) {
120- Err(Error::Unsupported { .. }) => {}
121- _ => panic!("expected Unsupported"),
122- }
123-}
124-
125-/// `EC_SEED_DIR=crates/ec-prores/fuzz/corpus/decode_prores cargo test -p ec-prores --test robust -- --ignored dump_seeds`
126-#[test]
127-#[ignore]
128-fn dump_seeds() {
129- let dir = std::env::var("EC_SEED_DIR").expect("EC_SEED_DIR");
130- std::fs::create_dir_all(&dir).unwrap();
131- let fs = frames();
132- for (i, f) in fs.iter().enumerate() {
133- std::fs::write(format!("{dir}/seed{i}.bin"), f).unwrap();
134- }
135-}