Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(scripts): refuse binaries inside the work directory and playback runs with failed frames

Marcos Daniel Rivera Gonzaleze00c11ee31ed
diff --git a/scripts/capbench.py b/scripts/capbench.py
index 5bdf2374c..bda164fed 100644
--- a/scripts/capbench.py
+++ b/scripts/capbench.py
@@ -327,6 +327,13 @@ def parse_playback_pipeline(lines):
"scrub_p50_ms": scrub.get("Total (decode+render)", {}).get("p50"),
"scrub_p95_ms": scrub.get("Total (decode+render)", {}).get("p95"),
}
+ failed = sum(
+ int(match.group(1))
+ for _, line in lines
+ if (match := re.match(r"(?:Decode|Render) failures:\s*(\d+)", line.strip()))
+ )
+ if failed:
+ raise InvalidRun(f"playback-pipeline-benchmark reported {failed} failed frames")
return {key: value for key, value in metrics.items() if value is not None}
@@ -604,6 +611,9 @@ def cmd_run(args):
work = out_root / "work"
if ctx.source_fixture.is_relative_to(work) or work.is_relative_to(ctx.source_fixture):
sys.exit(f"--fixture {ctx.source_fixture} and the work directory {work} overlap; the work directory is deleted before each run")
+ for label, bin_dir in variants:
+ if Path(bin_dir).resolve().is_relative_to(work):
+ sys.exit(f"binaries for {label} ({bin_dir}) are inside the work directory {work}, which is deleted before each run")
for _, bin_dir in variants:
ctx.bin_dir = Path(bin_dir).resolve()
try:
diff --git a/scripts/test-capbench.py b/scripts/test-capbench.py
index d6b60c01c..38c32b185 100644
--- a/scripts/test-capbench.py
+++ b/scripts/test-capbench.py
@@ -85,6 +85,11 @@ class CapbenchTests(unittest.TestCase):
self.assertEqual(metrics["scrub_p50_ms"], 93.93)
self.assertEqual(metrics["scrub_p95_ms"], 141.57)
+ def test_playback_runs_with_failed_frames_are_invalid(self):
+ failed = PLAYBACK_OUTPUT + "\n Decode failures: 3\n Render failures: 1\n"
+ with self.assertRaisesRegex(capbench.InvalidRun, "4 failed frames"):
+ capbench.parse_playback_pipeline(timed(failed))
+
def test_decode_metrics(self):
metrics = capbench.parse_decode(timed(DECODE_OUTPUT))
self.assertEqual(metrics, {
@@ -112,6 +117,21 @@ class CapbenchTests(unittest.TestCase):
capbench.cmd_run(args)
self.assertTrue(fixture.exists())
+ def test_binaries_inside_the_work_directory_are_not_deleted(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ out = Path(tmp) / "out"
+ bins = out / "work" / "build"
+ bins.mkdir(parents=True)
+ fixture = Path(tmp) / "reference.cap"
+ fixture.mkdir()
+ args = SimpleNamespace(
+ bench=["decode-display"], out=str(out), label="run", fixture=str(fixture), bin_dir=str(bins),
+ variant=[], env=[], screen=None, animate=False, affinity=None,
+ )
+ with self.assertRaisesRegex(SystemExit, "inside the work directory"):
+ capbench.cmd_run(args)
+ self.assertTrue(bins.exists())
+
def test_startup_check_finds_missing_helpers(self):
args = SimpleNamespace(fixture=".", bin_dir=str(Path(__file__).parent), screen=None, animate=False, affinity=None)
with self.assertRaisesRegex(FileNotFoundError, "cap-test"):