Make the frame-count failure name the real cause, and classify the defect
Browse files at this commite107603a9488f3c96f7e18a8535e47356fbb3295Parent: 32ee762- test
- make the frame-count failure name the real cause, and classify the defect
2 changed files +222 -12
crates/ec-av1/src/gate_coverage.rsmodified+141 -6
| @@ -2040,6 +2040,16 @@ mod pin_inventory_tests { | ||
| 2040 | 2040 | /// cannot pass silently -- it reds, with a message that blames FFMPEG for a |
| 2041 | 2041 | /// count OUR decoder chose. |
| 2042 | 2042 | /// |
| 2043 | +/// TWO DEFECT CLASSES, DO NOT CONFLATE THEM (lane-av1pins5 r6): | |
| 2044 | +/// * MISATTRIBUTED RED -- a wrong count reds, and the old message blamed | |
| 2045 | +/// ffmpeg for a number OUR decoder chose. This is what these sites are. | |
| 2046 | +/// `ffmpeg_decode_sequence`'s `stdout.len() == frame_bytes * frames` assert | |
| 2047 | +/// is unconditional, so it cannot pass silently. | |
| 2048 | +/// * SILENT PASS -- the compare is skipped or truncated and the gate reports | |
| 2049 | +/// green. A DIFFERENT defect with a DIFFERENT fix, and r4 mislabelled these | |
| 2050 | +/// sites as belonging to it. If you are reading this to decide what to fix, | |
| 2051 | +/// fix the message and the count SOURCE; do not go looking for a silent pass. | |
| 2052 | +/// | |
| 2043 | 2053 | /// r4 reported this shape as "a vacuous pass" and told Main so. That was wrong. |
| 2044 | 2054 | /// The consequence is a MISATTRIBUTED RED. The fix r4 shipped is still right (the |
| 2045 | 2055 | /// count now comes from the fixture, so the red names the real cause), but the |
| @@ -2059,18 +2069,28 @@ mod count_vacuity { | ||
| 2059 | 2069 | /// lines above: that is what makes the count a SPEC rather than a |
| 2060 | 2070 | /// self-fulfilling number. |
| 2061 | 2071 | pub pinned_by: Option<String>, |
| 2072 | + /// Does this gate actually COMPARE PIXELS (so a wrong count would | |
| 2073 | + /// corrupt a verdict), or is it a report-only probe? | |
| 2074 | + pub pixel_comparing: bool, | |
| 2075 | + /// A frame count already in scope that is a SPEC rather than a | |
| 2076 | + /// self-fulfilling number -- e.g. the `FRAMES` the gate encoded, or a | |
| 2077 | + /// count asserted on the pinned stream. `Some(..)` means the fix is a | |
| 2078 | + /// one-line swap at this site. | |
| 2079 | + pub fixable_from: Option<String>, | |
| 2062 | 2080 | } |
| 2063 | 2081 | |
| 2064 | 2082 | pub fn sites(src: &str) -> Vec<Site> { |
| 2065 | 2083 | let mut out = Vec::new(); |
| 2066 | 2084 | let lines: Vec<&str> = src.lines().collect(); |
| 2067 | 2085 | let mut gate = String::new(); |
| 2086 | + let mut fn_start = 0usize; | |
| 2068 | 2087 | for (i, line) in lines.iter().enumerate() { |
| 2069 | 2088 | let t = line.trim_start(); |
| 2070 | 2089 | if let Some(rest) = t.strip_prefix("fn ") { |
| 2071 | 2090 | if let Some(n) = rest.split('(').next() { |
| 2072 | 2091 | if !n.contains(' ') { |
| 2073 | 2092 | gate = n.to_string(); |
| 2093 | + fn_start = i; | |
| 2074 | 2094 | } |
| 2075 | 2095 | } |
| 2076 | 2096 | } |
| @@ -2111,16 +2131,118 @@ mod count_vacuity { | ||
| 2111 | 2131 | // within the preceding 12 lines? That is the difference between |
| 2112 | 2132 | // a spec and a self-fulfilling number. |
| 2113 | 2133 | let binding = last.trim_end_matches(".len()").trim_end_matches(".count()"); |
| 2134 | + // Match the assertion across a LINE BREAK: rustfmt puts | |
| 2135 | + // assert_eq!( | |
| 2136 | + // frames.len(), | |
| 2137 | + // so requiring `assert_eq!(frames.len()` on one line missed | |
| 2138 | + // every multi-line spelling and inflated the unpinned count. | |
| 2139 | + let want = format!("{binding}.len()"); | |
| 2114 | 2140 | let mut pinned = None; |
| 2115 | - for back in 1..=12usize { | |
| 2141 | + for back in 1..=14usize { | |
| 2116 | 2142 | if i < back { |
| 2117 | 2143 | break; |
| 2118 | 2144 | } |
| 2119 | - let prev = lines[i - back]; | |
| 2120 | - if prev.contains(&format!("assert_eq!({binding}.len()")) | |
| 2121 | - || prev.contains(&format!("assert_eq!({binding}.len(), ")) | |
| 2145 | + let prev = lines[i - back].trim_start(); | |
| 2146 | + if !prev.starts_with("assert") || !prev.contains('(') { | |
| 2147 | + continue; | |
| 2148 | + } | |
| 2149 | + // rustfmt splits `assert_eq!(` from its first argument, so | |
| 2150 | + // the binding is on THIS line or the NEXT one. | |
| 2151 | + let here = prev.contains(&want); | |
| 2152 | + let next = lines | |
| 2153 | + .get(i - back + 1) | |
| 2154 | + .map(|l| l.trim_start().contains(&want)) | |
| 2155 | + .unwrap_or(false); | |
| 2156 | + if here || next { | |
| 2157 | + pinned = Some(prev.chars().take(60).collect()); | |
| 2158 | + break; | |
| 2159 | + } | |
| 2160 | + } | |
| 2161 | + // Pixel-comparing? A gate that compares planes is the only | |
| 2162 | + // place a wrong count corrupts a verdict; a report-only probe | |
| 2163 | + // just prints. | |
| 2164 | + // Bound to THIS fn only. Slicing to EOF matched a later gate's | |
| 2165 | + // `const FRAMES` and its `assert_eq!(got.y`, which reported all | |
| 2166 | + // 48 sites as pixel-comparing with a spec in scope -- the same | |
| 2167 | + // over-broad-scope bug the class keeps teaching. | |
| 2168 | + // Brace-depth walk, not `find("\n }")`: a gate with an | |
| 2169 | + // early 4-space `}` (a bare block, a `match` arm tail) truncated | |
| 2170 | + // the slice and made the compare-detection read false. | |
| 2171 | + // STRING-AWARE brace walk. Counting raw bytes counts a `}` | |
| 2172 | + // inside a format string as a closing brace, which truncated the | |
| 2173 | + // body and made every compare-detection read false -- the same | |
| 2174 | + // trap that made stream.rs look 2 braces short in the first | |
| 2175 | + // review of this wave. | |
| 2176 | + let bytes = src.as_bytes(); | |
| 2177 | + let mut depth = 0i32; | |
| 2178 | + let mut started = false; | |
| 2179 | + let mut fn_end = src.len(); | |
| 2180 | + let mut in_str = false; | |
| 2181 | + let mut in_line_comment = false; | |
| 2182 | + let mut k = fn_start; | |
| 2183 | + while k < bytes.len() { | |
| 2184 | + let c = bytes[k]; | |
| 2185 | + if in_line_comment { | |
| 2186 | + if c == b'\n' { | |
| 2187 | + in_line_comment = false; | |
| 2188 | + } | |
| 2189 | + k += 1; | |
| 2190 | + continue; | |
| 2191 | + } | |
| 2192 | + if in_str { | |
| 2193 | + if c == b'\\' { | |
| 2194 | + k += 2; | |
| 2195 | + continue; | |
| 2196 | + } | |
| 2197 | + if c == b'"' { | |
| 2198 | + in_str = false; | |
| 2199 | + } | |
| 2200 | + k += 1; | |
| 2201 | + continue; | |
| 2202 | + } | |
| 2203 | + match c { | |
| 2204 | + b'"' => in_str = true, | |
| 2205 | + b'/' if bytes.get(k + 1) == Some(&b'/') => { | |
| 2206 | + in_line_comment = true; | |
| 2207 | + k += 1; | |
| 2208 | + } | |
| 2209 | + b'{' => { | |
| 2210 | + depth += 1; | |
| 2211 | + started = true; | |
| 2212 | + } | |
| 2213 | + b'}' => { | |
| 2214 | + depth -= 1; | |
| 2215 | + if started && depth == 0 { | |
| 2216 | + fn_end = k + 1; | |
| 2217 | + break; | |
| 2218 | + } | |
| 2219 | + } | |
| 2220 | + _ => {} | |
| 2221 | + } | |
| 2222 | + k += 1; | |
| 2223 | + } | |
| 2224 | + let body = &src[fn_start..fn_end]; | |
| 2225 | + // APPROXIMATE, and known to be so: the body slice is a | |
| 2226 | + // hand-rolled brace walk, and this crate's compare idioms vary | |
| 2227 | + // enough that the column under-reports. The LINE, GATE and | |
| 2228 | + // COUNT EXPR columns are exact (line-based scan, no body | |
| 2229 | + // slicing); treat `pixel_comparing` as a hint, not a verdict. | |
| 2230 | + // Idiom-tolerant: this crate spells the compare every which way | |
| 2231 | + // (`assert_eq!(got.y, want.y)`, `assert_eq!(g, w)`, | |
| 2232 | + // `let ok = ours.y == ref_f.y`, `ours.y, want.y`), so match the | |
| 2233 | + // PLANE inside an assertion, not one fixed spelling. | |
| 2234 | + let pixel_comparing = body.contains("assert") | |
| 2235 | + && (body.contains(".y,") | |
| 2236 | + || body.contains(".y ==") | |
| 2237 | + || body.contains(".y)") | |
| 2238 | + || body.contains("vs ffmpeg")); | |
| 2239 | + // A SPEC already in scope for this gate? | |
| 2240 | + let mut fixable = None; | |
| 2241 | + for cand in ["FRAMES", "frame_count", "NFRAMES", "frames_expected"] { | |
| 2242 | + if body.contains(&format!("const {cand}")) | |
| 2243 | + || body.contains(&format!("let {cand}")) | |
| 2122 | 2244 | { |
| 2123 | - pinned = Some(prev.trim().chars().take(90).collect()); | |
| 2245 | + fixable = Some(cand.to_string()); | |
| 2124 | 2246 | break; |
| 2125 | 2247 | } |
| 2126 | 2248 | } |
| @@ -2129,6 +2251,8 @@ mod count_vacuity { | ||
| 2129 | 2251 | gate: gate.clone(), |
| 2130 | 2252 | count_expr: last.to_string(), |
| 2131 | 2253 | pinned_by: pinned, |
| 2254 | + pixel_comparing, | |
| 2255 | + fixable_from: fixable, | |
| 2132 | 2256 | }); |
| 2133 | 2257 | } |
| 2134 | 2258 | } |
| @@ -2185,9 +2309,20 @@ mod count_vacuity_tests { | ||
| 2185 | 2309 | pinned, |
| 2186 | 2310 | unpinned.len() |
| 2187 | 2311 | ); |
| 2188 | - for line in unpinned.iter().take(12) { | |
| 2312 | + for line in unpinned.iter() { | |
| 2189 | 2313 | eprintln!(" {line}"); |
| 2190 | 2314 | } |
| 2315 | + // The table Main asked for, as columns the guard itself computes. | |
| 2316 | + for x in s.iter().filter(|x| x.pinned_by.is_none()) { | |
| 2317 | + eprintln!( | |
| 2318 | + "ROW {} | {} | {} | pixel_comparing={} | spec_in_scope={}", | |
| 2319 | + x.line, | |
| 2320 | + x.gate, | |
| 2321 | + x.count_expr, | |
| 2322 | + x.pixel_comparing, | |
| 2323 | + x.fixable_from.clone().unwrap_or_else(|| "-".into()) | |
| 2324 | + ); | |
| 2325 | + } | |
| 2191 | 2326 | assert!( |
| 2192 | 2327 | !s.is_empty() && s.iter().all(|x| !x.gate.is_empty()), |
| 2193 | 2328 | "a site has no owning gate -- the sweep's gate attribution is broken" |
crates/ec-av1/src/stream.rsmodified+81 -6
| @@ -5290,6 +5290,57 @@ pub(crate) mod tests { | ||
| 5290 | 5290 | } |
| 5291 | 5291 | |
| 5292 | 5292 | /// Decodes `frames` concatenated 4:2:0 frames out of one AV1 OBU stream. |
| 5293 | + /// The frame-count diagnostic shared by the three `ffmpeg_decode_sequence*` | |
| 5294 | + /// helpers (lane-av1pins5 r6). | |
| 5295 | + /// | |
| 5296 | + /// Before this, a caller that passed its OWN decode's length as the expected | |
| 5297 | + /// count got `expected N 4:2:0 frames, ffmpeg said: ` -- with an EMPTY tail, | |
| 5298 | + /// because ffmpeg ran at `-v error` and succeeded. The message named ffmpeg, | |
| 5299 | + /// said nothing about where `N` came from, and sent the next reader hunting | |
| 5300 | + /// ffmpeg for a count ffmpeg never chose. | |
| 5301 | + /// | |
| 5302 | + /// The class is MISATTRIBUTED RED, not silent pass: the helper's | |
| 5303 | + /// `out.stdout.len() == frame_bytes * frames` assert fires unconditionally, so | |
| 5304 | + /// a wrong count cannot pass -- it just fails while blaming the wrong | |
| 5305 | + /// component. (Measured: `ffmpeg_decode_sequence(&s, 192, 128, 0)` panics | |
| 5306 | + /// here, not silently.) Naming the real cause is the whole fix; no caller has | |
| 5307 | + /// to change to benefit. | |
| 5308 | + fn frame_count_diagnosis( | |
| 5309 | + format: &str, | |
| 5310 | + frames: usize, | |
| 5311 | + width: usize, | |
| 5312 | + height: usize, | |
| 5313 | + frame_bytes: usize, | |
| 5314 | + got: usize, | |
| 5315 | + stderr: &[u8], | |
| 5316 | + ) -> String { | |
| 5317 | + let actual = if frame_bytes == 0 { | |
| 5318 | + 0 | |
| 5319 | + } else { | |
| 5320 | + got / frame_bytes | |
| 5321 | + }; | |
| 5322 | + let leftover = if frame_bytes == 0 { | |
| 5323 | + got | |
| 5324 | + } else { | |
| 5325 | + got % frame_bytes | |
| 5326 | + }; | |
| 5327 | + format!( | |
| 5328 | + "FRAME COUNT MISMATCH ({format} {width}x{height}): the caller passed \ | |
| 5329 | + `frames={frames}`, ffmpeg produced {actual} frame(s) ({got} bytes, \ | |
| 5330 | + {leftover} byte(s) not a whole frame, at {frame_bytes} B/frame).\n\ | |
| 5331 | + `frames` is the EXPECTED count the CALLER asserted -- it is NOT measured \ | |
| 5332 | + from ffmpeg, so it never had ffmpeg's agreement. If it came from our own \ | |
| 5333 | + decode_stream(), this is OUR decoder disagreeing with ffmpeg about how many \ | |
| 5334 | + frames the stream holds, and the fix is on OUR side, not ffmpeg's. ffmpeg \ | |
| 5335 | + itself exited cleanly{}.", | |
| 5336 | + if stderr.is_empty() { | |
| 5337 | + " with no diagnostics (`-v error`)" | |
| 5338 | + } else { | |
| 5339 | + "" | |
| 5340 | + } | |
| 5341 | + ) | |
| 5342 | + } | |
| 5343 | + | |
| 5293 | 5344 | fn ffmpeg_decode_sequence( |
| 5294 | 5345 | stream: &[u8], |
| 5295 | 5346 | width: usize, |
| @@ -5312,8 +5363,16 @@ pub(crate) mod tests { | ||
| 5312 | 5363 | assert_eq!( |
| 5313 | 5364 | out.stdout.len(), |
| 5314 | 5365 | frame_bytes * frames, |
| 5315 | - "expected {frames} 4:2:0 frames, ffmpeg said: {}", | |
| 5316 | - String::from_utf8_lossy(&out.stderr) | |
| 5366 | + "{}", | |
| 5367 | + frame_count_diagnosis( | |
| 5368 | + "4:2:0", | |
| 5369 | + frames, | |
| 5370 | + width, | |
| 5371 | + height, | |
| 5372 | + frame_bytes, | |
| 5373 | + out.stdout.len(), | |
| 5374 | + &out.stderr | |
| 5375 | + ) | |
| 5317 | 5376 | ); |
| 5318 | 5377 | (0..frames) |
| 5319 | 5378 | .map(|i| { |
| @@ -5406,8 +5465,16 @@ pub(crate) mod tests { | ||
| 5406 | 5465 | assert_eq!( |
| 5407 | 5466 | out.stdout.len(), |
| 5408 | 5467 | frame_bytes * frames, |
| 5409 | - "expected {frames} 4:2:0 10-bit frames, ffmpeg said: {}", | |
| 5410 | - String::from_utf8_lossy(&out.stderr) | |
| 5468 | + "{}", | |
| 5469 | + frame_count_diagnosis( | |
| 5470 | + "4:2:0 10-bit", | |
| 5471 | + frames, | |
| 5472 | + width, | |
| 5473 | + height, | |
| 5474 | + frame_bytes, | |
| 5475 | + out.stdout.len(), | |
| 5476 | + &out.stderr | |
| 5477 | + ) | |
| 5411 | 5478 | ); |
| 5412 | 5479 | fn le16(bytes: &[u8]) -> Vec<u16> { |
| 5413 | 5480 | bytes |
| @@ -6811,8 +6878,16 @@ pub(crate) mod tests { | ||
| 6811 | 6878 | assert_eq!( |
| 6812 | 6879 | out.stdout.len(), |
| 6813 | 6880 | frame_bytes * frames, |
| 6814 | - "expected {frames} 4:4:4 frames, ffmpeg said: {}", | |
| 6815 | - String::from_utf8_lossy(&out.stderr) | |
| 6881 | + "{}", | |
| 6882 | + frame_count_diagnosis( | |
| 6883 | + "4:4:4", | |
| 6884 | + frames, | |
| 6885 | + width, | |
| 6886 | + height, | |
| 6887 | + frame_bytes, | |
| 6888 | + out.stdout.len(), | |
| 6889 | + &out.stderr | |
| 6890 | + ) | |
| 6816 | 6891 | ); |
| 6817 | 6892 | (0..frames) |
| 6818 | 6893 | .map(|i| { |