run_gpu_tests: bary, gradient and WQM checks fail a NaN or short frame

abs(nan - want) > tol is False, so an all-NaN frame counted as exact, and
none of the three counted pixels, so an empty .raw passed. check.py rejects
both; these now do too, as check_pixel_const already counts pixels.
This commit is contained in:
quackottu
2026-11-22 12:25:11 +05:30
parent 48ad23f026
commit 662752cc57
2 changed files with 57 additions and 0 deletions

View File

@ -7,6 +7,7 @@ Usage:
"""
import argparse
import json
import math
import os
import re
import shutil
@ -290,8 +291,17 @@ def check_pixel_const(raw_path: str, want: tuple[int, int, int, int]) -> tuple[b
return True, "4096/4096 pixels exact"
def frame_problem(px) -> str:
"""Why a 64x64 frame can't be judged: a short frame or a NaN passes every tolerance test (check.py rejects both)."""
if len(px) != 64 * 64:
return f"expected 4096 pixels, got {len(px)}"
return "" if all(math.isfinite(v) for p in px for v in p) else "non-finite values in the frame"
def check_bary(raw_path: str) -> tuple[bool, str]:
px = read_raw_rgba32f(raw_path)
if problem := frame_problem(px):
return False, problem
bad = 0
first = ""
for i, (ax, ay, bi, bj) in enumerate(px):
@ -346,6 +356,8 @@ def check_flat(raw_path: str) -> tuple[bool, str]:
def check_wqm(raw_path: str) -> tuple[bool, str]:
"""ps_wqm.asm: per pixel (wqm, own, wqm, own); wqm iff x%4 < 2 and y%4 >= 2, own iff x%4 == 1 and y%4 == 2."""
px = read_raw_u32(raw_path)
if problem := frame_problem(px):
return False, problem
w = int(len(px) ** 0.5)
wrong = sum(tuple(p) != (a, b, a, b)
for i, p in enumerate(px)
@ -394,6 +406,8 @@ def check_uniform_branch(raw_path: str) -> tuple[bool, str]:
def check_grad(raw_path: str, want_b: float, want_a: float) -> tuple[bool, str]:
px = read_raw_rgba32f(raw_path)
if problem := frame_problem(px):
return False, problem
bad = 0
first = ""
for i, (r, g, b, a) in enumerate(px):

View File

@ -0,0 +1,43 @@
"""scripts/run_gpu_tests.py: the pixel checkers fail a short frame or non-finite values, as check.py does (no device needed)."""
from pathlib import Path
import os
import struct
import sys
import tempfile
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
import run_gpu_tests as rgt
NAN = float("nan")
class PixelChecks(unittest.TestCase):
def raw(self, data: bytes) -> str:
fd, path = tempfile.mkstemp(suffix=".raw")
with os.fdopen(fd, "wb") as f:
f.write(data)
self.addCleanup(os.remove, path)
return path
def test_good_frames_pass(self):
grad = b"".join(struct.pack("<4f", (i % 64 + 0.5) / 64, (i // 64 + 0.5) / 64, 0.5, 1.0) for i in range(4096))
self.assertTrue(rgt.check_grad(self.raw(grad), 0.5, 1.0)[0])
bary = b"".join(struct.pack("<4f", 0.5, 0.25, 0.25, 0.125) for _ in range(4096))
self.assertTrue(rgt.check_bary(self.raw(bary))[0])
def test_nan_frame_fails(self):
nan = self.raw(struct.pack("<4f", NAN, NAN, NAN, NAN) * 4096)
self.assertFalse(rgt.check_bary(nan)[0])
self.assertFalse(rgt.check_grad(nan, 0.5, 1.0)[0])
def test_empty_frame_fails(self):
empty = self.raw(b"")
for name, check in (("bary", rgt.check_bary), ("grad", lambda p: rgt.check_grad(p, 0.0, 0.0)),
("wqm", rgt.check_wqm)):
with self.subTest(check=name):
self.assertFalse(check(empty)[0])
if __name__ == "__main__":
unittest.main()