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
19 changes: 13 additions & 6 deletions scripts/coverage_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/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 --sample 0 --validate --json` sweeps every console program in a
shader pack through the direct translator, runs DXC's validator on each result and prints
per-stage outcome counts (without `--validate` a release build never validates, so
`validator_failed` would stay 0 whatever the translator emits). 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 @@ -31,6 +33,14 @@ def sweep_json(stdout):
raise ValueError("no JSON report in the sweep output")


def sweep_command(xcl, rpf, threads=None):
"""The sweep the gate runs: every program, each translation through the validator."""
cmd = [str(xcl), "shaders", str(rpf), "--direct", "--sample", "0", "--validate", "--json"]
if threads:
cmd += ["--threads", str(threads)]
return cmd


def compare(baseline, run):
"""(regressions, notes) of a sweep against the baseline; regressions are (stage, why)."""
bad, notes = [], []
Expand Down Expand Up @@ -65,10 +75,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"]
if args.threads:
cmd += ["--threads", str(args.threads)]
proc = subprocess.run(cmd, capture_output=True, text=True)
proc = subprocess.run(sweep_command(args.xcl, args.rpf, args.threads), capture_output=True, text=True)
try:
run = sweep_json(proc.stdout)
except ValueError as e:
Expand Down
13 changes: 12 additions & 1 deletion scripts/test_coverage_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
from pathlib import Path

from coverage_gate import compare, sweep_json
from coverage_gate import compare, sweep_command, sweep_json

STAGES = {
"CS": {"total": 100, "translated": 95, "unsupported": 5, "validator_failed": 0, "panicked": 0, "timeout": 0},
Expand Down Expand Up @@ -58,6 +58,17 @@ def test_new_stage_is_a_note(self):
self.assertEqual(notes, ["MS: new stage in the sweep"])


class SweepCommandTests(unittest.TestCase):
def test_sweep_validates_every_program(self):
# without --validate a release xcl never runs the validator, so validator_failed
# would read 0 in every sweep and the gate could not catch a validator regression
cmd = sweep_command(Path("xcl.exe"), Path("pack.rpf"))
self.assertEqual(cmd, ["xcl.exe", "shaders", "pack.rpf", "--direct", "--sample", "0", "--validate", "--json"])

def test_threads_are_passed_on(self):
self.assertEqual(sweep_command("xcl.exe", "pack.rpf", 4)[-2:], ["--threads", "4"])


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