97 lines
4.0 KiB
Python
97 lines
4.0 KiB
Python
"""Runtime tests for the reconstructed rrCore translation unit.
|
|
|
|
rrCore is a data-only module: its entire ABI surface is one owned
|
|
function-pointer global, g_fp_rrDisplayAssertion, default NULL (the retail
|
|
object stores it zero-initialized in .bss on durango/orbis/ps3 and .data on
|
|
vita). There are no exported functions and no imports, so the support harness
|
|
has no stubs.
|
|
|
|
These assertions are grounded in the retail objects under
|
|
work/iggy-native-decomp/<platform>-objects/rrCore.obj, whose only real symbol
|
|
is `g_fp_rrDisplayAssertion` (B on durango/orbis/ps3, D on vita). The dylib is
|
|
built for the 64-bit host with IGGY_RECONSTRUCT_RRCORE_DURANGO selected; the
|
|
symbol is read back through ctypes and confirmed NULL/zero by default.
|
|
|
|
The authoritative callback prototype (include/rrCore.h:1702) is
|
|
`rrbool (RADLINK *)(int *Ignored, const char *fileName, const int line,
|
|
const char *function, const char *message)`; here it is only exercised as a
|
|
data pointer (its NULL default and mutability), so no call-signature is bound.
|
|
"""
|
|
|
|
import ctypes
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
|
SOURCE = RECONSTRUCTED / "rrCore.c"
|
|
HEADER = RECONSTRUCTED / "rrCore.h"
|
|
SUPPORT = ROOT / "tests/support/rrCore_test_support.c"
|
|
|
|
|
|
class ReconstructedRrCoreTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
missing = [str(path) for path in (SOURCE, HEADER, SUPPORT)
|
|
if not path.exists()]
|
|
if missing:
|
|
raise AssertionError(
|
|
"missing rrCore runtime inputs: " + ", ".join(missing))
|
|
cls.temp = tempfile.TemporaryDirectory()
|
|
output = Path(cls.temp.name) / "rrCore.dylib"
|
|
build = subprocess.run([
|
|
"clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra",
|
|
"-Werror", "-Wl,-undefined,dynamic_lookup",
|
|
"-DIGGY_RECONSTRUCT_RRCORE_DURANGO=1",
|
|
"-I", str(RECONSTRUCTED),
|
|
str(SOURCE), str(SUPPORT), "-o", str(output),
|
|
], capture_output=True, text=True)
|
|
if build.returncode:
|
|
raise AssertionError(build.stdout + build.stderr)
|
|
cls.lib = ctypes.CDLL(str(output))
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.temp.cleanup()
|
|
|
|
def test_display_assertion_symbol_exists(self):
|
|
# The one owned global must be present in the built module.
|
|
symbol = ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion")
|
|
self.assertIsNotNone(symbol)
|
|
|
|
def test_display_assertion_defaults_to_null(self):
|
|
# Retail places the pointer in BSS/DATA zero-initialized; the
|
|
# reconstruction defines it `= NULL`, so it must read back as 0/None.
|
|
symbol = ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion")
|
|
self.assertIn(symbol.value, (None, 0))
|
|
|
|
def test_display_assertion_is_pointer_wide_storage(self):
|
|
# Reading the address must succeed and the storage must be a full
|
|
# pointer (matching the retail function-pointer data symbol).
|
|
address = ctypes.addressof(
|
|
ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion"))
|
|
self.assertNotEqual(address, 0)
|
|
raw = ctypes.c_void_p.from_address(address)
|
|
self.assertIn(raw.value, (None, 0))
|
|
|
|
def test_display_assertion_is_writable_then_restored(self):
|
|
# A host layer installs a callback by assigning the global; confirm the
|
|
# storage is mutable and can be reset to NULL without disturbing others.
|
|
symbol = ctypes.c_void_p.in_dll(self.lib, "g_fp_rrDisplayAssertion")
|
|
self.assertIn(symbol.value, (None, 0))
|
|
symbol.value = 0xDEADBEEF
|
|
self.assertEqual(
|
|
ctypes.c_void_p.in_dll(
|
|
self.lib, "g_fp_rrDisplayAssertion").value, 0xDEADBEEF)
|
|
symbol.value = 0
|
|
self.assertIn(
|
|
ctypes.c_void_p.in_dll(
|
|
self.lib, "g_fp_rrDisplayAssertion").value, (None, 0))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|