"""tools/bvh_gpu_smoke.py without a GPU or game files: the heap image, the word count and the judging of runs, with a fake vk_compute_test in place of the real one.""" import os import struct import subprocess import sys import tempfile import unittest from pathlib import Path from unittest import mock ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "tools")) import bvh_gpu_smoke as smoke # noqa: E402 def fake_runner(behaviour): """A runner that writes the heap image plus per-program changes to the dump, as vk_compute_test's VKC_DUMP does. behaviour: name -> ("ok", writes) | ("exit 1",) | ("validation",) | ("timeout",) | ("flaky", writes).""" calls = {} def run(vkc, spv, init, dump, heap_words, validation, timeout): name = Path(spv).stem calls[name] = calls.get(name, 0) + 1 kind = behaviour.get(name, ("ok", {})) if kind[0] not in ("ok", "flaky"): return kind[0], "boom" heap = bytearray(Path(init).read_bytes()) assert len(heap) == heap_words * 4 for offset, word in kind[1].items(): if kind[0] == "flaky" and calls[name] == 2: word ^= 1 struct.pack_into("