From dffa50cd9c63d911aee7fae49a9696a8a8c6b991 Mon Sep 17 00:00:00 2001 From: elforeign <324243036+elforeign@users.noreply.github.com> Date: Tue, 24 Nov 2026 03:40:52 -0600 Subject: [PATCH] semantics: run the generator unit tests in CI and fail clearly below Python 3.11 (#215) Align the merged generator tests with the pinned documents and the complete unsupported list, add tests for the rules added after review, run them in the existing CI step next to the coverage tests, and give the coverage script the same explicit Python 3.11 error as the generator instead of a traceback. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com> --- .github/workflows/ci.yml | 6 ++-- scripts/audit/semantic_coverage.py | 5 ++- .../test_generate_semantics.py | 31 +++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 843e0d3..2bab7a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,8 +50,10 @@ jobs: sh -n scripts/agent-queue.sh scripts/agent-sync.sh - name: Test pull request template check run: PYTHONPATH=scripts python3 -m unittest discover -s tests/pr_template - - name: Test semantic coverage report - run: PYTHONPATH=scripts python3 -m unittest discover -s tests/semantic_coverage + - name: Test semantic registry generator and coverage report + run: | + python3 -m unittest discover -s tests/semantics_generator + PYTHONPATH=scripts python3 -m unittest discover -s tests/semantic_coverage - name: Check formatting and lint run: | cargo fmt --all -- --check diff --git a/scripts/audit/semantic_coverage.py b/scripts/audit/semantic_coverage.py index 54cc22a..6a6a614 100644 --- a/scripts/audit/semantic_coverage.py +++ b/scripts/audit/semantic_coverage.py @@ -8,7 +8,10 @@ from pathlib import Path import re import runpy import sys -import tomllib +try: + import tomllib +except ModuleNotFoundError: # pragma: no cover - depends on the interpreter + sys.exit("semantic_coverage.py needs Python 3.11 or newer (tomllib)") ROOT = Path(__file__).resolve().parents[2] SNAPSHOT = Path("crates/isa/data/rdna2.jsonl") diff --git a/tests/semantics_generator/test_generate_semantics.py b/tests/semantics_generator/test_generate_semantics.py index 3095138..dafcd90 100644 --- a/tests/semantics_generator/test_generate_semantics.py +++ b/tests/semantics_generator/test_generate_semantics.py @@ -82,12 +82,12 @@ def _form(name, opcode, variant, operation, signedness, scc, carry_in="none"): def registry(): rule = copy.deepcopy(gen.OPERAND_RULES["sop2_sgpr"]["shape"]) - rule["unsupported"] = ["dst_vcc", "two_literals"] + rule["unsupported"] = sorted(gen.UNSUPPORTED_COMBOS) return { "schema": 1, "architecture": "gfx1030", "source_sha256": SHA, - "documents": {"guide": {"title": "guide"}, "xml": {"title": "xml"}}, + "documents": copy.deepcopy(gen.PINNED_DOCUMENTS), "operand_rules": {"sop2_sgpr": rule}, "form": [ _form("S_ADD_U32", 0, "AddU32", "add", "unsigned", "carry_out"), @@ -288,6 +288,33 @@ class Validate(unittest.TestCase): reg["operand_rules"]["sop2_sgpr"]["max_literals"] = 2 self.rejects(reg, "operand rule sop2_sgpr: declaration differs") + def test_rejects_an_incomplete_unsupported_list(self): + reg = registry() + reg["operand_rules"]["sop2_sgpr"]["unsupported"].remove("two_literals") + self.rejects( + reg, "operand rule sop2_sgpr: unsupported combos differ from those the decoder rejects" + ) + + def test_rejects_a_citation_to_another_file(self): + reg = registry() + reg["documents"]["guide"]["file"] = "missing.pdf" + self.rejects(reg, "document guide: differs from the pinned public document") + + def test_rejects_an_unenforced_wave_restriction(self): + reg = registry() + reg["form"][0]["wave"] = "wave32" + self.rejects(reg, "S_ADD_U32: wave wave32 has no decoder enforcement yet") + + def test_rejects_a_reserved_variant(self): + reg = registry() + reg["form"][0]["variant"] = "Self" + self.rejects(reg, "S_ADD_U32: variant 'Self' is reserved") + + def test_rejects_a_boolean_schema(self): + reg = registry() + reg["schema"] = True + self.rejects(reg, "schema True is not 1") + def test_rejects_unknown_unsupported_combo(self): reg = registry() reg["operand_rules"]["sop2_sgpr"]["unsupported"].append("dst_lds")