"""#461: the DLLs the Windows HIP runtime needs beside strata.exe, from the PE import tables. python tools/test_dll_closure.py (the real-zip test skips when the 0.1.40.2 HIP zip is not here) Covers tools/hip/dll_closure.py and setup.hip_runtime_beside_exe on a fake engine folder. """ import os import struct import sys import tempfile import unittest import zipfile from pathlib import Path from unittest import mock ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / "tools" / "hip")) sys.path.insert(0, str(ROOT)) import dll_closure as dc # noqa: E402 import setup # noqa: E402 def fake_pe(imports, delay=()): """A minimal PE32+ image whose import table (and delay-import table) names `imports` (`delay`).""" text = bytearray() va = 0x1000 def add_str(s): off = len(text) text.extend(s.encode() + b"\0") return va + off names = [add_str(n) for n in imports] dnames = [add_str(n) for n in delay] while len(text) % 8: text.append(0) imp_off = len(text) for rva in names: text.extend(struct.pack("