314 lines
13 KiB
Python
314 lines
13 KiB
Python
"""Runtime tests for the reconstructed as3vm_classes_base_dummy translation unit.
|
|
|
|
RED STATE: as3vm_classes_base_dummy.c / as3vm_classes_base_dummy.h do not exist
|
|
yet, so setUpClass raises "missing as3vm_classes_base_dummy runtime inputs".
|
|
Every assertion below is grounded in a specific line of
|
|
iggy-decompiled/raw/durango/as3vm_classes_base_dummy.c (cited inline) so a
|
|
faithful DURANGO reconstruction turns these green.
|
|
|
|
as3vm_classes_base_dummy is Iggy's E4X XML / QName / XMLList AS3-class DUMMY
|
|
layer: the 80 as3vm_QName_* / as3vm_XML_* / as3vm_XMLList_* methods that Iggy
|
|
stubs out because E4X XML is UNSUPPORTED. It exports EXACTLY 80 entry points on
|
|
all four platforms (the raw .c is a byte-identical 883 lines everywhere) and --
|
|
UNLIKE as3vm_gc / as3vm_property but LIKE as3vm_imp_math / as3vm_convert -- owns
|
|
ZERO externally named data globals (nm shows no extern B/C/D data symbol; there
|
|
are no ??_C@ rodata artifacts at all, because these stubs carry NO message
|
|
string, only a numeric error code).
|
|
|
|
PINNED BEHAVIOR (raw/durango, byte-identical across all four platforms; every one
|
|
of the 80 stubs is the SAME three-line body):
|
|
|
|
void as3vm_<Class>_<method>(undefined8 *param_1) {
|
|
as3vm_exception_GC(*param_1, 0x74);
|
|
return;
|
|
}
|
|
|
|
So each of the 80 methods dereferences frame[0] as the vm handle and raises
|
|
exception code 0x74 ("E4X XML unsupported") through the single import
|
|
as3vm_exception_GC, then returns void -- no boxing, no return value, no store,
|
|
NO per-method variation. ALL 80 share the ONE error code 0x74 (raw/durango:9,
|
|
20, 31, ... 878 -- the literal 0x74 appears in every body). This runtime test
|
|
exercises ALL 80 exports (not a sample) and pins that uniform contract:
|
|
- each call fires as3vm_exception_GC exactly once,
|
|
- with error code 0x74,
|
|
- with the vm argument == frame[0] (the raw `*param_1`),
|
|
- and returns void.
|
|
|
|
Full-suite runs use python3.12 (the machine python3 is 3.14, which SEGFAULTs on
|
|
the full suite via an unrelated CPython ctypes-GC bug); single-module runs of
|
|
this file are fine on either interpreter.
|
|
"""
|
|
|
|
import ctypes
|
|
import shutil
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
RECONSTRUCTED = ROOT / "iggy-decompiled/src/reconstructed"
|
|
SOURCE = RECONSTRUCTED / "as3vm_classes_base_dummy.c"
|
|
HEADER = RECONSTRUCTED / "as3vm_classes_base_dummy.h"
|
|
SUPPORT = ROOT / "tests/support/as3vm_classes_base_dummy_test_support.c"
|
|
|
|
MASK64 = (1 << 64) - 1
|
|
|
|
# All 80 exported E4X dummy stubs -- the invariant ABI (leading '.' stripped on
|
|
# ps3). QName (5) + XMLList (22) + XML (53) == 80.
|
|
EXPORTS = (
|
|
"as3vm_QName__construct",
|
|
"as3vm_QName_get_localName",
|
|
"as3vm_QName_get_uri",
|
|
"as3vm_QName_toString",
|
|
"as3vm_QName_valueOf",
|
|
"as3vm_XMLList__construct",
|
|
"as3vm_XMLList_attribute",
|
|
"as3vm_XMLList_attributes",
|
|
"as3vm_XMLList_child",
|
|
"as3vm_XMLList_children",
|
|
"as3vm_XMLList_comments",
|
|
"as3vm_XMLList_contains",
|
|
"as3vm_XMLList_copy",
|
|
"as3vm_XMLList_descendents",
|
|
"as3vm_XMLList_elements",
|
|
"as3vm_XMLList_hasComplexContent",
|
|
"as3vm_XMLList_hasOwnProperty",
|
|
"as3vm_XMLList_hashSimpleContent",
|
|
"as3vm_XMLList_length",
|
|
"as3vm_XMLList_normalize",
|
|
"as3vm_XMLList_parent",
|
|
"as3vm_XMLList_processingInstructions",
|
|
"as3vm_XMLList_propertyIsEnumerable",
|
|
"as3vm_XMLList_text",
|
|
"as3vm_XMLList_toString",
|
|
"as3vm_XMLList_toXMLString",
|
|
"as3vm_XMLList_valueOf",
|
|
"as3vm_XML__construct",
|
|
"as3vm_XML_addNamespace",
|
|
"as3vm_XML_appendChild",
|
|
"as3vm_XML_attribute",
|
|
"as3vm_XML_attributes",
|
|
"as3vm_XML_child",
|
|
"as3vm_XML_childIndex",
|
|
"as3vm_XML_children",
|
|
"as3vm_XML_comments",
|
|
"as3vm_XML_contains",
|
|
"as3vm_XML_copy",
|
|
"as3vm_XML_defaultSettings",
|
|
"as3vm_XML_descendents",
|
|
"as3vm_XML_elements",
|
|
"as3vm_XML_get_ignoreComments",
|
|
"as3vm_XML_get_ignoreProcessingInstructions",
|
|
"as3vm_XML_get_ignoreWhitespace",
|
|
"as3vm_XML_get_prettyIndent",
|
|
"as3vm_XML_get_prettyPrinting",
|
|
"as3vm_XML_hasComplexContent",
|
|
"as3vm_XML_hasOwnProperty",
|
|
"as3vm_XML_hashSimpleContent",
|
|
"as3vm_XML_inScopeNamespaces",
|
|
"as3vm_XML_insertChildAfter",
|
|
"as3vm_XML_insertChildBefore",
|
|
"as3vm_XML_length",
|
|
"as3vm_XML_localName",
|
|
"as3vm_XML_name",
|
|
"as3vm_XML_namespace",
|
|
"as3vm_XML_namespaceDeclarations",
|
|
"as3vm_XML_nodeKind",
|
|
"as3vm_XML_normalize",
|
|
"as3vm_XML_parent",
|
|
"as3vm_XML_prependChild",
|
|
"as3vm_XML_processingInstructions",
|
|
"as3vm_XML_propertyIsEnumerable",
|
|
"as3vm_XML_removeNamespace",
|
|
"as3vm_XML_replace",
|
|
"as3vm_XML_setChildren",
|
|
"as3vm_XML_setLocalName",
|
|
"as3vm_XML_setName",
|
|
"as3vm_XML_setNamespace",
|
|
"as3vm_XML_setSettings",
|
|
"as3vm_XML_set_ignoreComments",
|
|
"as3vm_XML_set_ignoreProcessingInstructions",
|
|
"as3vm_XML_set_ignoreWhitespace",
|
|
"as3vm_XML_set_prettyIndent",
|
|
"as3vm_XML_set_prettyPrinting",
|
|
"as3vm_XML_settings",
|
|
"as3vm_XML_text",
|
|
"as3vm_XML_toString",
|
|
"as3vm_XML_toXMLString",
|
|
"as3vm_XML_valueOf",
|
|
)
|
|
|
|
# The single, uniform error code every stub passes (raw/durango:9, 20, ... 878).
|
|
DUMMY_EXCEPTION_CODE = 0x74
|
|
|
|
|
|
class ReconstructedAs3vmClassesBaseDummyTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
missing = [str(path) for path in (SOURCE, HEADER, SUPPORT)
|
|
if not path.exists()]
|
|
if missing:
|
|
raise AssertionError(
|
|
"missing as3vm_classes_base_dummy runtime inputs: "
|
|
+ ", ".join(missing))
|
|
cls.temp = tempfile.TemporaryDirectory()
|
|
cls.base = Path(cls.temp.name) / "as3vm_classes_base_dummy.dylib"
|
|
build = subprocess.run([
|
|
"clang", "-dynamiclib", "-std=c11", "-O2", "-Wall", "-Wextra",
|
|
"-Werror", "-Wl,-undefined,dynamic_lookup",
|
|
"-DIGGY_RECONSTRUCT_AS3VM_CLASSES_BASE_DUMMY_DURANGO=1",
|
|
"-I", str(RECONSTRUCTED),
|
|
str(SOURCE), str(SUPPORT), "-o", str(cls.base),
|
|
], capture_output=True, text=True)
|
|
if build.returncode:
|
|
raise AssertionError(build.stdout + build.stderr)
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
cls.temp.cleanup()
|
|
|
|
def setUp(self):
|
|
unique = (Path(self.temp.name) /
|
|
f"as3vm_classes_base_dummy_{self._testMethodName}.dylib")
|
|
shutil.copyfile(self.base, unique)
|
|
self.lib = ctypes.CDLL(str(unique))
|
|
self._bind(self.lib)
|
|
self.lib.as3vm_classes_base_dummy_test_reset()
|
|
self._keep = []
|
|
|
|
def _bind(self, lib):
|
|
void_p = ctypes.c_void_p
|
|
lib.as3vm_classes_base_dummy_test_reset.restype = None
|
|
lib.as3vm_classes_base_dummy_test_reset.argtypes = []
|
|
lib.as3vm_classes_base_dummy_test_exception_count.restype = (
|
|
ctypes.c_size_t)
|
|
lib.as3vm_classes_base_dummy_test_exception_count.argtypes = []
|
|
lib.as3vm_classes_base_dummy_test_last_exception_code.restype = (
|
|
ctypes.c_int32)
|
|
lib.as3vm_classes_base_dummy_test_last_exception_code.argtypes = []
|
|
lib.as3vm_classes_base_dummy_test_last_exception_vm.restype = void_p
|
|
lib.as3vm_classes_base_dummy_test_last_exception_vm.argtypes = []
|
|
# Every one of the 80 exports is `void fn(void *frame)`.
|
|
for name in EXPORTS:
|
|
fn = getattr(lib, name)
|
|
fn.restype = None
|
|
fn.argtypes = [void_p]
|
|
|
|
def _exception_count(self):
|
|
return self.lib.as3vm_classes_base_dummy_test_exception_count()
|
|
|
|
def _last_code(self):
|
|
return self.lib.as3vm_classes_base_dummy_test_last_exception_code()
|
|
|
|
def _last_vm(self):
|
|
return (self.lib.as3vm_classes_base_dummy_test_last_exception_vm()
|
|
or 0) & MASK64
|
|
|
|
def _frame(self, vm):
|
|
# raw/durango:9 the stub reads `*param_1` (frame[0]) as the vm handle it
|
|
# hands to as3vm_exception_GC; nothing else in the frame is touched.
|
|
frame = (ctypes.c_uint64 * 4)()
|
|
self._keep.append(frame)
|
|
frame[0] = vm & MASK64
|
|
return ctypes.addressof(frame)
|
|
|
|
def _invoke(self, name, vm):
|
|
self.lib.as3vm_classes_base_dummy_test_reset()
|
|
result = getattr(self.lib, name)(self._frame(vm))
|
|
return result
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# The whole-module invariant: all 80 stubs raise 0x74 with vm==frame[0].
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_all_80_exports_raise_e4x_unsupported_uniformly(self):
|
|
# raw/durango: every one of the 80 bodies is
|
|
# as3vm_exception_GC(*param_1, 0x74); return;
|
|
# -- one throw, the ONE shared code 0x74, vm == frame[0], no return
|
|
# value. Exercising all 80 pins the "uniform across every method" claim.
|
|
self.assertEqual(len(EXPORTS), 80)
|
|
self.assertEqual(len(set(EXPORTS)), 80)
|
|
for index, name in enumerate(EXPORTS):
|
|
vm = (0xC0DE0000_00000000 | (index + 1)) & MASK64
|
|
result = self._invoke(name, vm)
|
|
self.assertIsNone(result, name) # void return.
|
|
self.assertEqual(self._exception_count(), 1, name) # exactly once.
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE, name)
|
|
self.assertEqual(self._last_vm(), vm, name) # vm==frame[0].
|
|
|
|
def test_all_codes_are_identical_single_value(self):
|
|
# Stronger form of "uniform": collect the code every stub passes and
|
|
# assert the set is the single value {0x74} -- no method deviates.
|
|
codes = set()
|
|
for name in EXPORTS:
|
|
self._invoke(name, 0x1234)
|
|
codes.add(self._last_code())
|
|
self.assertEqual(codes, {DUMMY_EXCEPTION_CODE})
|
|
|
|
# ------------------------------------------------------------------ #
|
|
# Representative per-category spot checks (QName / XML / XMLList /
|
|
# __construct / getter / setter) -- same contract, read individually.
|
|
# ------------------------------------------------------------------ #
|
|
|
|
def test_qname_construct_raises_0x74(self):
|
|
# raw/durango:6-11 as3vm_QName__construct throws 0x74.
|
|
self._invoke("as3vm_QName__construct", 0xAA00)
|
|
self.assertEqual(self._exception_count(), 1)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0xAA00)
|
|
|
|
def test_qname_valueof_getter_raises_0x74(self):
|
|
# raw/durango:50-55 as3vm_QName_valueOf throws 0x74.
|
|
self._invoke("as3vm_QName_valueOf", 0xBB00)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0xBB00)
|
|
|
|
def test_xml_construct_raises_0x74(self):
|
|
# raw/durango:303-308 as3vm_XML__construct throws 0x74.
|
|
self._invoke("as3vm_XML__construct", 0xCC00)
|
|
self.assertEqual(self._exception_count(), 1)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0xCC00)
|
|
|
|
def test_xml_get_pretty_printing_getter_raises_0x74(self):
|
|
# raw/durango:499-506 as3vm_XML_get_prettyPrinting throws 0x74.
|
|
self._invoke("as3vm_XML_get_prettyPrinting", 0xDD00)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0xDD00)
|
|
|
|
def test_xml_set_pretty_printing_setter_raises_0x74(self):
|
|
# raw/durango:818-825 as3vm_XML_set_prettyPrinting throws 0x74 -- the
|
|
# setters behave exactly like the getters (no store, just the throw).
|
|
self._invoke("as3vm_XML_set_prettyPrinting", 0xEE00)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0xEE00)
|
|
|
|
def test_xmllist_length_raises_0x74(self):
|
|
# raw/durango:204-209 as3vm_XMLList_length throws 0x74.
|
|
self._invoke("as3vm_XMLList_length", 0xFF00)
|
|
self.assertEqual(self._exception_count(), 1)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0xFF00)
|
|
|
|
def test_xmllist_construct_raises_0x74(self):
|
|
# raw/durango:61-66 as3vm_XMLList__construct throws 0x74.
|
|
self._invoke("as3vm_XMLList__construct", 0x9900)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
self.assertEqual(self._last_vm(), 0x9900)
|
|
|
|
def test_repeated_calls_are_independent_and_deterministic(self):
|
|
# No hidden state: two calls to the same stub each fire once with the
|
|
# same code, and the recorded vm tracks the caller's frame[0].
|
|
self._invoke("as3vm_XML_toXMLString", 0x1111)
|
|
self.assertEqual(self._last_vm(), 0x1111)
|
|
self._invoke("as3vm_XML_toXMLString", 0x2222)
|
|
self.assertEqual(self._exception_count(), 1)
|
|
self.assertEqual(self._last_vm(), 0x2222)
|
|
self.assertEqual(self._last_code(), DUMMY_EXCEPTION_CODE)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|