"""CPU test for tools/psocache_inspect.py on a synthetic cache built by this test, not the game's. The synthetic file follows the measured layout: a 0x80 header with the four counts and two sizes, two graphics records of 0x70, one compute record of 0x18, two 8-byte meta-index entries, two 8-byte shader-index entries, a meta blob of chunk records and a code blob with two s_endpgm markers padded with s_code_end. """ import json import os import struct import subprocess import sys import tempfile import unittest ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "psocache_inspect.py") sys.path.insert(0, os.path.join(ROOT, "tools")) import psocache_inspect # noqa: E402 HEADER = 0x80 CHUNK = 32 ENTRY0 = 0x18 + 5 * CHUNK # header 0x18, two 0x41 and two 0x42 and one 0x43 chunk ENTRY1 = 0x10 + 2 * CHUNK # header 0x10, one 0x41 and one 0x43 chunk META_SIZE = ENTRY0 + ENTRY1 CODE_SIZE = 0x200 # two 0x100-byte programs GRAPHICS = 2 COMPUTE = 1 META_INDEX = 2 SHADER_INDEX = 2 FILE_SIZE = ( HEADER + GRAPHICS * 0x70 + COMPUTE * 0x18 + META_INDEX * 8 + SHADER_INDEX * 8 + META_SIZE + CODE_SIZE ) END_PGM = b"\x00\x00\x81\xbf" # s_endpgm 0xBF810000 little-endian CODE_END = b"\x00\x00\x9f\xbf" # s_code_end 0xBF9F0000 little-endian def build(): """Return the bytes of a tiny cache that satisfies the model.""" data = bytearray(FILE_SIZE) data[0:4] = b"PS\x00\x09" data[0x04:0x0A] = b"test\x00\x00" data[0x24:0x29] = b"v1\x00\x00" data[0x48:0x50] = bytes.fromhex("0011223344556677") struct.pack_into("<4I", data, 0x50, GRAPHICS, COMPUTE, META_INDEX, SHADER_INDEX) struct.pack_into("<2I", data, 0x60, META_SIZE, CODE_SIZE) off = HEADER for i in range(GRAPHICS): struct.pack_into("