Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/coverage_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def main(argv=None):
if args.threads:
cmd += ["--threads", str(args.threads)]
proc = subprocess.run(cmd, capture_output=True, text=True)
if proc.returncode != 0:
print(f"shader sweep exited with {proc.returncode}\n{proc.stdout[-2000:]}\n{proc.stderr[-2000:]}", file=sys.stderr)
return 2
try:
run = sweep_json(proc.stdout)
except ValueError as e:
Expand Down
38 changes: 37 additions & 1 deletion scripts/test_coverage_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import contextlib
import io
import json
import subprocess
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch

from coverage_gate import compare, sweep_json
from coverage_gate import compare, main, sweep_json

STAGES = {
"CS": {"total": 100, "translated": 95, "unsupported": 5, "validator_failed": 0, "panicked": 0, "timeout": 0},
Expand Down Expand Up @@ -68,5 +73,36 @@ def test_raises_without_a_report(self):
sweep_json("no json here")


class LiveSweepTests(unittest.TestCase):
def test_failed_child_cannot_pass_comparison_or_replace_baseline(self):
with tempfile.TemporaryDirectory() as tmp:
baseline = Path(tmp) / "baseline.json"
original = json.dumps(run()).encode("utf-8")
baseline.write_bytes(original)
args = ["--xcl", "synthetic-xcl", "--rpf", "synthetic-pack", "--baseline", str(baseline)]
for extra in ([], ["--update"]):
with self.subTest(args=extra):
child = subprocess.CompletedProcess([], 23, json.dumps(run()), "sweep failed")
out, err = io.StringIO(), io.StringIO()
with patch("coverage_gate.subprocess.run", return_value=child), \
contextlib.redirect_stdout(out), contextlib.redirect_stderr(err):
self.assertEqual(main(args + extra), 2)
self.assertIn("23", err.getvalue())
self.assertIn("sweep failed", err.getvalue())
self.assertEqual(out.getvalue(), "")
self.assertEqual(baseline.read_bytes(), original)

def test_successful_child_report_is_compared(self):
with tempfile.TemporaryDirectory() as tmp:
baseline = Path(tmp) / "baseline.json"
baseline.write_text(json.dumps(run()), encoding="utf-8")
args = ["--xcl", "synthetic-xcl", "--rpf", "synthetic-pack", "--baseline", str(baseline)]
for report, expected in ((run(), 0), (run(CS={"translated": 94, "unsupported": 6}), 1)):
with self.subTest(expected=expected):
child = subprocess.CompletedProcess([], 0, json.dumps(report), "")
with patch("coverage_gate.subprocess.run", return_value=child), contextlib.redirect_stdout(io.StringIO()):
self.assertEqual(main(args), expected)


if __name__ == "__main__":
unittest.main()
Loading