"""CPU checks for tools/image_fuzz.py: the oracle, the texel mapping and the generated shader, no GPU. The GPU side (vk_image_fuzz, rdna2spirv.py) is what the fuzzer compares against; these tests make sure the oracle it compares with is right, so a mismatch is the translator's and not the fuzzer's. """ import json import os import random import signal import struct import subprocess import sys import pytest HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) sys.path.insert(0, os.path.join(ROOT, "tools")) import image_fuzz as imf # noqa: E402 def test_format_codes_match_the_translator_table(): with open(os.path.join(imf.TOOLS, "gfx10_formats.json"), encoding="utf-8") as f: by_name = {name: int(code) for code, name in json.load(f).items()} gfx10_names = { "R8G8B8A8_UNORM": "GFX10_FORMAT_8_8_8_8_UNORM", "R16G16B16A16_SFLOAT": "GFX10_FORMAT_16_16_16_16_FLOAT", "R32G32B32A32_SFLOAT": "GFX10_FORMAT_32_32_32_32_FLOAT", "R32_SFLOAT": "GFX10_FORMAT_32_FLOAT", "R8G8B8A8_UINT": "GFX10_FORMAT_8_8_8_8_UINT", "R8G8B8A8_SINT": "GFX10_FORMAT_8_8_8_8_SINT", } assert set(gfx10_names) == set(imf.FORMATS) for name, (_, code, bpp, model) in imf.FORMATS.items(): assert by_name[gfx10_names[name]] == code, name assert bpp in (4, 8, 16) and model in ("unorm8", "half4", "float4", "float1", "uint8", "sint8"), name def test_unorm_oracle_divides_by_255(): texels = bytes([0, 1, 127, 255, 10, 20, 30, 40]) got = imf.oracle("R8G8B8A8_UNORM", texels, 2, 1) assert got[0] == [0.0, imf.f32(1 / 255.0), imf.f32(127 / 255.0), 1.0] assert got[1] == [imf.f32(v / 255.0) for v in (10, 20, 30, 40)] def test_half_oracle_reads_four_binary16(): wanted = [-2.0, -0.0, 0.5, 65504.0] texels = b"".join(struct.pack("