From 8bc3a383bd8241d6b1e5f9ea629457d6d1c0dcc8 Mon Sep 17 00:00:00 2001 From: alvaroolt Date: Wed, 25 Nov 2026 01:05:31 +0100 Subject: [PATCH] tooling: refuse a missing form_coverage records directory tools/form_coverage.py read --records with Path.glob, which yields nothing for a path that does not exist. A mistyped directory, or the dev default used with a release JUnit file, therefore counted every shader and record-mode form as uncovered and exited 0. With --gaps or --json nothing said why. A --records path that is not a directory is now an error (exit 2). A directory whose records were all written outside the JUnit run is still measured, with a warning on stderr. An empty directory stays silent, because no recording test ran. --- CONTRIBUTING.md | 4 +++ tests/form_coverage_check.py | 51 +++++++++++++++++++++++++++++++++++- tools/form_coverage.py | 17 ++++++++++-- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ca222e7a5..f960f92a10 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,6 +56,10 @@ skipped fixture. An `observed_without_pass` row appears in fixture evidence but has no passing or skipped fixture. An `unobserved` row has no matching evidence in the supplied measurement. A partial run can therefore list forms exercised elsewhere. Check current fixtures and open PRs before choosing a form to work on. +Use the records directory of the preset that produced the JUnit file, for example +`out/build/release/form_coverage` for a `release` run. The tool exits with status +2 if that directory does not exist, and warns on stderr if none of its records +was written during the JUnit run, since no record-mode or shader form then counts. Use original source, synthetic inputs or a public sample with its revision and license. Store local inputs in `game-files/` and generated output in `out/`. Keep game files, distribution links, SDK redistributables and dumps out of issues, PRs and Git. Remove personal paths and credentials from logs. diff --git a/tests/form_coverage_check.py b/tests/form_coverage_check.py index 861894ff3b..db04faacb3 100644 --- a/tests/form_coverage_check.py +++ b/tests/form_coverage_check.py @@ -934,8 +934,56 @@ def check_junit_errors(): assert expected in run.stderr, (name, run.stderr) +def check_records_errors(): + """A --records path that is not a directory is reported with exit status 2, because reading nothing from it + would count every record-mode and shader form as uncovered. A directory whose records all come from another + run is measured as before, with a warning; an empty directory (no recording test ran) is silent.""" + import subprocess + tool = Path(fc.__file__) + start = datetime(2026, 11, 21, 21, 5, 21).timestamp() # CTest writes local time + junit_text = ('' + '') + + def run(records, *extra): + return subprocess.run([sys.executable, "-B", str(tool), str(junit), "--records", str(records), *extra], + capture_output=True, text=True) + + with tempfile.TemporaryDirectory() as tmp: + junit = Path(tmp) / "results.xml" + junit.write_text(junit_text, encoding="utf-8") + not_a_dir = Path(tmp) / "records.txt" + not_a_dir.write_text("s_endpgm\n", encoding="utf-8") + for path, expected in ((Path(tmp) / "missing", "records directory does not exist"), + (not_a_dir, "records path is not a directory")): + for extra in ((), ("--gaps", "gfx1013")): + result = run(path, *extra) + assert result.returncode == 2, (path, extra, result.returncode, result.stderr) + assert "Traceback" not in result.stderr, result.stderr + assert result.stderr == f"form_coverage: {path}: {expected}\n", result.stderr + assert result.stdout == "", result.stdout + records = Path(tmp) / "records" + records.mkdir() + empty = run(records) + assert empty.returncode == 0 and empty.stderr == "", (empty.returncode, empty.stderr) + assert "Shader translation records from this run: none" in empty.stdout, empty.stdout + record = records / "pixel_aot_warp.txt" + record.write_text("s_endpgm\n", encoding="utf-8") + os.utime(record, (start + 0.5, start + 0.5)) + fresh = run(records) + assert fresh.returncode == 0 and fresh.stderr == "", (fresh.returncode, fresh.stderr) + assert "Shader translation records from this run: pixel_aot_warp" in fresh.stdout, fresh.stdout + # Negative control: the same record written an hour before the run is ignored, and the tool says so. + os.utime(record, (start - 3600, start - 3600)) + for extra, header in (((), "Tests: 1 passed"), (("--gaps", "gfx1013"), "group\tform\tevidence\n")): + stale = run(records, *extra) + assert stale.returncode == 0, (extra, stale.returncode, stale.stderr) + assert stale.stderr == (f"form_coverage: {records}: none of the 1 records here was written during " + "this JUnit run, so no record-mode or shader form is counted\n"), stale.stderr + assert header in stale.stdout, stale.stdout + + def check_gaps(): - reference = {("VOP1", "v_a"), ("VOP3", "v_a_e64"), ("VOP3", "v_b_e64"), ("VOP1", "v_c")} + reference ={("VOP1", "v_a"), ("VOP3", "v_a_e64"), ("VOP3", "v_b_e64"), ("VOP1", "v_c")} fixtures = {"passing": ({"v_a_e32"}, "pass"), "skipping": ({"v_a_e32", "v_a_e64"}, "skip"), "failing": ({"v_a_e64", "v_b_e64"}, "fail")} @@ -1431,6 +1479,7 @@ def check_dpp_f16_arith_round_forms(): check_s_version_form() check_parsing() check_junit_errors() + check_records_errors() check_gaps() check_dashboard() check_avx2_regs() diff --git a/tools/form_coverage.py b/tools/form_coverage.py index 98d6a62e4b..e80febcac9 100644 --- a/tools/form_coverage.py +++ b/tools/form_coverage.py @@ -19,7 +19,8 @@ of each line of every program tools/pixel_aot.py lowered without an error, in the file CTest names in FORM_COVERAGE_RECORD (/form_coverage/.txt). Programs a check expects to be rejected raise before they are recorded. A record not written during the JUnit file's run is ignored, so a - record and a test status always come from the same run. + record and a test status always come from the same run. A --records path that is not a directory is an + error (exit 2); a directory whose records all come from another run is measured with a warning. - Reference lists (denominators) live in docs/coverage/ and are produced by tools/form_reference.py. Python standard library only. """ @@ -332,7 +333,19 @@ def main(argv): except (OSError, ET.ParseError, ValueError) as error: print(f"form_coverage: {args.junit}: {error}", file=sys.stderr) return 2 - m = measure(results, records=read_records(args.records, window), gaps_for=args.gaps) + # Reading nothing from a mistyped or wrong --records path would silently count every record-mode and shader + # form as uncovered, so a path that is not a directory is an error. + if not args.records.is_dir(): + problem = "records path is not a directory" if args.records.exists() else "records directory does not exist" + print(f"form_coverage: {args.records}: {problem}", file=sys.stderr) + return 2 + records = read_records(args.records, window) + stored = sum(1 for _ in args.records.glob("*.txt")) + if stored and not records: + # For example the records of another preset's build directory: valid, but nothing from this run counts. + print(f"form_coverage: {args.records}: none of the {stored} records here was written during this JUnit " + "run, so no record-mode or shader form is counted", file=sys.stderr) + m = measure(results, records=records, gaps_for=args.gaps) if args.gaps: gaps = m[args.gaps].pop("gaps") if args.json: