"""CPU test for tools/psocache_extract.py on synthetic RPF9 archives built by this test. The cache inside is a tiny file that satisfies the layout `psocache_inspect` checks: a 0x80 header, one 0x70 record, one 0x18 record, two 8-byte index entries, a 32-byte meta entry and a 0x100-byte code entry. The cache is split across two zlib streams in the archive, with zero padding, a stream before it and a stream after it. """ import os import struct import subprocess import sys import tempfile import unittest from unittest import mock import zlib ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOL = os.path.join(ROOT, "tools", "psocache_extract.py") sys.path.insert(0, os.path.join(ROOT, "tools")) import psocache_extract as pe # noqa: E402 HEADER = 0x80 GRAPHICS = 1 COMPUTE = 1 META_INDEX = 1 SHADER_INDEX = 1 META_SIZE = 32 CODE_SIZE = 0x100 CACHE_SIZE = ( HEADER + GRAPHICS * 0x70 + COMPUTE * 0x18 + META_INDEX * 8 + SHADER_INDEX * 8 + META_SIZE + CODE_SIZE ) SPLIT = 200 END_PGM = b"\x00\x00\x81\xbf" CODE_END = b"\x00\x00\x9f\xbf" def build_cache(): data = bytearray(CACHE_SIZE) data[0:4] = b"PS\x00\x09" struct.pack_into("<4I", data, 0x50, GRAPHICS, COMPUTE, META_INDEX, SHADER_INDEX) struct.pack_into("<2I", data, 0x60, META_SIZE, CODE_SIZE) off = HEADER struct.pack_into("