87 lines
4.9 KiB
Python
87 lines
4.9 KiB
Python
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
|
SOURCE = RECONSTRUCTED / "swf_draw_interface.c"
|
|
LLVM_NM = Path("/opt/homebrew/opt/llvm/bin/llvm-nm")
|
|
VARIANTS = {
|
|
"durango": ("clang", "x86_64-pc-windows-msvc"),
|
|
"orbis": ("clang", "x86_64-unknown-freebsd"),
|
|
"vita": ("clang", "armv7a-unknown-linux-gnueabihf"),
|
|
}
|
|
PS3_CLANG = Path("/opt/homebrew/opt/llvm/bin/clang")
|
|
if PS3_CLANG.exists():
|
|
# Generic PPC32 smoke coverage only, not retail PPU ELFv1/OPD validation.
|
|
VARIANTS["ps3"] = (str(PS3_CLANG), "powerpc-unknown-linux-gnu")
|
|
|
|
EXPECTED = {
|
|
"IggyPlayerDebugBatchChooseEnd", "IggyPlayerDebugBatchInit", "IggyPlayerDebugBatchMove",
|
|
"IggyPlayerDebugBatchSplit", "IggyPlayerDebugBatchStartFrame", "iggy_cursor_width",
|
|
"iggy_draw_batch", "iggy_draw_buffered_rect", "iggy_draw_buffered_rect_would_flush",
|
|
"iggy_draw_filter_quad", "iggy_draw_pixel_box", "iggy_draw_rectangle",
|
|
"iggy_draw_rectangle_texgen", "iggy_draw_screen_rect", "iggy_draw_stroke_mesh",
|
|
"iggy_draw_text_border", "iggy_draw_text_cursor", "iggy_end_buffered_rects",
|
|
"iggy_end_masking", "iggy_flush_buffered_rects", "iggy_gdraw_FreeTexture",
|
|
"iggy_gdraw_FreeVertexBuffer", "iggy_gdraw_TryToLockTexture",
|
|
"iggy_gdraw_TryToLockVertexBuffer", "iggy_gdraw_UnlockHandles", "iggy_gdraw_stats",
|
|
"iggy_lowlevel_set_xform", "iggy_lowlevel_set_xform_translation",
|
|
"iggy_predraw_stroke_mesh", "iggy_start_buffered_rects", "iggy_start_masking",
|
|
}
|
|
COMMON_IMPORTS = {"iggy_clear_renderstate", "iggy_gdraw", "iggy_invert_matrix",
|
|
"iggy_setcolor_4ub_cxf", "iggy_setup_fill_style", "iggy_temp_alloc",
|
|
"iggy_temp_free", "iggy_tm_internal", "iggy_tm_normal"}
|
|
TARGET_IMPORTS = {
|
|
"durango": COMMON_IMPORTS | {"_fltused", "ceil", "floor", "sqrt"},
|
|
"orbis": COMMON_IMPORTS | {"memcpy"},
|
|
"ps3": COMMON_IMPORTS | {"ceilf", "floorf", "memcpy"},
|
|
"vita": COMMON_IMPORTS | {"ceil", "floor", "memset", "sqrt"},
|
|
}
|
|
|
|
|
|
class ReconstructedSwfDrawInterfaceCrossTests(unittest.TestCase):
|
|
def test_exports_imports_cpp_header_and_target_smoke(self):
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
temporary = Path(directory)
|
|
for platform, (compiler, target) in VARIANTS.items():
|
|
output = temporary / f"interface_{platform}.o"
|
|
extra = ["-mthumb"] if platform == "vita" else []
|
|
result = subprocess.run([
|
|
compiler, "-target", target, "-ffreestanding", "-c", "-std=c11", "-O2",
|
|
"-Wall", "-Wextra", "-Werror", *extra,
|
|
f"-DIGGY_RECONSTRUCT_SWF_DRAW_INTERFACE_{platform.upper()}=1",
|
|
"-I", str(RECONSTRUCTED), str(SOURCE), "-o", str(output),
|
|
], capture_output=True, text=True)
|
|
self.assertEqual(result.returncode, 0, (platform, result.stderr))
|
|
if LLVM_NM.exists():
|
|
defined = subprocess.run([str(LLVM_NM), "--defined-only", str(output)], capture_output=True, text=True)
|
|
undefined = subprocess.run([str(LLVM_NM), "--undefined-only", str(output)], capture_output=True, text=True)
|
|
names = {line.split()[-1].removeprefix(".") for line in defined.stdout.splitlines() if line.split()}
|
|
imports = {line.split()[-1].removeprefix(".") for line in undefined.stdout.splitlines() if line.split()}
|
|
self.assertEqual(names & EXPECTED, EXPECTED, platform)
|
|
self.assertEqual(imports, TARGET_IMPORTS[platform], (platform, imports))
|
|
cpp = temporary / "interface.cpp"
|
|
cpp.write_text(
|
|
'#include "swf_draw_interface.h"\n'
|
|
"static_assert(sizeof(IggyDrawStats) == 48);\n"
|
|
"static_assert(sizeof(IggyDrawBatch) == 32);\n"
|
|
"void use(Iggy *i) { iggy_gdraw_UnlockHandles(i); }\n", encoding="utf-8")
|
|
syntax = subprocess.run(["clang++", "-fsyntax-only", "-std=c++17", "-Wall", "-Wextra", "-Werror", "-I", str(RECONSTRUCTED), str(cpp)], capture_output=True, text=True)
|
|
self.assertEqual(syntax.returncode, 0, syntax.stderr)
|
|
|
|
def test_native_ps3_descriptor_and_offsets_are_documented_by_object(self):
|
|
obj = ROOT / "work/iggy-native-decomp/ps3-objects/swf_draw_interface.obj"
|
|
result = subprocess.run(["nm", "-a", str(obj)], capture_output=True, text=True)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertIn(" D iggy_draw_rectangle", result.stdout)
|
|
self.assertIn(" T .iggy_draw_rectangle", result.stdout)
|
|
raw = (ROOT / "iggy-decompiled/raw/ps3/swf_draw_interface.c").read_text(encoding="utf-8")
|
|
for token in ("0x19e4", "0x1dbc", "0x1dc0", "0x1dc8", "0x1ea0", "0x21ac", "0x21b0"):
|
|
self.assertIn(token, raw)
|
|
|
|
|
|
if __name__ == "__main__": unittest.main()
|