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
50 changes: 50 additions & 0 deletions tests/test_buffer_format_fuzz_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""CPU-only tests for tools/buffer_format_fuzz.py's command line: an explicit --formats is checked before the GPU.

python -I tests/test_buffer_format_fuzz_cli.py

A typo in --formats used to be found only after runner.open_oracle(), so a machine without the oracle answered
"hardware oracle unavailable" (77) and one with it raised SystemExit (1). It is a usage error (2) before the oracle.
"""
import importlib.util
import os
import subprocess
import sys
import unittest

REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TOOL = os.path.join(REPO, "tools", "buffer_format_fuzz.py")


def run(*args):
return subprocess.run([sys.executable, "-I", TOOL, *args], capture_output=True, text=True, check=False)


def load_tool():
spec = importlib.util.spec_from_file_location("buffer_format_fuzz", TOOL)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module


class BufferFormatFuzzFormatsTests(unittest.TestCase):
def test_unknown_format_is_a_usage_error_before_the_oracle(self):
proc = run("--oracle", "hw", "--formats", "8_8_8_8_UNORM_typo")
self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr)
self.assertIn("unknown format '8_8_8_8_UNORM_typo'", proc.stderr)
self.assertNotIn("hardware oracle", proc.stdout + proc.stderr)

def test_a_code_outside_the_table_is_refused_too(self):
proc = run("--oracle", "hw", "--formats", "0,8_8_8_8_UNORM")
self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr)
self.assertIn("unknown format '0'", proc.stderr)

def test_known_names_and_codes_map_to_the_table(self):
tool = load_tool()
pairs = tool.select_formats("8_8_8_8_UNORM,56")
self.assertEqual([n for _, n in pairs], ["8_8_8_8_UNORM", tool.GFX10_NAMES[56]])
with self.assertRaises(ValueError):
tool.select_formats("not_a_format")


if __name__ == "__main__":
unittest.main()
14 changes: 11 additions & 3 deletions tools/buffer_format_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
python -I tools/buffer_format_fuzz.py --self-test
python -I tools/buffer_format_fuzz.py --oracle hw [--mode load|store|all] [--path mubuf|mtbuf|both]
[--formats 56,36,...] [--seed S] [--negative-control]
Exit code: 0 all match, 1 a mismatch, 2 harness error, 77 no hardware oracle. Nothing here reads game files.
Exit code: 0 all match, 1 a mismatch, 2 a usage or harness error, 77 no hardware oracle. Nothing here reads game files.
"""
import argparse
import json
Expand Down Expand Up @@ -507,7 +507,7 @@ def select_formats(spec, family="gfx11"):
tok = tok.strip()
code = int(tok) if tok.isdigit() else codes.get(tok)
if code not in GFX10_NAMES:
raise SystemExit(f"unknown format {tok!r}; give a GFX10 code (1..77) or name such as 8_8_8_8_UNORM")
raise ValueError(f"unknown format {tok!r}; give a GFX10 code (1..77) or name such as 8_8_8_8_UNORM")
out.append((code, GFX10_NAMES[code]))
return out

Expand Down Expand Up @@ -606,14 +606,22 @@ def main():
return self_test()
if a.oracle != "hw":
ap.error("--oracle hw or --self-test")
# An explicit --formats needs no GPU to be parsed: a typo is a usage error here, before the oracle is opened
# (it used to be reported only after it, or masked by "hardware oracle unavailable" without one).
explicit = None
if a.formats:
try:
explicit = select_formats(a.formats)
except ValueError as e:
ap.error(str(e))
from hw_oracle import runner, asm
try:
oracle = runner.open_oracle(arch=a.hw_arch)
except runner.Unavailable as e:
print(f"hardware oracle unavailable: {e}")
return 77
family = asm.family(oracle.arch)
fmts = select_formats(a.formats, family)
fmts = explicit if explicit is not None else select_formats("", family)
if family == "gfx12":
print("GFX12 numbers its formats again; not built here")
oracle.close()
Expand Down