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
6 changes: 3 additions & 3 deletions scripts/coverage_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
"""Direct-DXIL coverage baseline and gate.

`xcl shaders <pack> --direct --sample 0 --json` sweeps every console program in a shader
pack through the direct translator and prints per-stage outcome counts. Run that sweep (or
`xcl shaders <pack> --direct --validate --sample 0 --json` sweeps every console program in a shader
pack through the direct translator and validator, then prints per-stage outcome counts. Run that sweep (or
hand in its saved JSON) and compare the counts against a committed baseline: a stage that
translated fewer programs than the baseline, or gained validator failures, panicked or
timed out, is a coverage regression - the class of bug a sibling project lost 323 shader
Expand Down Expand Up @@ -65,7 +65,7 @@ def main(argv=None):
else:
if not (args.xcl and args.rpf):
ap.error("--xcl and --rpf are required unless --run-json is given")
cmd = [str(args.xcl), "shaders", str(args.rpf), "--direct", "--sample", "0", "--json"]
cmd = [str(args.xcl), "shaders", str(args.rpf), "--direct", "--validate", "--sample", "0", "--json"]
if args.threads:
cmd += ["--threads", str(args.threads)]
proc = subprocess.run(cmd, capture_output=True, text=True)
Expand Down
18 changes: 17 additions & 1 deletion scripts/test_coverage_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
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 @@ -58,6 +60,20 @@ def test_new_stage_is_a_note(self):
self.assertEqual(notes, ["MS: new stage in the sweep"])


class GateCommandTests(unittest.TestCase):
def test_gate_sweep_enables_validation(self):
with TemporaryDirectory() as directory, patch("coverage_gate.subprocess.run") as run_sweep:
root = Path(directory)
xcl, pack = root / "xcl.exe", root / "shaders.rpf"
xcl.touch()
pack.touch()
run_sweep.return_value.stdout = json.dumps({"stages": STAGES})
run_sweep.return_value.stderr = ""
result = main(["--xcl", str(xcl), "--rpf", str(pack), "--update", "--baseline", str(root / "baseline.json")])
self.assertEqual(result, 0)
self.assertIn("--validate", run_sweep.call_args.args[0])


class SweepJsonTests(unittest.TestCase):
def test_takes_the_last_json_line(self):
out = "some progress\n" + json.dumps({"stages": STAGES, "all": {}}) + "\n"
Expand Down
Loading