diff --git a/crates/ec-h265/tests/it/cu_syntax.rs b/crates/ec-h265/tests/it/cu_syntax.rs index bafcea3d..a8735482 100644 --- a/crates/ec-h265/tests/it/cu_syntax.rs +++ b/crates/ec-h265/tests/it/cu_syntax.rs @@ -1,14 +1,9 @@ -//! Syntax-only sweep of the JCT-VC conformance streams through the CU syntax -//! parser ([`ec_h265::dec::cu_syntax`]). Pixel decode is off; every slice of -//! every picture is parsed to `end_of_slice_segment_flag`. A slice is clean when -//! that flag lands on the last CTB and nothing refuses or desyncs. -//! -//! The per-stream table goes to stdout. With `EC_H265_SYNTAX_TABLE` set, the same -//! table is also written there as TSV. +//! CU syntax tests over the JCT-VC conformance streams: the P/B slice syntax with the +//! zero-motion stand-in (the sweep, pixel-pipeline and motion-determinism tests were removed by +//! testcut Phase 2). use ec_core::error::Error; -use ec_h265::dec::{Decoder, NalOutcome}; -use std::collections::BTreeMap; +use ec_h265::dec::Decoder; use std::path::{Path, PathBuf}; /// The conformance streams: the first `.bin` or `.bit` bitstream of each directory @@ -79,167 +74,6 @@ fn is_slice(nal: &[u8]) -> bool { t <= 9 || (16..=21).contains(&t) } -#[derive(Default)] -struct Row { - slices: usize, - clean: usize, - refused: BTreeMap, - desync: usize, - desync_first: String, - other: usize, - /// Parameter sets refused, by name (a slice then fails with "never received"). - param_refused: BTreeMap, -} - -fn sweep(path: &Path) -> Row { - let data = std::fs::read(path).expect("read bitstream"); - let mut dec = Decoder::new(); - dec.set_pixel_decode(false); - dec.set_syntax_check(true); - let mut row = Row::default(); - for nal in nal_units(&data) { - let slice = is_slice(nal); - match dec.push_nal(nal) { - Ok(NalOutcome::Slice) if slice => { - row.slices += 1; - row.clean += 1; - } - Ok(_) => {} - Err(err) => { - if !slice { - if let Error::Unsupported { what, .. } = err { - *row.param_refused.entry(what).or_default() += 1; - } - continue; - } - row.slices += 1; - match err { - Error::Unsupported { what, .. } => { - *row.refused.entry(what).or_default() += 1; - } - // A slice whose parameter set was refused by name: not a parse failure. - Error::Corrupt { context } if context.contains("never received") => { - *row.refused - .entry("parameter set refused (see above)".to_string()) - .or_default() += 1; - } - Error::Corrupt { context } => { - row.desync += 1; - if row.desync_first.is_empty() { - row.desync_first = context; - } - } - other => { - row.other += 1; - if row.desync_first.is_empty() { - row.desync_first = other.to_string(); - } - } - } - } - } - } - row -} - -#[test] -fn cu_syntax_sweep_over_conformance_streams() { - let streams = streams(); - if streams.is_empty() { - eprintln!("cu_syntax: no conformance streams found, skipping"); - return; - } - let mut table = String::from("stream\tslices\tclean\trefused\tdesync\tother\tnote\n"); - let (mut total_slices, mut total_clean, mut streams_clean, mut streams_all) = (0, 0, 0, 0); - for path in &streams { - let name = path - .file_stem() - .and_then(|s| s.to_str()) - .unwrap_or("?") - .to_string(); - let row = sweep(path); - let refused: usize = row.refused.values().sum(); - let refused_note: Vec = row - .refused - .iter() - .map(|(what, n)| format!("{what} x{n}")) - .collect(); - let mut parts = refused_note; - parts.extend( - row.param_refused - .iter() - .map(|(what, n)| format!("{what} x{n} (parameter set)")), - ); - let mut note = parts.join("; "); - if !row.desync_first.is_empty() { - if !note.is_empty() { - note.push_str("; "); - } - note.push_str(&row.desync_first); - } - table.push_str(&format!( - "{name}\t{}\t{}\t{refused}\t{}\t{}\t{note}\n", - row.slices, row.clean, row.desync, row.other - )); - total_slices += row.slices; - total_clean += row.clean; - streams_all += 1; - if row.slices > 0 && row.clean == row.slices { - streams_clean += 1; - } - } - print!("{table}"); - println!( - "cu_syntax: {streams_clean}/{streams_all} streams parse every slice clean; {total_clean}/{total_slices} slices clean" - ); - if let Ok(path) = std::env::var("EC_H265_SYNTAX_TABLE") { - std::fs::write(path, &table).expect("write syntax table"); - } -} - -/// The pixel pipeline over the same streams: pixel decode on, so intra slices go -/// through `decode_i_slice` and P/B slices through the placeholder inter path. -/// Prints one line per stream with the first error, if any. Samples are not -/// compared; this checks that the pipeline runs. -#[test] -fn pixel_pipeline_runs_over_conformance_streams() { - let streams = streams(); - if streams.is_empty() { - eprintln!("pixel pipeline: no conformance streams found, skipping"); - return; - } - let mut ok_streams = 0; - for path in &streams { - let name = path - .file_stem() - .and_then(|s| s.to_str()) - .unwrap_or("?") - .to_string(); - let data = std::fs::read(path).expect("read bitstream"); - let mut dec = Decoder::new(); - let mut first_err = String::new(); - for nal in nal_units(&data) { - if let Err(err) = dec.push_nal(nal) { - first_err = match err { - Error::Unsupported { what, .. } => format!("refused: {what}"), - other => other.to_string(), - }; - break; - } - } - if first_err.is_empty() && dec.flush().is_ok() { - ok_streams += 1; - println!("pixel\t{name}\tok"); - } else { - println!("pixel\t{name}\t{first_err}"); - } - } - println!( - "pixel pipeline: {ok_streams}/{} streams decode without error", - streams.len() - ); -} - /// The P/B slice syntax ([`ec_h265::dec::cu_syntax::parse_slice`] with the zero-motion /// stand-in, no DPB to derive motion from) over every P and B slice segment of every /// stream. Pixel decode is off so the decoder only keeps parameter sets. Refusals are @@ -303,47 +137,3 @@ fn inter_placeholder_runs_over_pb_slices() { "inter syntax: {decoded} P/B slices parsed, {refused} refused by name, of {pb_slices} first-slice P/B segments" ); } - -/// The motion derivation (merge, AMVP, temporal) runs through the syntax-only decode -/// of every stream. Two decodes of the same stream must give the same motion field -/// hash, and the derivation must not fail on any slice that parses cleanly. -#[test] -fn motion_derivation_is_deterministic_over_conformance_streams() { - let streams = streams(); - if streams.is_empty() { - eprintln!("motion determinism: no conformance streams found, skipping"); - return; - } - fn run(path: &Path) -> (u64, usize) { - let data = std::fs::read(path).expect("read bitstream"); - let mut dec = Decoder::new(); - dec.set_pixel_decode(false); - dec.set_syntax_check(true); - let mut failures = 0usize; - for nal in nal_units(&data) { - match dec.push_nal(nal) { - Ok(_) | Err(Error::Unsupported { .. }) => {} - // A slice whose parameter set was refused by name (see the sweep). - Err(Error::Corrupt { context }) if context.contains("never received") => {} - Err(_) => failures += 1, - } - } - let _ = dec.flush(); - (dec.motion_checksum(), failures) - } - let (mut streams_run, mut total_failures) = (0usize, 0usize); - for path in &streams { - let (first, failures) = run(path); - let (second, _) = run(path); - assert_eq!( - first, - second, - "{}: motion field differs between runs", - path.display() - ); - total_failures += failures; - streams_run += 1; - } - println!("motion determinism: {streams_run} streams, {total_failures} slice failures"); - assert_eq!(total_failures, 0, "slices failed while deriving motion"); -} diff --git a/lanes/testcut/p2-h265.md b/lanes/testcut/p2-h265.md new file mode 100644 index 00000000..762ee8f4 --- /dev/null +++ b/lanes/testcut/p2-h265.md @@ -0,0 +1,36 @@ +# testcut Phase 2: ec-h265 lane (testcut-p2-h265) + +Status: DONE (second attempt, host b, lanes `testcut-p2-h265-s1`, `-s2`). Deleted 3 tests, about 317 s of release runtime saved (per rest.tsv times: 143.0 + 54.7 + 119.2). ffmpeg_decodes_bit_exactly_at_every_shape was restored after the recheck below. + +## Method and why the first attempt was invalid +The earlier "kills" were timeouts: mutation runs used the debug profile, so the unmutated pixel run took 915 s against a 429 s timeout. This run uses `--release` everywhere, builds each mutant first (`--no-run`, separate build timeout), and sets the test timeout to 2.5 x the measured unmutated baseline of the same command on the same host (`run1.sh`, `fast.sh`, `mutrun.py`). Mutants are applied by index from `mutants.json`, 10 seeded (seed 2026) mutants per candidate from U(T) functions (noisy: functions T covers). A kill counts only if the test failed (rc=100, tests ran); timeouts do not count. Fast stage: `--profile fast --release`, fail-fast; unmutated fast baseline was 168 passed / 14 skipped, 0 failures, so nothing had to be excluded. Fixtures: `EC_REQUIRE_FIXTURES=1` everywhere; baselines passed with the test started. + +Validity checks: baseline logs show `PASS` for exactly the one test; SURVIVED rows have `rc=0 ran=1`; KILLED rows have `rc=100`. A parser bug (nextest prints `N/M tests run` on fail-fast failures, read as `ran=0` and NORUN) was found and fixed in `mutrun.py`; the fast stage was rerun after the fix. Leaked test processes from timed-out hang mutants (nextest children escape the killpg) raised b's load during the later stages; this can only turn kills into timeouts, never survivors into kills, and the affected rows are treated as not killed. They were killed by PID afterwards. + +## Protocol table +| crate | test | seconds | class | \|U(T)\| | mutants tried | \|S\| | \|KT\| | \|K\| | \|K'\| | decision | +|---|---|---|---|---|---|---|---|---|---|---| +| ec-h265 | pixel_pipeline_runs_over_conformance_streams | 142.99 | pseudo (prints only) | 223 | 10 | 10 | 0 | - | - | DELETED (kills nothing; baseline 48 s, timeout 125 s) | +| ec-h265 | cu_syntax_sweep_over_conformance_streams | 54.75 | pseudo (prints table only) | 171 | 10 | 9 | 1 (wpp.rs:494:27 `-` to `/`) | 0 | 0 | DELETED (the one kill is also killed by the fast suite) | +| ec-h265 | motion_derivation_is_deterministic_over_conformance_streams | 119.18 | candidate | 148 | 10 | 9 | 1 | 0 | 0 | DELETED (fast suite kills the T-kill) | +| ec-h265 | ffmpeg_decodes_bit_exactly_at_every_shape | 47.80 | candidate | 57 | 10 | 5 | 5 (2 failing, 3 hang-timeouts; hangs reconfirmed on a quiet host, load 0.9) | 1 (ctu.rs:429:13 `+` to `-` in code_quadtree: T hangs, fast suite also hangs, no real failure) | not run | KEEP (K'=1 unresolved; the other 4 T-kills are real fast-suite failures) | +| ec-h265 | noisy_near_black_lands_within_five_percent | 41.17 | candidate | 84 | 10 | 3 | 7 | 1 (ctu.rs:534:29 `+` to `-` in save_meta: T fails, fast suite hangs past 1200 s) | not run | KEEP (the only fast-suite outcome is a hang, not a failure; K' step not run) | +| ec-h265 | conformance_pictures_match_the_sei_hash | 85.08 | protected | | | | | | | protected | +| ec-h265 | rext_conformance_pictures_match_the_sei_hash | 83.30 | protected | | | | | | | protected | +| ec-h265 | conformance_output_order_matches_ffprobe | 133.71 | protected | | | | | | | protected | +| ec-h265 | speedup_curve | 114.86 | protected (perf) | | | | | | | protected | +| ec-h265 | ctb_32_is_the_faster_tree_at_1080p | 165.46 | protected (perf) | | | | | | | protected | +| ec-h265 | intra_1080p_beats_the_incumbent_on_twelve_threads | 451.04 | protected (perf) | | | | | | | protected | + +Release baselines measured on b: pixel 48 s, cu_syntax 21 s, noisy 39 s, motion 40 s, ffmpeg 23 s (the rest.tsv times are from a different run mix). Evidence is a 10-mutant sample per candidate, as the orchestrator allowed; it is thin for motion and cu_syntax (1 T-kill each). + +## Summary +1. Tests deleted: pixel_pipeline_runs_over_conformance_streams, cu_syntax_sweep_over_conformance_streams, motion_derivation_is_deterministic_over_conformance_streams (helpers `Row`, `sweep` and unused imports removed). +2. Seconds saved: about 317 s (rest.tsv times). +3. Kept with evidence: noisy_near_black_lands_within_five_percent (K=1, hang-only fast outcome) and ffmpeg_decodes_bit_exactly_at_every_shape (K'=1, hang-only). Protected: 6 tests. +4. Gate on b: `EC_REQUIRE_FIXTURES=1 cargo test --release -p ec-h265` all binaries ok (96 + 76 + 3 passed, 0 failed); `cargo clippy --release -p ec-h265 --tests -D warnings` clean; `#![forbid(unsafe_code)]` present in lib.rs. +5. `inter_placeholder_runs_over_pb_slices` was not heavy and is kept. +Tools: `lanes/testcut/p2h265-tools/{run1.sh,fast.sh,recheck.sh,gate.sh,mutrun.py}`. Per-mutant rows: `lanes/testcut/p2h265-evidence/res-*.tsv`. + +Note: samples were 10 mutants per candidate. Evidence for motion_derivation and cu_syntax_sweep is thin (1 T-kill each, both also killed by the fast suite). +Recheck (lane -s2, quiet host, load 0.9, T baseline 22 s, timeout 63 s): all 3 ffmpeg hang mutants still hang in T alone (real kills under the lane rules). Fast profile: residual.rs:609 and residual.rs:430 fail with rc=100 (killed); ctu.rs:429 hangs past 2.5 x the 54 s fast baseline (and past 1200 s earlier), so it is not killed by the fast suite. The test was restored byte-for-byte from before the deletion (conformance.rs), so the gate result above for the remaining code still applies. diff --git a/lanes/testcut/p2h265-evidence/res-B1-cu_syntax_sweep_over_conformance_streams.tsv b/lanes/testcut/p2h265-evidence/res-B1-cu_syntax_sweep_over_conformance_streams.tsv new file mode 100644 index 00000000..561cfa1d --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-B1-cu_syntax_sweep_over_conformance_streams.tsv @@ -0,0 +1,10 @@ +crates/ec-h265/src/dec/cu_syntax/wpp.rs:112:50: replace + with - in Board::prefill SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:494:27: replace - with / in parse_segment KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/dec/rowfilter.rs:52:28: replace >= with < in RowFilter::advance SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/rowfilter.rs:57:46: replace * with + in RowFilter::advance SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:110:41: replace * with / in Board::prefill SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:199:23: replace >> with << in Board::leave SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/shared.rs:173:34: replace >> with << in SharedPic::publish_rows SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/merge.rs:62:33: delete - in derive_merge SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/shared.rs:175:77: replace * with / in SharedPic::publish_rows SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/rowfilter.rs:91:26: replace + with - in RowFilter::sao_row SURVIVED rc=0 ran=1 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-B1-ffmpeg_decodes_bit_exactly_at_every_shape.tsv b/lanes/testcut/p2h265-evidence/res-B1-ffmpeg_decodes_bit_exactly_at_every_shape.tsv new file mode 100644 index 00000000..f6309ce3 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-B1-ffmpeg_decodes_bit_exactly_at_every_shape.tsv @@ -0,0 +1,10 @@ +crates/ec-h265/src/ctu.rs:1536:9: replace CtuEncoder<'a>::transform_luma_ts_rd -> (f64, bool) with (1.0, true) SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/deblock.rs:138:25: replace >> with << in luma_segment SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/intra.rs:400:43: replace + with * in predict_dc SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/intra.rs:437:30: replace * with / in predict_angular KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/ctu.rs:1429:23: delete - in CtuEncoder<'a>::choose_luma_mode SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/residual.rs:270:43: replace + with * in estimate_residual_bits SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/intra.rs:73:66: replace == with != in Availability::is_empty KILLED rc=100 ran=1 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-B1-motion_derivation_is_deterministic_over_conformance_streams.tsv b/lanes/testcut/p2h265-evidence/res-B1-motion_derivation_is_deterministic_over_conformance_streams.tsv new file mode 100644 index 00000000..d2b8a8da --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-B1-motion_derivation_is_deterministic_over_conformance_streams.tsv @@ -0,0 +1,10 @@ +crates/ec-h265/src/dec/cu_syntax/wpp.rs:112:50: replace + with - in Board::prefill SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:494:27: replace - with / in parse_segment KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/dec/rowfilter.rs:113:55: replace * with + in RowFilter::sao_row SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/rowfilter.rs:54:56: replace + with * in RowFilter::advance SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:110:41: replace * with / in Board::prefill SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:199:23: replace >> with << in Board::leave SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/runner.rs:128:9: replace Checksum::wait -> Option with None SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/merge.rs:62:33: delete - in derive_merge SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/shared.rs:175:26: replace * with + in SharedPic::publish_rows SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/rowfilter.rs:89:29: replace >> with << in RowFilter::sao_row SURVIVED rc=0 ran=1 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-B1-noisy_near_black_lands_within_five_percent.tsv b/lanes/testcut/p2h265-evidence/res-B1-noisy_near_black_lands_within_five_percent.tsv new file mode 100644 index 00000000..97989dc3 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-B1-noisy_near_black_lands_within_five_percent.tsv @@ -0,0 +1,10 @@ +crates/ec-h265/src/ctu.rs:534:29: replace + with - in CtuEncoder<'a>::save_meta KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/dec/pic.rs:330:9: replace PicState::available -> bool with true KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/enc_p.rs:666:74: replace > with < in PCoder<'a>::write_split SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/enc_p.rs:820:24: replace << with >> in PCoder<'a>::analyse KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/residual.rs:609:42: replace + with * in residual_header KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/ctu.rs:416:50: replace < with == in CtuEncoder<'a>::code_quadtree KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/dec/deblock.rs:253:59: replace + with - in luma_segment SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/intra.rs:460:49: replace & with ^ in predict_angular KILLED rc=100 ran=1 timeout=False +crates/ec-h265/src/residual.rs:112:19: replace += with *= in encode_remaining SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/encoder.rs:818:67: replace / with * in Encoder::code_picture_planes KILLED rc=100 ran=1 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-B1-pixel_pipeline_runs_over_conformance_streams.tsv b/lanes/testcut/p2h265-evidence/res-B1-pixel_pipeline_runs_over_conformance_streams.tsv new file mode 100644 index 00000000..10a8b909 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-B1-pixel_pipeline_runs_over_conformance_streams.tsv @@ -0,0 +1,10 @@ +crates/ec-h265/src/dec/cu_syntax.rs:424:62: replace != with == in parse_slice_into SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/deblock.rs:224:49: replace + with - in luma_segment SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/deblock.rs:376:25: replace - with / in chroma_pass SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/deblock.rs:394:84: replace >> with << in chroma_pass SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/sao.rs:166:56: replace << with >> in filter_ctb_rows SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax.rs:412:28: replace || with && in parse_slice_into SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/cu_syntax/wpp.rs:627:39: replace << with >> in parse_segment SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/picjob.rs:163:35: replace + with * in PicJob::run_slice SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/sao.rs:125:25: replace + with - in filter_ctb_rows SURVIVED rc=0 ran=1 timeout=False +crates/ec-h265/src/dec/merge.rs:38:32: replace > with == in derive_merge SURVIVED rc=0 ran=1 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-F-cu_syntax_sweep_over_conformance_streams.tsv b/lanes/testcut/p2h265-evidence/res-F-cu_syntax_sweep_over_conformance_streams.tsv new file mode 100644 index 00000000..ce5ea42b --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-F-cu_syntax_sweep_over_conformance_streams.tsv @@ -0,0 +1 @@ +crates/ec-h265/src/dec/cu_syntax/wpp.rs:494:27: replace - with / in parse_segment KILLED rc=100 ran=132 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-F-ffmpeg_decodes_bit_exactly_at_every_shape.tsv b/lanes/testcut/p2h265-evidence/res-F-ffmpeg_decodes_bit_exactly_at_every_shape.tsv new file mode 100644 index 00000000..8486b003 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-F-ffmpeg_decodes_bit_exactly_at_every_shape.tsv @@ -0,0 +1,5 @@ +crates/ec-h265/src/intra.rs:437:30: replace * with / in predict_angular KILLED rc=100 ran=75 timeout=False +crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header KILLED rc=100 ran=80 timeout=False +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq KILLED rc=100 ran=86 timeout=False +crates/ec-h265/src/intra.rs:73:66: replace == with != in Availability::is_empty KILLED rc=100 ran=78 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-F-motion_derivation_is_deterministic_over_conformance_streams.tsv b/lanes/testcut/p2h265-evidence/res-F-motion_derivation_is_deterministic_over_conformance_streams.tsv new file mode 100644 index 00000000..ce5ea42b --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-F-motion_derivation_is_deterministic_over_conformance_streams.tsv @@ -0,0 +1 @@ +crates/ec-h265/src/dec/cu_syntax/wpp.rs:494:27: replace - with / in parse_segment KILLED rc=100 ran=132 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-F-noisy_near_black_lands_within_five_percent.tsv b/lanes/testcut/p2h265-evidence/res-F-noisy_near_black_lands_within_five_percent.tsv new file mode 100644 index 00000000..ca215349 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-F-noisy_near_black_lands_within_five_percent.tsv @@ -0,0 +1,7 @@ +crates/ec-h265/src/ctu.rs:534:29: replace + with - in CtuEncoder<'a>::save_meta KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/dec/pic.rs:330:9: replace PicState::available -> bool with true KILLED rc=100 ran=113 timeout=False +crates/ec-h265/src/enc_p.rs:820:24: replace << with >> in PCoder<'a>::analyse KILLED rc=100 ran=134 timeout=False +crates/ec-h265/src/residual.rs:609:42: replace + with * in residual_header KILLED rc=100 ran=80 timeout=False +crates/ec-h265/src/ctu.rs:416:50: replace < with == in CtuEncoder<'a>::code_quadtree KILLED rc=100 ran=99 timeout=False +crates/ec-h265/src/intra.rs:460:49: replace & with ^ in predict_angular KILLED rc=100 ran=75 timeout=False +crates/ec-h265/src/encoder.rs:818:67: replace / with * in Encoder::code_picture_planes KILLED rc=100 ran=97 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-R2-F.tsv b/lanes/testcut/p2h265-evidence/res-R2-F.tsv new file mode 100644 index 00000000..d2a21b0e --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-R2-F.tsv @@ -0,0 +1,3 @@ +crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header KILLED rc=100 ran=81 timeout=False +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq KILLED rc=100 ran=86 timeout=False diff --git a/lanes/testcut/p2h265-evidence/res-R2-T.tsv b/lanes/testcut/p2h265-evidence/res-R2-T.tsv new file mode 100644 index 00000000..5a9c20f2 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-R2-T.tsv @@ -0,0 +1,3 @@ +crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True +crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq KILLED rc=-1 ran=0 timeout=True diff --git a/lanes/testcut/p2h265-evidence/res-rc-f-T.tsv b/lanes/testcut/p2h265-evidence/res-rc-f-T.tsv new file mode 100644 index 00000000..1ff65730 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-rc-f-T.tsv @@ -0,0 +1 @@ +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True diff --git a/lanes/testcut/p2h265-evidence/res-rc-f-fast.tsv b/lanes/testcut/p2h265-evidence/res-rc-f-fast.tsv new file mode 100644 index 00000000..1ff65730 --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-rc-f-fast.tsv @@ -0,0 +1 @@ +crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree KILLED rc=-1 ran=0 timeout=True diff --git a/lanes/testcut/p2h265-evidence/res-rc-n-fast.tsv b/lanes/testcut/p2h265-evidence/res-rc-n-fast.tsv new file mode 100644 index 00000000..30ac6e1e --- /dev/null +++ b/lanes/testcut/p2h265-evidence/res-rc-n-fast.tsv @@ -0,0 +1 @@ +crates/ec-h265/src/ctu.rs:534:29: replace + with - in CtuEncoder<'a>::save_meta KILLED rc=-1 ran=0 timeout=True diff --git a/lanes/testcut/p2h265-tools/analyze-all.sh b/lanes/testcut/p2h265-tools/analyze-all.sh new file mode 100755 index 00000000..75b469e2 --- /dev/null +++ b/lanes/testcut/p2h265-tools/analyze-all.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -uo pipefail +OUT=$HOME/lanes/testcut-p2-h265-c1/out +TOOLS=$PWD/lanes/testcut/p2h265-tools +NAMES="pixel_pipeline_runs_over_conformance_streams motion_derivation_is_deterministic_over_conformance_streams cu_syntax_sweep_over_conformance_streams ffmpeg_decodes_bit_exactly_at_every_shape noisy_near_black_lands_within_five_percent" +python3 "$TOOLS/analyze.py" "$OUT" $NAMES +cargo mutants -p ec-h265 --list --json > "$OUT/mutants.json" 2> "$OUT/mutants.list.err" +echo "mutants listed: $(python3 -c 'import json,sys;print(len(json.load(open(sys.argv[1]))))' "$OUT/mutants.json")" +for t in $NAMES; do python3 "$TOOLS/sample.py" "$OUT" "$t" 60; done diff --git a/lanes/testcut/p2h265-tools/analyze.py b/lanes/testcut/p2h265-tools/analyze.py new file mode 100644 index 00000000..f2355fd8 --- /dev/null +++ b/lanes/testcut/p2h265-tools/analyze.py @@ -0,0 +1,27 @@ +import json, sys, collections +out, names = sys.argv[1], sys.argv[2:] +def load(n): + return json.load(open(f"{out}/{n}.json"))["data"][0] +def regions(data): + s = {} + for fn in data["functions"]: + for r in fn["regions"]: + fname = fn["filenames"][r[5]] + key = (fn["name"], fname, r[0], r[1], r[2], r[3], r[7]) + s[key] = max(s.get(key, 0), r[4]) + return s +fast = load("fast") +fr = regions(fast) +fast_cov = {k for k, v in fr.items() if v > 0} +res = {} +for n in names: + d = load(n) + r = regions(d) + cov = {k for k, v in r.items() if v > 0} + u = cov - fast_cov + fns = collections.Counter() + for k in u: + fi = k[1].find("ec-h265/"); fns[(k[1][fi + 8:] if fi >= 0 else None, k[0])] += 1 + res[n] = {"covered": len(cov), "U": len(u), "U_functions": [[f, fn, c] for (f, fn), c in fns.items() if f]} + print(n, "covered", len(cov), "U", len(u), "funcs", len(fns)) +json.dump({"fast_regions": len(fast_cov), "per_test": res}, open(f"{out}/coverage-summary.json", "w")) diff --git a/lanes/testcut/p2h265-tools/bc_all.sh b/lanes/testcut/p2h265-tools/bc_all.sh new file mode 100644 index 00000000..d8538efd --- /dev/null +++ b/lanes/testcut/p2h265-tools/bc_all.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Run B (T only) and run C (remaining heavy tests) per candidate, in decreasing runtime order. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +OUT=$HOME/lanes/testcut-p2-h265-c1/out +TOOLS=$PWD/lanes/testcut/p2h265-tools +ALLHEAVY="pixel_pipeline_runs_over_conformance_streams motion_derivation_is_deterministic_over_conformance_streams cu_syntax_sweep_over_conformance_streams ffmpeg_decodes_bit_exactly_at_every_shape noisy_near_black_lands_within_five_percent conformance_pictures_match_the_sei_hash rext_conformance_pictures_match_the_sei_hash conformance_output_order_matches_ffprobe speedup_curve ctb_32_is_the_faster_tree_at_1080p intra_1080p_beats_the_incumbent_on_twelve_threads" +CANDS="pixel_pipeline_runs_over_conformance_streams motion_derivation_is_deterministic_over_conformance_streams cu_syntax_sweep_over_conformance_streams ffmpeg_decodes_bit_exactly_at_every_shape noisy_near_black_lands_within_five_percent" +PSEUDO=" pixel_pipeline_runs_over_conformance_streams cu_syntax_sweep_over_conformance_streams " +DELETED="" +expr() { local out=""; for n in "$@"; do out="${out:+$out | }test(/(^|::)$n\$/)"; done; echo "$out"; } +for T in $CANDS; do + python3 -c 'import json,sys; sm=set(json.load(open(sys.argv[1]))); S=set(l.rstrip("\n") for l in open(sys.argv[2]) if l.strip()); print("\n".join(sorted(sm & S)))' "$OUT/sample-$T.json" "$OUT/A.S.txt" > "$OUT/$T.SA.txt" + SN=$(wc -l < "$OUT/$T.SA.txt") + echo "== $T S=$SN" + if [ "$SN" -eq 0 ]; then echo "DECIDE $T K=0 S=0 -> delete"; DELETED="$DELETED $T"; continue; fi + RES=$(python3 -c 'import re,sys; print("|".join(re.escape(l.rstrip("\n")) for l in open(sys.argv[1]) if l.strip()))' "$OUT/$T.SA.txt") + cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$RES" --cargo-test-arg=-E --cargo-test-arg="$(expr $T)" -o "$OUT/$T.B" > "$OUT/$T.B.log" 2>&1 + python3 "$TOOLS/outcomes.py" "$OUT/$T.B/mutants.out/outcomes.json" killed > "$OUT/$T.K.txt" + KN=$(wc -l < "$OUT/$T.K.txt") + echo "$T K=$KN" + if [ "$KN" -eq 0 ]; then echo "DECIDE $T K=0 -> delete"; DELETED="$DELETED $T"; continue; fi + if [[ "$PSEUDO" == *" $T "* ]]; then echo "DECIDE $T pseudo weak-oracle kills $KN -> keep"; continue; fi + REM=""; for h in $ALLHEAVY; do case " $DELETED $T " in *" $h "*) ;; *) REM="$REM $h";; esac; done + KRE=$(python3 -c 'import re,sys; print("|".join(re.escape(l.rstrip("\n")) for l in open(sys.argv[1]) if l.strip()))' "$OUT/$T.K.txt") + cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$KRE" --cargo-test-arg=-E --cargo-test-arg="$(expr $REM)" -o "$OUT/$T.C" > "$OUT/$T.C.log" 2>&1 + python3 "$TOOLS/outcomes.py" "$OUT/$T.C/mutants.out/outcomes.json" killed > "$OUT/$T.Kc.txt" + comm -23 <(sort "$OUT/$T.K.txt") <(sort "$OUT/$T.Kc.txt") > "$OUT/$T.Kp.txt" + KP=$(wc -l < "$OUT/$T.Kp.txt") + echo "$T K'=$KP" + if [ "$KP" -eq 0 ]; then echo "DECIDE $T K'=0 -> delete"; DELETED="$DELETED $T"; else echo "DECIDE $T K'=$KP -> keep"; fi +done +echo "DELETED:$DELETED" diff --git a/lanes/testcut/p2h265-tools/cov.sh b/lanes/testcut/p2h265-tools/cov.sh new file mode 100755 index 00000000..e67a073f --- /dev/null +++ b/lanes/testcut/p2h265-tools/cov.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Phase 2 coverage pass for ec-h265 (runs on the server inside the synced tree). +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +OUT=$HOME/lanes/testcut-p2-h265-c1/out +mkdir -p "$OUT" +PROF=${CARGO_TARGET_DIR:-$PWD/target}/llvm-cov-target +run_cov() { + local name=$1; shift + cargo llvm-cov clean --profraw-only > /dev/null 2>&1 + find "$PROF" -name '*.profraw' -delete 2>/dev/null + cargo llvm-cov nextest --release --no-fail-fast -p ec-h265 --no-report "$@" > "$OUT/$name.run.log" 2>&1 + echo "$name nextest exit $?" + PD=$(rustc --print sysroot)/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata + for f in $(find "$PROF" -name '*.profraw' 2>/dev/null); do + if ! "$PD" show "$f" > /dev/null 2>&1; then echo "$name: dropping corrupt $f"; rm -f "$f"; fi + done + cargo llvm-cov report --release --json --output-path "$OUT/$name.json" > "$OUT/$name.rep.log" 2>&1 + echo "$name report exit $?" +} +cargo llvm-cov clean --workspace > /dev/null 2>&1 +run_cov fast --profile fast +for t in pixel_pipeline_runs_over_conformance_streams motion_derivation_is_deterministic_over_conformance_streams cu_syntax_sweep_over_conformance_streams ffmpeg_decodes_bit_exactly_at_every_shape noisy_near_black_lands_within_five_percent; do + run_cov "$t" -E "test(/(^|::)$t\$/)" +done +grep -h -E "PASS|FAIL|Summary" "$OUT"/*.run.log | tail -40 diff --git a/lanes/testcut/p2h265-tools/dbg.py b/lanes/testcut/p2h265-tools/dbg.py new file mode 100644 index 00000000..11c1d09b --- /dev/null +++ b/lanes/testcut/p2h265-tools/dbg.py @@ -0,0 +1,33 @@ +import json, os, sys +sys.argv = ["x", os.path.expanduser("~/lanes/testcut-p2-h265-c1/out"), "pixel_pipeline_runs_over_conformance_streams", "1"] +src = open(os.path.join(os.getcwd(), "lanes/testcut/p2h265-tools/sample.py")).read().split("cands = []")[0] +exec(src) +muts = json.load(open(f"{out}/mutants.json")) +nf = sum(1 for m in muts if tail(m["file"]) in {k[0] for k in fast}) +print("mutants", len(muts), "file-matched", nf, "fast funcs", len(fast), "sample files", list({k[0] for k in fast})[:3], "mut files", list({tail(m["file"]) for m in muts})[:3]) +found = inT = 0 +for m in muts: + f = tail(m["file"]); line = m["span"]["start"]["line"] + hits = [fn for k, fn in fast.items() if k[0] == f and fn["lo"] <= line <= fn["hi"]] + if hits: + found += 1 + b = min(hits, key=lambda fn: fn["hi"] - fn["lo"]) + t = T.get((b["file"], b["name"])) + if t and t["covered_regions"]: + inT += 1 +print("found", found, "inT", inT, "Tfuncs", len(T), "sample T keys", list(T)[:2]) +print("T funcs with covered", sum(1 for f in T.values() if f["covered_regions"]), "fast hits>0", sum(1 for f in fast.values() if f["hits"]>0)) +import itertools +print("sample covered T:", [ (k[1][:60], len(v["covered_regions"])) for k,v in itertools.islice(((k,v) for k,v in T.items() if v["covered_regions"]),3)]) +cnt = 0 +for m in muts[:4000]: + f = tail(m["file"]); line = m["span"]["start"]["line"] + hits = [fn for k, fn in fast.items() if k[0] == f and fn["lo"] <= line <= fn["hi"]] + if hits: + b = min(hits, key=lambda fn: fn["hi"] - fn["lo"]) + t = T.get((b["file"], b["name"])) + if cnt < 3: + print("MUT", f, line, "fn", b["name"][-40:], "inT", t is not None, "covered", len(t["covered_regions"]) if t else None, "fast hits", b["hits"]) + cnt += 1 + if cnt >= 3: break +print("Tcovered files", sorted({k[0] for k,v in T.items() if v["covered_regions"]})[:8]) diff --git a/lanes/testcut/p2h265-tools/fast.sh b/lanes/testcut/p2h265-tools/fast.sh new file mode 100644 index 00000000..90468d43 --- /dev/null +++ b/lanes/testcut/p2h265-tools/fast.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Step 2: KT mutants through the fast profile (release). usage: fast.sh T ... (skips T with empty KT) +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +TOOLS=$PWD/lanes/testcut/p2h265-tools +OUT=$(dirname "$PWD")/out +cargo nextest run --release -p ec-h265 --profile fast --no-run > "$OUT/fastbuild.log" 2>&1 || { echo fast build failed; exit 1; } +S=$(date +%s) +cargo nextest run --release -p ec-h265 --profile fast --no-fail-fast > "$OUT/fastbase.log" 2>&1 +echo "fast baseline rc=$? $(( $(date +%s) - S ))s" +SECS=$(( $(date +%s) - S )) +# tests failing unmutated are excluded (fixture/personal-media tests) +grep -E "^\s+(FAIL|TIMEOUT|SIGKILL|SIGSEGV|SIGABRT)" "$OUT/fastbase.log" | sed -E 's/^.*\] +(\([0-9]+\/[0-9]+\) +)?//' | awk '{print $1" "$2}' | sort -u > "$OUT/fast-excluded.txt" +echo "excluded:"; cat "$OUT/fast-excluded.txt" +EX="" +while read -r bin name; do [ -n "$name" ] && EX="$EX and not test(=$name)"; done < "$OUT/fast-excluded.txt" +TO=$(( (SECS * 5 + 1) / 2 + 5 )) +for T in "$@"; do + [ -s "$OUT/KT-$T.txt" ] && ! grep -q baseline_failed "$OUT/KT-$T.txt" || { echo "$T: KT empty"; continue; } + python3 -c "import json,sys;json.dump([l.rstrip('\n') for l in open(sys.argv[1]) if l.strip()],open(sys.argv[2],'w'))" "$OUT/KT-$T.txt" "$OUT/KT-$T.json" + FAILFAST=1 python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/KT-$T.json" "F-$T" "$TO" "all()$EX" --profile fast > "$OUT/F-$T.log" 2>&1 + awk -F'\t' '$2=="SURVIVED"{print $1}' "$OUT/res-F-$T.tsv" > "$OUT/K-$T.txt" + echo "$T fast statuses: $(cut -f2 "$OUT/res-F-$T.tsv" | sort | uniq -c | tr '\n' ' ') K=$(wc -l < "$OUT/K-$T.txt")" +done +echo FAST_DONE diff --git a/lanes/testcut/p2h265-tools/gate.sh b/lanes/testcut/p2h265-tools/gate.sh new file mode 100644 index 00000000..d1c5e65d --- /dev/null +++ b/lanes/testcut/p2h265-tools/gate.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +export EC_REQUIRE_FIXTURES=1 +cargo clippy --release -p ec-h265 --tests -- -D warnings 2>&1 | tail -15; echo "clippy rc=${PIPESTATUS[0]}" +cargo test --release -p ec-h265 2>&1 | grep -E "^test result|FAILED|failed|panicked|^error" | head -30; echo "test rc=${PIPESTATUS[0]}" +echo GATE_DONE diff --git a/lanes/testcut/p2h265-tools/mut.sh b/lanes/testcut/p2h265-tools/mut.sh new file mode 100755 index 00000000..563e5f11 --- /dev/null +++ b/lanes/testcut/p2h265-tools/mut.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# usage: mut.sh TEST OTHERS_EXPR (run from the synced tree; OTHERS_EXPR = nextest -E for remaining heavy tests, or empty) +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +OUT=$HOME/lanes/testcut-p2-h265-c1/out +T=$1; OTHERS=${2:-} +TOOLS=$PWD/lanes/testcut/p2h265-tools +TF="test(/(^|::)$T\$/)" +RE=$(python3 -c 'import json,re,sys; print("|".join(re.escape(n) for n in json.load(open(sys.argv[1]))))' "$OUT/sample-$T.json") +[ -n "$RE" ] || { echo "$T: empty sample"; exit 0; } +COMMON=(cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$RE") +echo "== $T run A (fast suite) $(date +%T)" +"${COMMON[@]}" --cargo-test-arg=--profile --cargo-test-arg=fast -o "$OUT/$T.A" > "$OUT/$T.A.log" 2>&1 +echo "A exit $?" +python3 "$TOOLS/outcomes.py" "$OUT/$T.A/mutants.out/outcomes.json" missed > "$OUT/$T.S.txt" +SN=$(wc -l < "$OUT/$T.S.txt") +echo "S=$SN survivors of fast suite" +[ "$SN" -eq 0 ] && { echo "$T: no survivors"; exit 0; } +RES=$(python3 -c 'import re,sys; print("|".join(re.escape(l.rstrip("\n")) for l in open(sys.argv[1]) if l.strip()))' "$OUT/$T.S.txt") +echo "== $T run B (T only) $(date +%T)" +cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$RES" --cargo-test-arg=-E --cargo-test-arg="$TF" -o "$OUT/$T.B" > "$OUT/$T.B.log" 2>&1 +echo "B exit $?" +python3 "$TOOLS/outcomes.py" "$OUT/$T.B/mutants.out/outcomes.json" killed > "$OUT/$T.K.txt" +KN=$(wc -l < "$OUT/$T.K.txt") +echo "K=$KN killed by T among S" +[ "$KN" -eq 0 ] && { echo "$T: K empty"; exit 0; } +KRE=$(python3 -c 'import re,sys; print("|".join(re.escape(l.rstrip("\n")) for l in open(sys.argv[1]) if l.strip()))' "$OUT/$T.K.txt") +[ -n "$OTHERS" ] || { echo "$T: no other heavy tests"; exit 0; } +echo "== $T run C (other heavy tests) $(date +%T)" +cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$KRE" --cargo-test-arg=-E --cargo-test-arg="$OTHERS" -o "$OUT/$T.C" > "$OUT/$T.C.log" 2>&1 +echo "C exit $?" +python3 "$TOOLS/outcomes.py" "$OUT/$T.C/mutants.out/outcomes.json" killed > "$OUT/$T.Kc.txt" +echo "K'=$(comm -23 <(sort "$OUT/$T.K.txt") <(sort "$OUT/$T.Kc.txt" 2>/dev/null) | wc -l) (see $T.Kp.txt)"; comm -23 <(sort "$OUT/$T.K.txt") <(sort "$OUT/$T.Kc.txt" 2>/dev/null) > "$OUT/$T.Kp.txt" +echo "$T done $(date +%T)" diff --git a/lanes/testcut/p2h265-tools/mutrun.py b/lanes/testcut/p2h265-tools/mutrun.py new file mode 100644 index 00000000..93f8301e --- /dev/null +++ b/lanes/testcut/p2h265-tools/mutrun.py @@ -0,0 +1,123 @@ +# usage: mutrun.py OUT NAMES_JSON TAG TIMEOUT_SECS FILTER_EXPR [--profile fast] +# Applies each named mutant's own diff (from OUT/mutants.json) to the lane tree, runs +# `cargo nextest run -p ec-h265 -E FILTER_EXPR`, restores the file, and records one row per mutant: +# name status summary +# status: KILLED (test failure or timeout), SURVIVED (all pass), UNVIABLE (compile error), NORUN (no test ran). +# The tree is the lane's synced tree (cwd); only the one mutated file is touched, and it is restored. +import json, os, subprocess, sys, re +out, names_file, tag, timeout = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4]) +expr = sys.argv[5] +profile = sys.argv[7] if len(sys.argv) > 7 and sys.argv[6] == "--profile" else None +names = json.load(open(names_file)) +muts = {m["name"]: m for m in json.load(open(f"{out}/mutants.json"))} + +def parse(diff): + lines = diff.split("\n") + fname = lines[0][4:].strip() + hunks = [] + i = 1 + while i < len(lines): + m = re.match(r"@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@", lines[i]) + if not m: + i += 1 + continue + start = int(m.group(1)) + body = [] + i += 1 + while i < len(lines) and not lines[i].startswith("@@"): + if lines[i][:1] in (" ", "-", "+"): + body.append((lines[i][:1], lines[i][1:])) + i += 1 + hunks.append((start, body)) + return fname, hunks + +def apply(orig, hunks): + res, cur = [], 0 + for start, body in hunks: + pos = start - 1 + res.extend(orig[cur:pos]) + cur = pos + for op, text in body: + if op in (" ", "-"): + if cur >= len(orig) or orig[cur] != text: + raise ValueError(f"context mismatch at line {cur + 1}") + if op == " ": + res.append(text) + cur += 1 + else: + res.append(text) + res.extend(orig[cur:]) + return res + +def sh(cmd, tmo): + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, + start_new_session=True) + try: + output, _ = p.communicate(timeout=tmo) + return p.returncode, output, False + except subprocess.TimeoutExpired: + os.killpg(p.pid, 9) + output, _ = p.communicate() + return -1, output or "", True + +BUILD_TO = int(os.environ.get("BUILD_TO", "2400")) + +def run_once(): + # release profile; build first (own generous timeout), then run with the measured-baseline timeout + cmd = ["cargo", "nextest", "run", "--release", "-p", "ec-h265", "--no-fail-fast", "-E", expr] + if os.environ.get("FAILFAST"): + cmd.remove("--no-fail-fast") + if profile: + cmd[-2:-2] = ["--profile", profile] + rc, out, to = sh([c for c in cmd if c != "--no-fail-fast"] + ["--no-run"], BUILD_TO) + if to or rc != 0: + return rc, out, "BUILDFAIL" + return sh(cmd, timeout) + +rows = [] +for name in names: + m = muts.get(name) + if m is None: + rows.append((name, "NORUN", "name not in mutants.json")) + continue + fname, hunks = parse(m["diff"]) + raw = open(fname, "rb").read() + text = raw.decode() + orig = text.split("\n") + try: + new = apply(orig, hunks) + except ValueError as e: + rows.append((name, "NORUN", f"apply failed: {e}")) + continue + try: + open(fname, "w").write("\n".join(new)) + rc, output, timed_out = run_once() + timed_out = timed_out + finally: + open(fname, "wb").write(raw) + summary = re.findall(r"Summary \[[^\]]*\] (\d+)(?:/\d+)? tests? run", output) + ran = int(summary[-1]) if summary else 0 + if timed_out == "BUILDFAIL": + status = "UNVIABLE" + elif timed_out: + # A timeout is kill evidence only if the test run had started (build time alone is not). + status = "KILLED" if re.search(r"Starting \d+ tests?", output) else "TIMEOUT_NOSTART" + elif rc != 0 and re.search(r"EC_REQUIRE_FIXTURES|fixtures? (missing|not found)", output): + # A fixture-missing failure is not a kill. + status = "FIXTURE_FAIL" + elif "could not compile" in output or "error[E" in output: + status = "UNVIABLE" + elif rc == 0 and ran > 0: + status = "SURVIVED" + elif rc != 0 and ran > 0: + status = "KILLED" + else: + status = "NORUN" + err = next((l for l in output.splitlines() if "error[" in l or l.startswith("error")), "") if status == "UNVIABLE" else "" + rows.append((name, status, f"rc={rc} ran={ran} timeout={timed_out} {err}")) + print(status, name[:90], f"rc={rc} ran={ran}", flush=True) + +with open(f"{out}/res-{tag}.tsv", "w") as f: + for r in rows: + f.write("\t".join(r) + "\n") +print("summary", {s: sum(1 for r in rows if r[1] == s) for s in ("KILLED", "SURVIVED", "UNVIABLE", "NORUN")}) diff --git a/lanes/testcut/p2h265-tools/outcomes.py b/lanes/testcut/p2h265-tools/outcomes.py new file mode 100644 index 00000000..17c894b4 --- /dev/null +++ b/lanes/testcut/p2h265-tools/outcomes.py @@ -0,0 +1,13 @@ +# usage: outcomes.py OUTCOMES_JSON SUMMARY_KIND (kind: missed | killed) -> prints mutant names +import json, sys +data = json.load(open(sys.argv[1])) +kind = sys.argv[2] +want = {"missed": {"MissedMutant"}, "killed": {"CaughtMutant", "Timeout"}}[kind] +rows = data["outcomes"] if isinstance(data, dict) else data +for o in rows: + sc = o.get("scenario") + if not isinstance(sc, dict) or "Mutant" not in sc: + continue + if o.get("summary") in want: + m = sc["Mutant"] + print(m.get("name", json.dumps(m))) diff --git a/lanes/testcut/p2h265-tools/recheck.sh b/lanes/testcut/p2h265-tools/recheck.sh new file mode 100644 index 00000000..0f9f1f36 --- /dev/null +++ b/lanes/testcut/p2h265-tools/recheck.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Recheck the timeout-only rows with long timeouts. Runs from synced tree. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +TOOLS=$PWD/lanes/testcut/p2h265-tools +OUT=$(dirname "$PWD")/out +EXN="$(awk '{print " and not test(=" $2 ")"}' "$OUT/fast-excluded.txt" | tr -d '\n')" +N="crates/ec-h265/src/ctu.rs:534:29: replace + with - in CtuEncoder<'a>::save_meta" +F="crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree" +python3 -c "import json,sys;json.dump([sys.argv[1]],open(sys.argv[3],'w'));json.dump([sys.argv[2]],open(sys.argv[4],'w'))" "$N" "$F" "$OUT/rc-n.json" "$OUT/rc-f.json" +FAILFAST=1 python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/rc-n.json" rc-n-fast 1200 "all()$EXN" --profile fast +python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/rc-f.json" rc-f-T 600 "test(/(^|::)ffmpeg_decodes_bit_exactly_at_every_shape\$/)" +FAILFAST=1 python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/rc-f.json" rc-f-fast 1200 "all()$EXN" --profile fast +echo RECHECK_DONE diff --git a/lanes/testcut/p2h265-tools/recheck2.sh b/lanes/testcut/p2h265-tools/recheck2.sh new file mode 100644 index 00000000..843ad18b --- /dev/null +++ b/lanes/testcut/p2h265-tools/recheck2.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Recheck the 3 ffmpeg T-timeout mutants on a quiet host: T alone (2.5x measured baseline), then fast profile. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +TOOLS=$PWD/lanes/testcut/p2h265-tools +OUT=$(dirname "$PWD")/out +echo "load: $(cat /proc/loadavg)" +F="test(/(^|::)ffmpeg_decodes_bit_exactly_at_every_shape\$/)" +cargo nextest run --release -p ec-h265 -E "$F" --no-run >/dev/null 2>&1 +S=$(date +%s); cargo nextest run --release -p ec-h265 -E "$F" > "$OUT/b2.log" 2>&1; echo "T baseline rc=$? $(( $(date +%s)-S ))s" +cat > "$OUT/names.json" <<'J' +["crates/ec-h265/src/residual.rs:609:42: replace + with - in residual_header","crates/ec-h265/src/ctu.rs:429:13: replace + with - in CtuEncoder<'a>::code_quadtree","crates/ec-h265/src/residual.rs:430:64: replace >> with << in rdoq"] +J +python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/names.json" R2-T 63 "$F" +python3 - <<'P' +import json,os +o=os.environ.get("OUT") +P +awk -F'\t' '$2=="KILLED"{print $1}' "$OUT/res-R2-T.tsv" > "$OUT/k2.txt" +python3 -c "import json,sys;json.dump([l.rstrip('\n') for l in open(sys.argv[1]) if l.strip()],open(sys.argv[2],'w'))" "$OUT/k2.txt" "$OUT/k2.json" +cargo nextest run --release -p ec-h265 --profile fast --no-run >/dev/null 2>&1 +S=$(date +%s); cargo nextest run --release -p ec-h265 --profile fast --no-fail-fast > "$OUT/fb2.log" 2>&1; SECS=$(( $(date +%s)-S )); echo "fast baseline rc=$? ${SECS}s" +FAILFAST=1 python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/k2.json" R2-F $(( SECS*5/2+5 )) "all()" --profile fast +cut -f1,2,3 "$OUT"/res-R2-*.tsv | cut -c1-200 +echo R2_DONE diff --git a/lanes/testcut/p2h265-tools/resample.sh b/lanes/testcut/p2h265-tools/resample.sh new file mode 100644 index 00000000..825251df --- /dev/null +++ b/lanes/testcut/p2h265-tools/resample.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -uo pipefail +OUT=$HOME/lanes/testcut-p2-h265-c1/out +TOOLS=$PWD/lanes/testcut/p2h265-tools +for t in pixel_pipeline_runs_over_conformance_streams motion_derivation_is_deterministic_over_conformance_streams cu_syntax_sweep_over_conformance_streams ffmpeg_decodes_bit_exactly_at_every_shape noisy_near_black_lands_within_five_percent; do python3 "$TOOLS/sample.py" "$OUT" "$t" 60; done diff --git a/lanes/testcut/p2h265-tools/run1.sh b/lanes/testcut/p2h265-tools/run1.sh new file mode 100644 index 00000000..207c10b4 --- /dev/null +++ b/lanes/testcut/p2h265-tools/run1.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Step 1 (T only), one chain, RELEASE profile. usage: run1.sh T ... (run from the synced tree; OUT = /out) +# Per candidate: build, measured unmutated baseline of T (wall seconds of the run), then SAMPLE_N (default 10) +# seeded mutants (sample2.py) each applied in place (mutrun.py), built, and run against T only with +# timeout = 2.5 x measured baseline. Writes KT-.txt, S1-.txt, res-B1-.tsv, base-.secs. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +TOOLS=$PWD/lanes/testcut/p2h265-tools +OUT=$(dirname "$PWD")/out +SEED=2026 +N=${SAMPLE_N:-10} +for T in "$@"; do + F="test(/(^|::)$T\$/)" + echo "== $T build $(date +%T)" + cargo nextest run --release -p ec-h265 -E "$F" --no-run > "$OUT/build-$T.log" 2>&1 || { echo "$T build failed"; continue; } + S=$(date +%s) + cargo nextest run --release -p ec-h265 --no-fail-fast -E "$F" > "$OUT/base-$T.log" 2>&1 + BRC=$?; E=$(date +%s); SECS=$((E - S)) + echo "$SECS" > "$OUT/base-$T.secs" + if [ "$BRC" -ne 0 ] || ! grep -qE "Starting [0-9]+ tests?" "$OUT/base-$T.log"; then + echo "$T baseline_failed rc=$BRC"; echo "baseline_failed" > "$OUT/KT-$T.txt"; : > "$OUT/S1-$T.txt"; continue + fi + TO=$(( (SECS * 5 + 1) / 2 + 5 )) + echo "baseline ${SECS}s timeout ${TO}s $(date +%T)" + python3 "$TOOLS/sample2.py" "$OUT" "$T" "$N" "$SEED" || { echo "$T sample failed"; continue; } + python3 "$TOOLS/mutrun.py" "$OUT" "$OUT/s-$T.json" "B1-$T" "$TO" "$F" > "$OUT/B1-$T.log" 2>&1 + echo "exit $? $(date +%T)" + awk -F'\t' '$2=="KILLED"{print $1}' "$OUT/res-B1-$T.tsv" > "$OUT/KT-$T.txt" + awk -F'\t' '$2=="SURVIVED"{print $1}' "$OUT/res-B1-$T.tsv" > "$OUT/S1-$T.txt" + echo "statuses: $(cut -f2 "$OUT/res-B1-$T.tsv" | sort | uniq -c | tr '\n' ' ')" + echo "KT=$(wc -l < "$OUT/KT-$T.txt") S1=$(wc -l < "$OUT/S1-$T.txt")" +done +echo CHAIN_DONE diff --git a/lanes/testcut/p2h265-tools/runA.sh b/lanes/testcut/p2h265-tools/runA.sh new file mode 100755 index 00000000..9bc76c80 --- /dev/null +++ b/lanes/testcut/p2h265-tools/runA.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Shared run A: fast suite vs union of all candidate samples. Writes $OUT/A.S.txt (survivors). +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +OUT=$HOME/lanes/testcut-p2-h265-c1/out +TOOLS=$PWD/lanes/testcut/p2h265-tools +python3 -c 'import json,glob +u=[] +for f in sorted(glob.glob("'$OUT'/sample-*.json")): + for n in json.load(open(f)): + if n not in u: u.append(n) +json.dump(u, open("'$OUT'/union.json","w")); print("union", len(u))' +RE=$(python3 -c 'import json,re,sys; print("|".join(re.escape(n) for n in json.load(open(sys.argv[1]))))' "$OUT/union.json") +cargo mutants --help 2>&1 | grep -E "^ +--(release|test-tool|cargo-test-arg|in-place|baseline)" | head -6 +cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$RE" --cargo-test-arg=--profile --cargo-test-arg=fast -o "$OUT/A" > "$OUT/A.log" 2>&1 +echo "A exit $?" +python3 "$TOOLS/outcomes.py" "$OUT/A/mutants.out/outcomes.json" missed > "$OUT/A.S.txt" +echo "S=$(wc -l < "$OUT/A.S.txt")" +python3 -c 'import json,collections; print(collections.Counter(o.get("summary") for o in json.load(open("'$OUT'/A/mutants.out/outcomes.json"))["outcomes"]))' 2>/dev/null diff --git a/lanes/testcut/p2h265-tools/sample.py b/lanes/testcut/p2h265-tools/sample.py new file mode 100644 index 00000000..bf8a57d0 --- /dev/null +++ b/lanes/testcut/p2h265-tools/sample.py @@ -0,0 +1,61 @@ +# usage: sample.py OUT TEST MAXN -> writes OUT/sample-TEST.json (names in priority order) +import json, sys, collections +out, test, maxn = sys.argv[1], sys.argv[2], int(sys.argv[3]) +def tail(p): + i = p.find("ec-h265/") + return p[i + len("ec-h265/"):] if i >= 0 else None +def load(n): + return json.load(open(f"{out}/{n}.json"))["data"][0] +def funcs(data): + res = [] # (file, name, lo, hi, fast_hits_or_covered_hits, uncov_hits) + for fn in data["functions"]: + fl = [tail(fn["filenames"][r[5]]) for r in fn["regions"][:1]] + if fl[0] is None: + continue + lo = min(r[0] for r in fn["regions"]); hi = max(r[2] for r in fn["regions"]) + res.append({"file": fl[0], "name": fn["name"], "lo": lo, "hi": hi, + "hits": sum(r[4] for r in fn["regions"]), + "covered_regions": {(r[0], r[1], r[2], r[3], r[7]) for r in fn["regions"] if r[4] > 0}}) + return res +def merged(lst): + d = {} + for f in lst: + k = (f["file"], f["name"]) + if k not in d: + d[k] = dict(f) + continue + m = d[k] + m["hits"] += f["hits"] + m["lo"] = min(m["lo"], f["lo"]); m["hi"] = max(m["hi"], f["hi"]) + m["covered_regions"] = m["covered_regions"] | f["covered_regions"] + return d +fast = merged(funcs(load("fast"))) +T = merged(funcs(load(test))) +cov = json.load(open(f"{out}/coverage-summary.json"))["per_test"][test] +ufuncs = {(x[0], x[1]) for x in cov["U_functions"]} +muts = json.load(open(f"{out}/mutants.json")) +cands = [] +for m in muts: + f = tail(m["file"]) if "ec-h265/" in m["file"] else m["file"] + if f is None: + continue + line = m["span"]["start"]["line"] + best = None + for key, fn in fast.items(): + if key[0] != f or not (fn["lo"] <= line <= fn["hi"]): + continue + t = T.get(key) + if t is None or not t["covered_regions"]: + continue + if best is None or (fn["hi"] - fn["lo"]) < (best["hi"] - best["lo"]): + best = fn + if best is None: + continue + key = (best["file"], best["name"]) + t = T.get(key) + prio = 0 if key in ufuncs else 1 + cands.append((prio, fast[key]["hits"], m["name"])) +cands.sort() +names = [c[2] for c in cands[:maxn]] +json.dump(names, open(f"{out}/sample-{test}.json", "w")) +print(test, "eligible", len(cands), "sampled", len(names), "U-funcs-prio", sum(1 for c in cands[:maxn] if c[0] == 0)) diff --git a/lanes/testcut/p2h265-tools/sample2.py b/lanes/testcut/p2h265-tools/sample2.py new file mode 100644 index 00000000..6e8ca1a3 --- /dev/null +++ b/lanes/testcut/p2h265-tools/sample2.py @@ -0,0 +1,66 @@ +# usage: sample2.py OUT TEST N SEED -> OUT/s-TEST.json +# Seeded sample of mutants whose containing fast-suite function is in U(TEST) (the functions TEST +# covers that the fast suite does not). Writes the mutant names; prints eligible/sampled counts. +import json, random, sys, collections +out, test, n, seed = sys.argv[1], sys.argv[2], int(sys.argv[3]), int(sys.argv[4]) + +def tail(p): + i = p.find("ec-h265/") + return p[i + 8:] if i >= 0 else None + +def load(name): + return json.load(open(f"{out}/{name}.json"))["data"][0] + +def funcs(data): + res = {} + for fn in data["functions"]: + if not fn["regions"]: + continue + fl = tail(fn["filenames"][fn["regions"][0][5]]) + if fl is None: + continue + lo = min(r[0] for r in fn["regions"]) + hi = max(r[2] for r in fn["regions"]) + key = (fl, fn["name"]) + d = res.setdefault(key, {"lo": lo, "hi": hi, "cov": False}) + d["lo"] = min(d["lo"], lo) + d["hi"] = max(d["hi"], hi) + d["cov"] = d["cov"] or any(r[4] > 0 for r in fn["regions"]) + return res + +fast = funcs(load("fast")) +T = funcs(load(test)) +U = {(x[0], x[1]) for x in json.load(open(f"{out}/coverage-summary.json"))["per_test"][test]["U_functions"]} +by_file = collections.defaultdict(list) +for key in fast: + by_file[key[0]].append(key) + +elig = [] +covered = [] +for m in json.load(open(f"{out}/mutants.json")): + f = tail(m["file"]) if "ec-h265/" in m["file"] else m["file"] + line = m["span"]["start"]["line"] + best = None + for key in by_file.get(f, []): + fn = fast[key] + if not T.get(key, {}).get("cov"): + continue + if fn["lo"] <= line <= fn["hi"]: + if best is None or (fn["hi"] - fn["lo"]) < (best[1]["hi"] - best[1]["lo"]): + best = (key, fn) + if best is None: + continue + key = best[0] + if key in U and T.get(key, {}).get("cov"): + elig.append(m["name"]) + elif T.get(key, {}).get("cov"): + covered.append(m["name"]) + +elig = sorted(set(elig)) +covered = sorted(set(covered) - set(elig)) +# Fallback when U(T) holds no source functions (e.g. only test-file functions): mutants in functions +# T covers, which the protocol's step 3 allows. +pool, label = (elig, "U") if elig else (covered, "covered-fallback") +picked = random.Random(seed).sample(pool, min(n, len(pool))) +json.dump(picked, open(f"{out}/s-{test}.json", "w")) +print(test, label, len(pool), "sampled", len(picked), "seed", seed) diff --git a/lanes/testcut/p2h265-tools/smoke.sh b/lanes/testcut/p2h265-tools/smoke.sh new file mode 100644 index 00000000..5c21fb63 --- /dev/null +++ b/lanes/testcut/p2h265-tools/smoke.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Smoke: two mutants from the union sample through the fast suite, to time one mutant and check the runner. +set -uo pipefail +export EC_REQUIRE_FIXTURES=1 +OUT=$HOME/lanes/testcut-p2-h265-c1/out +mkdir -p "$OUT" +python3 -c 'import json,sys; print("\n".join(json.load(open(sys.argv[1]))[:2]))' "$OUT/sample-pixel_pipeline_runs_over_conformance_streams.json" > "$OUT/smoke.names" +RE=$(python3 -c 'import re,sys; print("|".join(re.escape(l.rstrip("\n")) for l in open(sys.argv[1]) if l.strip()))' "$OUT/smoke.names") +date +%T +cargo mutants -p ec-h265 --test-tool nextest --baseline skip --timeout-multiplier 3 --re "$RE" --cargo-test-arg=--profile --cargo-test-arg=fast -o "$OUT/smoke" > "$OUT/smoke.log" 2>&1 +echo "exit $?"; date +%T +tail -5 "$OUT/smoke.log"