Skip to content
Open
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
5 changes: 4 additions & 1 deletion scripts/coverage_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
translations to unnoticed. The baseline holds counts only: no program names, no game data.

python scripts/coverage_gate.py --xcl target/release/xcl.exe --rpf PACK [--threads N]
python scripts/coverage_gate.py --update ... rewrite the baseline from a fresh sweep
python scripts/coverage_gate.py --update ... rewrite the baseline from a sweep with at least one stage
python scripts/coverage_gate.py --run-json F compare a saved sweep (no game needed)
"""
import argparse
Expand Down Expand Up @@ -75,6 +75,9 @@ def main(argv=None):
print(f"{e}\n{proc.stdout[-2000:]}\n{proc.stderr[-2000:]}", file=sys.stderr)
return 2
if args.update:
if not run["stages"]:
print("cannot update baseline: sweep contains no shader stages", file=sys.stderr)
return 2
args.baseline.parent.mkdir(parents=True, exist_ok=True)
args.baseline.write_text(json.dumps({"stages": run["stages"]}, indent=1, sort_keys=True) + "\n", encoding="utf-8")
print(f"baseline written: {args.baseline}")
Expand Down
30 changes: 29 additions & 1 deletion scripts/test_coverage_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory

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 +69,32 @@ def test_raises_without_a_report(self):
sweep_json("no json here")


class BaselineUpdateTests(unittest.TestCase):
def test_empty_sweep_preserves_existing_baseline(self):
with TemporaryDirectory() as directory:
baseline = Path(directory) / "baseline.json"
report = Path(directory) / "run.json"
original = json.dumps({"stages": STAGES}).encode()
baseline.write_bytes(original)
report.write_text('{"stages": {}}', encoding="utf-8")

result = main(["--update", "--run-json", str(report), "--baseline", str(baseline)])

self.assertEqual(result, 2)
self.assertEqual(baseline.read_bytes(), original)

def test_populated_sweep_updates_baseline(self):
with TemporaryDirectory() as directory:
baseline = Path(directory) / "baseline.json"
report = Path(directory) / "run.json"
baseline.write_text('{"stages": {}}', encoding="utf-8")
report.write_text(json.dumps(run()), encoding="utf-8")

result = main(["--update", "--run-json", str(report), "--baseline", str(baseline)])

self.assertEqual(result, 0)
self.assertEqual(json.loads(baseline.read_text(encoding="utf-8")), {"stages": STAGES})


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