Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

test(verify): never count an unmeasurable class as fixed

Richie McIlroy3363f39ff147
diff --git a/crates/rendering/src/decoder/model/mod.rs b/crates/rendering/src/decoder/model/mod.rs
index a6c6bc01c..178038522 100644
--- a/crates/rendering/src/decoder/model/mod.rs
+++ b/crates/rendering/src/decoder/model/mod.rs
@@ -760,6 +760,7 @@ fn write_records(
outcome,
failures,
seeds_ran: ran.get(&result.name).cloned().flatten(),
+ unobserved: Default::default(),
problems,
summary: summary.join("\n"),
repro,
diff --git a/crates/verify-expect/src/lib.rs b/crates/verify-expect/src/lib.rs
index 15796f9cc..f623b92e6 100644
--- a/crates/verify-expect/src/lib.rs
+++ b/crates/verify-expect/src/lib.rs
@@ -391,8 +391,26 @@ fn covered_by<'a>(
covered
}
+/// Classes a case could not measure because an earlier check failed (for
+/// example A/V sync when no audio marker could be identified): `(case,
+/// class)`. An unobserved class is neither a failure nor a pass, so an xfail
+/// for it is not reported as fixed and `bless` leaves it alone. The failure
+/// that made it unobservable is judged on its own.
+pub type Unobserved = BTreeSet<(String, String)>;
+
/// Compares the failures of a run with the expectations, on `platform`.
pub fn judge(xfails: &[Xfail], platform: &str, ran: &Ran, observed: &Observed) -> Verdict {
+ judge_observing(xfails, platform, ran, observed, &Unobserved::new())
+}
+
+/// [`judge`] for runs where some classes could not be measured.
+pub fn judge_observing(
+ xfails: &[Xfail],
+ platform: &str,
+ ran: &Ran,
+ observed: &Observed,
+ unobserved: &Unobserved,
+) -> Verdict {
let mut verdict = Verdict::default();
for ((case, class), seeds) in observed {
let has_entry = xfails
@@ -418,6 +436,9 @@ pub fn judge(xfails: &[Xfail], platform: &str, ran: &Ran, observed: &Observed) -
}
for x in xfails.iter().filter(|x| !x.flaky && x.applies_on(platform)) {
for (case, ran_seeds) in ran.iter().filter(|(case, _)| glob_match(&x.case, case)) {
+ if unobserved.contains(&(case.clone(), x.class.clone())) {
+ continue;
+ }
let seen = observed.get(&(case.clone(), x.class.clone()));
let seeds = match (&x.seeds, seen) {
(None, None) => None,
@@ -455,6 +476,26 @@ pub fn bless(
ran: &Ran,
observed: &Observed,
problems: &BTreeMap<(String, String), String>,
+) -> Vec<Xfail> {
+ bless_observing(
+ xfails,
+ platform,
+ ran,
+ observed,
+ &Unobserved::new(),
+ problems,
+ )
+}
+
+/// [`bless`] that keeps entries whose class some matching case could not
+/// measure in this run.
+pub fn bless_observing(
+ xfails: &[Xfail],
+ platform: &str,
+ ran: &Ran,
+ observed: &Observed,
+ unobserved: &Unobserved,
+ problems: &BTreeMap<(String, String), String>,
) -> Vec<Xfail> {
let mut out: Vec<Xfail> = Vec::new();
let mut kept_here: Vec<Xfail> = Vec::new();
@@ -463,7 +504,10 @@ pub fn bless(
.iter()
.filter(|(case, _)| glob_match(&x.case, case))
.collect();
- if !x.applies_on(platform) || matched.is_empty() || x.flaky {
+ let unmeasured = matched
+ .iter()
+ .any(|(case, _)| unobserved.contains(&((*case).clone(), x.class.clone())));
+ if !x.applies_on(platform) || matched.is_empty() || x.flaky || unmeasured {
out.push(x.clone());
if x.applies_on(platform) {
kept_here.push(x.clone());
@@ -626,6 +670,9 @@ pub struct Record {
/// Seeds that ran, for seeded cases.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub seeds_ran: Option<BTreeSet<u64>>,
+ /// Classes this case could not measure -> why (see [`Unobserved`]).
+ #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
+ pub unobserved: BTreeMap<String, String>,
/// First problem per class, used as the draft reason when blessing.
#[serde(default)]
pub problems: BTreeMap<String, String>,
@@ -723,6 +770,7 @@ mod tests {
outcome: Outcome::Unsupported,
failures: BTreeMap::new(),
seeds_ran: None,
+ unobserved: BTreeMap::new(),
problems: BTreeMap::new(),
summary: "test record".repeat(100),
repro: String::new(),
@@ -814,6 +862,37 @@ mod tests {
assert_eq!(verdict.fixed[0].seeds, Some(set(&[1])));
}
+ #[test]
+ fn unobserved_classes_are_neither_fixed_nor_blessed_away() {
+ let xfails = vec![
+ entry("a", "sync", &[], None),
+ entry("a", "audio", &[], None),
+ ];
+ let ran = Ran::from([("a".to_string(), None)]);
+ let observed = Observed::from([(("a".into(), "audio".into()), set(&[]))]);
+ let unobserved = Unobserved::from([("a".to_string(), "sync".to_string())]);
+ assert!(judge_observing(&xfails, "linux", &ran, &observed, &unobserved).ok());
+ let measured = judge(&xfails, "linux", &ran, &observed);
+ assert_eq!(measured.fixed.len(), 1);
+ assert_eq!(measured.fixed[0].xfail.class, "sync");
+ let blessed = bless_observing(
+ &xfails,
+ "linux",
+ &ran,
+ &observed,
+ &unobserved,
+ &BTreeMap::new(),
+ );
+ assert_eq!(blessed, coalesce(xfails.clone()));
+ let unexpected = Observed::from([(("a".into(), "audio".into()), set(&[]))]);
+ let verdict = judge_observing(&[], "linux", &ran, &unexpected, &unobserved);
+ assert_eq!(
+ verdict.unexpected.len(),
+ 1,
+ "the prerequisite failure still fails"
+ );
+ }
+
#[test]
fn seeds_that_did_not_run_are_not_fixed() {
let xfails = vec![entry("a", "stale", &[], Some(&[1, 50]))];
diff --git a/crates/verify-expect/src/main.rs b/crates/verify-expect/src/main.rs
index f058fffb8..bf092825b 100644
--- a/crates/verify-expect/src/main.rs
+++ b/crates/verify-expect/src/main.rs
@@ -11,7 +11,9 @@ use std::{
process::ExitCode,
};
-use cap_verify_expect::{Observed, Outcome, Ran, Record, bless, header, load, parse, render};
+use cap_verify_expect::{
+ Observed, Outcome, Ran, Record, Unobserved, bless_observing, header, load, parse, render,
+};
fn collect(path: &Path, out: &mut Vec<PathBuf>) {
if path.is_dir() {
@@ -38,6 +40,7 @@ fn repo_root() -> PathBuf {
struct Run {
ran: Ran,
observed: Observed,
+ unobserved: Unobserved,
problems: BTreeMap<(String, String), String>,
}
@@ -73,6 +76,9 @@ fn bless_command(inputs: &[String]) -> ExitCode {
if let Some(seeds) = &record.seeds_ran {
ran.get_or_insert_with(BTreeSet::new).extend(seeds);
}
+ for class in record.unobserved.keys() {
+ run.unobserved.insert((record.case.clone(), class.clone()));
+ }
for (class, seeds) in &record.failures {
run.observed
.entry((record.case.clone(), class.clone()))
@@ -93,7 +99,14 @@ fn bless_command(inputs: &[String]) -> ExitCode {
let before = load(&path);
let mut entries = before.clone();
for (platform, run) in platforms {
- entries = bless(&entries, platform, &run.ran, &run.observed, &run.problems);
+ entries = bless_observing(
+ &entries,
+ platform,
+ &run.ran,
+ &run.observed,
+ &run.unobserved,
+ &run.problems,
+ );
}
let added = entries.iter().filter(|e| !before.contains(e)).count();
let removed = before.iter().filter(|e| !entries.contains(e)).count();
diff --git a/crates/verify/README.md b/crates/verify/README.md
index 06939b30a..2a1d9c0e3 100644
--- a/crates/verify/README.md
+++ b/crates/verify/README.md
@@ -89,6 +89,11 @@ link = "https://github.com/CapSoftware/Cap/pull/2595" # empty = no fix yet
- A listed class or seed that no longer fails also fails the run, with
"remove this xfail". When a fix lands, its expected failures must be removed
in the same PR, so the fix is locked in.
+- A class that cannot be measured because an earlier check failed (A/V sync
+ when no audio marker of a source could be identified) is recorded as "not
+ measured", never as a pass: its xfail is neither confirmed nor reported as
+ fixed, and bless leaves it alone. The failure that prevented the measurement
+ is judged on its own, so it still has to be listed.
To update the files after a deliberate change, run:
diff --git a/crates/verify/src/pipeline.rs b/crates/verify/src/pipeline.rs
index 3a5fc462c..18d8fc484 100644
--- a/crates/verify/src/pipeline.rs
+++ b/crates/verify/src/pipeline.rs
@@ -476,6 +476,10 @@ pub struct Emitted {
pub fps: u32,
/// (source, marker index, chirp time) of every audio marker.
pub audio: Vec<(AudioSource, u32, f64)>,
+ /// (slot, time the frame was actually handed to the pipeline), to tell a
+ /// late emitter (a starved test runtime) from late processing.
+ #[serde(default)]
+ pub screen_sent: Vec<(u32, f64)>,
}
pub async fn record_instant(spec: &InstantSpec, dir: &Path) -> anyhow::Result<()> {
@@ -511,6 +515,7 @@ pub async fn record_instant(spec: &InstantSpec, dir: &Path) -> anyhow::Result<()
}
let (fps, width, height, delay) = (video.fps, video.width, video.height, video.start_delay);
let video_emit = tokio::spawn(async move {
+ let mut sent = Vec::new();
for slot in slots {
let t = delay + f64::from(slot) / f64::from(fps);
let at = base + Duration::from_secs_f64(t);
@@ -522,7 +527,9 @@ pub async fn record_instant(spec: &InstantSpec, dir: &Path) -> anyhow::Result<()
if tx.send_async(frame).await.is_err() {
break;
}
+ sent.push((slot, base.elapsed().as_secs_f64()));
}
+ sent
});
let mut video_builder = OutputPipeline::builder(content.join("display"))
.with_video::<ChannelVideoSource<FFmpegVideoFrame>>(ChannelVideoSourceConfig::new(info, rx))
@@ -654,7 +661,7 @@ pub async fn record_instant(spec: &InstantSpec, dir: &Path) -> anyhow::Result<()
tokio::time::sleep_until((base + Duration::from_secs_f64(arm_at)).into()).await;
gate.arm();
}
- video_emit.await.context("video emit")?;
+ emitted.screen_sent = video_emit.await.context("video emit")?;
let mut held = Vec::new();
for emit in audio_emits {
held.push(emit.await.context("audio emit")?);
diff --git a/crates/verify/src/report.rs b/crates/verify/src/report.rs
index d67618c45..9ac742457 100644
--- a/crates/verify/src/report.rs
+++ b/crates/verify/src/report.rs
@@ -67,6 +67,9 @@ pub struct Case {
/// First problem per class (the draft reason when blessing).
class_problems: BTreeMap<String, String>,
pub notes: Vec<String>,
+ /// Classes this case could not measure because an earlier check failed
+ /// -> why (see `cap_verify_expect::Unobserved`).
+ pub unobserved: BTreeMap<String, String>,
/// Set when this runner cannot run the case at all (for example no
/// D3D11 video device for Media Foundation on a GPU-less Windows VM).
pub unsupported: Option<String>,
@@ -84,6 +87,7 @@ impl Case {
classes: Default::default(),
class_problems: Default::default(),
notes: Vec::new(),
+ unobserved: Default::default(),
unsupported: None,
}
}
@@ -114,6 +118,16 @@ impl Case {
self.problems.push(text);
}
+ /// Records that `class` could not be measured because the check it
+ /// depends on failed. The case must also report that failure: an
+ /// unobserved class never makes a case pass, it only stops an expected
+ /// failure of `class` from counting as fixed.
+ pub fn unobserved(&mut self, class: &str, why: impl Into<String>) {
+ self.unobserved
+ .entry(class.to_string())
+ .or_insert_with(|| why.into());
+ }
+
pub fn note(&mut self, text: impl Into<String>) {
self.notes.push(text.into());
}
@@ -184,7 +198,11 @@ pub fn selected(id: &str) -> bool {
cap_verify_expect::case_selected(id)
}
-fn write_result(result: &CaseResult, classes: &BTreeMap<String, String>) {
+fn write_result(
+ result: &CaseResult,
+ classes: &BTreeMap<String, String>,
+ unobserved: &BTreeMap<String, String>,
+) {
use cap_verify_expect::{Outcome, Record};
let record = Record {
suite: "cap-verify".into(),
@@ -207,6 +225,7 @@ fn write_result(result: &CaseResult, classes: &BTreeMap<String, String>) {
.map(|class| (class.clone(), Default::default()))
.collect(),
seeds_ran: None,
+ unobserved: unobserved.clone(),
problems: classes.clone(),
summary: result.summary.clone(),
repro: result.repro.clone(),
@@ -221,7 +240,23 @@ fn write_result(result: &CaseResult, classes: &BTreeMap<String, String>) {
/// Settles a case against the expectations file. Returns an error message
/// when the test must fail.
-pub fn settle(case: Case) -> Result<CaseResult, String> {
+pub fn settle(mut case: Case) -> Result<CaseResult, String> {
+ let measured: Vec<String> = case
+ .unobserved
+ .keys()
+ .filter(|class| case.classes.contains(*class))
+ .cloned()
+ .collect();
+ for class in measured {
+ case.unobserved.remove(&class);
+ }
+ if !case.unobserved.is_empty() && !case.failed() {
+ let classes: Vec<&String> = case.unobserved.keys().collect();
+ case.problem(
+ "harness",
+ format!("{classes:?} reported unmeasurable without the failure that prevented it"),
+ );
+ }
let xfails = xfails_for(&case.id);
let failed = case.failed();
let repro = repro_command(&case.id);
@@ -232,7 +267,13 @@ pub fn settle(case: Case) -> Result<CaseResult, String> {
.iter()
.map(|class| ((case.id.clone(), class.clone()), Default::default()))
.collect();
- let verdict = cap_verify_expect::judge(&xfails, platform, &ran, &observed);
+ let unobserved: cap_verify_expect::Unobserved = case
+ .unobserved
+ .keys()
+ .map(|class| (case.id.clone(), class.clone()))
+ .collect();
+ let verdict =
+ cap_verify_expect::judge_observing(&xfails, platform, &ran, &observed, &unobserved);
let unexpected: Vec<&String> = verdict.unexpected.iter().map(|u| &u.class).collect();
let fixed: Vec<&Xfail> = verdict.fixed.iter().map(|f| &f.xfail).collect();
let outcome = if case.unsupported.is_some() && !failed {
@@ -258,6 +299,9 @@ pub fn settle(case: Case) -> Result<CaseResult, String> {
.collect();
format!("all checks passed: {}", streams.join(", "))
};
+ for (class, why) in &case.unobserved {
+ summary.push_str(&format!("\n ({class} not measured: {why})"));
+ }
for x in &xfails {
summary.push_str(&format!(
"\n (expected {}{}: {} {})",
@@ -279,7 +323,7 @@ pub fn settle(case: Case) -> Result<CaseResult, String> {
repro: repro.clone(),
outcome: outcome.to_string(),
};
- write_result(&result, &case.class_problems);
+ write_result(&result, &case.class_problems, &case.unobserved);
eprintln!(
"[cap-verify] {outcome} {} in {:.1}s\n {summary}",
result.id, result.seconds
diff --git a/crates/verify/tests/export.rs b/crates/verify/tests/export.rs
index 03954ff1f..23850c57d 100644
--- a/crates/verify/tests/export.rs
+++ b/crates/verify/tests/export.rs
@@ -460,15 +460,18 @@ fn instant_case(spec: cap_verify::pipeline::InstantSpec) -> Option<String> {
),
);
}
- let emit_time = |slot: u32| {
- emitted
- .screen
- .iter()
- .find(|e| e.0 == slot)
- .map(|e| e.1)
- .unwrap_or(f64::NAN)
- };
- let video_offsets: Vec<f64> = shown.iter().map(|&(pts, s)| pts - emit_time(s)).collect();
+ // Frames within the start gate's margin have no recorded emit time and
+ // are not timed.
+ let video_offsets: Vec<f64> = shown
+ .iter()
+ .filter_map(|&(pts, slot)| {
+ emitted
+ .screen
+ .iter()
+ .find(|e| e.0 == slot)
+ .map(|e| pts - e.1)
+ })
+ .collect();
let spread = |v: &[f64]| {
let lo = v.iter().copied().fold(f64::INFINITY, f64::min);
let hi = v.iter().copied().fold(f64::NEG_INFINITY, f64::max);
@@ -480,9 +483,31 @@ fn instant_case(spec: cap_verify::pipeline::InstantSpec) -> Option<String> {
v.get(v.len() / 2).copied().unwrap_or(f64::NAN)
};
let frame = 1.0 / f64::from(emitted.fps);
+ if video_offsets.is_empty() {
+ case.problem(
+ "dropped",
+ "no emitted screen frame identified in the output",
+ );
+ case.unobserved("timestamps", "no emitted screen frame identified");
+ case.unobserved("sync", "no emitted screen frame identified");
+ }
let video_spread = spread(&video_offsets);
case.note(format!("video timing spread {:.2} ms", video_spread * 1e3));
- if video_spread > frame / 2.0 {
+ let late = emitted
+ .screen_sent
+ .iter()
+ .filter_map(|&(slot, sent)| {
+ let planned = emitted.screen.iter().find(|e| e.0 == slot)?.1;
+ Some((slot, sent - planned))
+ })
+ .max_by(|a, b| a.1.total_cmp(&b.1));
+ if let Some((slot, late)) = late {
+ case.note(format!(
+ "test emitter at most {:.2} ms late (slot {slot})",
+ late * 1e3
+ ));
+ }
+ if !video_offsets.is_empty() && video_spread > frame / 2.0 {
case.problem(
"timestamps",
format!(
@@ -504,6 +529,8 @@ fn instant_case(spec: cap_verify::pipeline::InstantSpec) -> Option<String> {
if expected.is_empty() {
continue;
}
+ // Markers are matched by their decoded identity anywhere in the
+ // track, so an arbitrarily large A/V offset is still measured.
let found = audio_code::locate_markers(&mono, audio.sample_rate, source);
let mut offsets = Vec::new();
let mut absent = Vec::new();
@@ -515,18 +542,53 @@ fn instant_case(spec: cap_verify::pipeline::InstantSpec) -> Option<String> {
}
let extra = found.len().saturating_sub(expected.len() - absent.len());
if !absent.is_empty() || extra > 0 {
+ let undecoded = found.iter().filter(|f| f.index.is_none()).count();
case.problem(
"audio",
format!(
- "{}: {} markers missing (first {:?}), {} unexpected",
+ "{}: {} markers missing (first {:?}), {} unexpected ({} chirps without a decodable identity)",
source.name(),
absent.len(),
&absent[..absent.len().min(5)],
- extra
+ extra,
+ undecoded
),
);
+ let listed: Vec<String> = found
+ .iter()
+ .take(16)
+ .map(|f| {
+ format!(
+ "{:.4}s {} corr {:.2} gain {:.3}",
+ f.time_secs + audio.start_secs,
+ f.index.map_or("undecoded".to_string(), |i| format!("#{i}")),
+ f.correlation,
+ f.gain
+ )
+ })
+ .collect();
+ case.note(format!(
+ "{} chirps found: [{}]; expected {:?}",
+ source.name(),
+ listed.join(", "),
+ expected
+ .iter()
+ .map(|&(i, t)| format!("#{i} {t:.4}s"))
+ .collect::<Vec<_>>()
+ ));
}
if offsets.is_empty() {
+ case.unobserved(
+ "sync",
+ format!(
+ "{}: none of the {} expected markers was identified in the output",
+ source.name(),
+ expected.len()
+ ),
+ );
+ continue;
+ }
+ if video_offsets.is_empty() {
continue;
}
let av = median(&offsets) - median(&video_offsets);
diff --git a/scripts/verify/summary.py b/scripts/verify/summary.py
index 9c5cab1f8..e93099526 100755
--- a/scripts/verify/summary.py
+++ b/scripts/verify/summary.py
@@ -109,6 +109,9 @@ def render(records, title, junit, flaky, text):
f"{counts.get('fail', 0)} FAILED, {counts.get('xpass', 0)} unexpectedly passing, "
f"{counts.get('unsupported', 0)} unsupported ({seconds:.0f} s of case time)"
)
+ unmeasured = [r for r in records if r.get("unobserved")]
+ if unmeasured:
+ head += f"; {len(unmeasured)} with classes not measured because an earlier check failed"
recorded = {r["case"] for r in records}
crashed = [(name, msg) for name, msg in junit if not any(c in msg for c in recorded)]
out = []
@@ -170,6 +173,9 @@ def render(records, title, junit, flaky, text):
out.append("| --- | --- | --- |")
for r in xfails:
classes = ", ".join(sorted((r.get("failures") or {}).keys())) or "-"
+ unmeasured = sorted((r.get("unobserved") or {}).keys())
+ if unmeasured:
+ classes += f" (not measured: {', '.join(unmeasured)})"
summary = (r.get("summary") or "").splitlines()[0:1]
summary = summary[0].replace("|", "\\|")[:200] if summary else ""
out.append(f"| `{r['case']}` | {classes} | {summary} |")