From 8d29ffd26ce35c9bad7d0b751d0637e23139934c Mon Sep 17 00:00:00 2001 From: milk4sale <53350507+milk4sale@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:48:56 -0600 Subject: [PATCH] tests: the pytest helper takes a text-only sample's lines as its listing, as run_gpu_tests.py does (TEST-TRANSLATE-TEXT-ONLY) translator-tests fails on main since 6261ca916 (the merge of #957), which added runtime/test/shaders/cs_dpp_cmp.asm: tests/test_translate.py::test_gpu_samples_translate_and_validate[cs_dpp_cmp.asm] and ::test_wave64_emulate_uses_no_subgroup_ops[cs_dpp_cmp.asm] stop at the llvm-mc assertion of conftest.Shader with "dpp variant of this instruction is not supported" (2 failed, 1879 passed on a runner with llvm-mc 21; the same two with 23.1.4). llvm-mc has no gfx1013 encoding for a VOPC compare in DPP form, so the fixture carries the line "; run_gpu_tests: text only, ..." and assemble_to_s in scripts/run_gpu_tests.py writes its listing from the text. conftest.Shader assembled every sample with llvm-mc and did not know the line. It now does the same as the GPU runner for a sample that carries it, so both tests translate and validate the fixture instead of failing before they reach the translator. Two new tests: the line is spelled in conftest as in run_gpu_tests.py, and only a sample that carries it skips llvm-mc (the same lines without it still go to llvm-mc and fail there). Controls: with the line spelled differently in conftest the spelling test and both cs_dpp_cmp tests fail; with every sample taking the text path the second new test fails. The translator-tests step with the workflow's file list (37 files, pytest 9.2.0, llvm-mc 23.1.4, without numpy and Pillow, so 134 skipped): 2 failed, 1618 passed on main 89d7dfcf5; 1622 passed here. Co-Authored-By: Claude Fable 5.2 --- tests/conftest.py | 15 +++++++++++++-- tests/test_translate.py | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 1152827615..308590f678 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -156,6 +156,10 @@ def mesh_psv0_chunk(threads=(128, 1, 1), max_vertices=64, max_primitives=64, top # 0x8088 = 4 user SGPRs, TGID_X, 512 B of LDS; group 64x1x1 (the header the cs_* samples in runtime/test/shaders use). DEFAULT_CS_HEADER = (0x8088, (64, 1, 1)) +# The comment line a sample carries when llvm-mc cannot assemble it (cs_dpp_cmp.asm: a VOPC compare in DPP form). +# scripts/run_gpu_tests.py has the same line; tests/test_translate.py checks that the two agree. +TEXT_ONLY_MARK = "; run_gpu_tests: text only, llvm-mc has no gfx1013 encoding for an instruction here" + class Shader: def __init__(self, workdir, name, asm, cs_header=DEFAULT_CS_HEADER, dxbc=EMPTY_DXBC): @@ -167,6 +171,15 @@ def __init__(self, workdir, name, asm, cs_header=DEFAULT_CS_HEADER, dxbc=EMPTY_D rsrc2, (lx, ly, lz) = cs_header (workdir / "fssm").mkdir(exist_ok=True) (workdir / "fssm" / f"{name}.fssm").write_bytes(bytes(0x138) + struct.pack("<4I", rsrc2, lx, ly, lz)) + self.path = disasm / f"{name}.s" + self.workdir = workdir + if any(ln.strip() == TEXT_ONLY_MARK for ln in asm.splitlines()): + # llvm-mc has no gfx1013 encoding for an instruction of this sample, so its text is the listing, as in + # assemble_to_s of scripts/run_gpu_tests.py: the translator reads straight-line code from the text alone. + lines = [f"; {name} code 0x0..0x0 (synthetic), gfx1013, 0 invalid words"] + lines += ["\t" + ln.strip() for ln in asm.splitlines() if ln.strip() and not ln.lstrip().startswith(";")] + self.path.write_text("\n".join(lines) + "\n", encoding="utf-8", newline="\n") + return cmd = LLVM_MC + ["-triple=amdgcn--amdpal", "-mcpu=gfx1013"] for ln in asm.splitlines(): s = ln.strip() @@ -181,9 +194,7 @@ def __init__(self, workdir, name, asm, cs_header=DEFAULT_CS_HEADER, dxbc=EMPTY_D cmd.append("-show-encoding") r = subprocess.run(cmd, input=asm, capture_output=True, text=True) assert r.returncode == 0, r.stderr - self.path = disasm / f"{name}.s" self.path.write_text(f"; {name} synthetic\n{r.stdout}") - self.workdir = workdir def translate(self): return rdna2spirv.translate(str(self.path)) diff --git a/tests/test_translate.py b/tests/test_translate.py index d151c36e28..3782ea8716 100644 --- a/tests/test_translate.py +++ b/tests/test_translate.py @@ -13,8 +13,8 @@ import pytest import rdna2spirv -from conftest import (EMPTY_DXBC, KNOWN_VAL_ISSUES, ROOT, SAMPLE_DXBC, Shader, make_dxbc, mesh_psv0_chunk, - requires_tools, signature_chunk) +from conftest import (EMPTY_DXBC, KNOWN_VAL_ISSUES, ROOT, SAMPLE_DXBC, TEXT_ONLY_MARK, Shader, make_dxbc, + mesh_psv0_chunk, requires_tools, signature_chunk) pytestmark = requires_tools @@ -64,6 +64,24 @@ def test_gpu_samples_translate_and_validate(path, make_shader): shader.validate(shader.translate(), KNOWN_VAL_ISSUES.get(stem)) +def test_text_only_mark_is_spelled_as_in_the_gpu_runner(): + """conftest.Shader and scripts/run_gpu_tests.py have to agree on the comment line that marks a sample llvm-mc + cannot assemble: with two spellings, a marked sample is handed to llvm-mc here and fails.""" + runner = Path(ROOT, "scripts", "run_gpu_tests.py").read_text(encoding="utf-8") + assert f'\nTEXT_ONLY_MARK = "{TEXT_ONLY_MARK}"\n' in runner + + +def test_only_a_marked_sample_skips_llvm_mc(make_shader): + """A sample with the text-only line becomes its own listing, comment lines dropped, whatever llvm-mc makes of + its instructions; the same lines without it still go to llvm-mc and fail there.""" + body = "v_mov_b32 v1, 1.0\n v_no_such_instruction v0, v1\n\ns_endpgm\n" + shader = make_shader(f"; a sample llvm-mc cannot assemble\n{TEXT_ONLY_MARK}\n{body}", "cs_text_only") + assert shader.path.read_text(encoding="utf-8").splitlines()[1:] == [ + "\tv_mov_b32 v1, 1.0", "\tv_no_such_instruction v0, v1", "\ts_endpgm"] + with pytest.raises(AssertionError, match="v_no_such_instruction"): + make_shader(body, "cs_not_marked") + + @pytest.mark.parametrize("case", sorted(SUPPORTED)) def test_supported_instruction(case, make_shader): shader = make_shader(program(SUPPORTED[case]))