"""Exercise the native Windows crash monitor with an entirely synthetic child.""" import os from pathlib import Path import shutil import struct import subprocess import sys import tempfile import unittest REPO = Path(__file__).resolve().parents[2] @unittest.skipUnless(__name__ == "__main__", "run through the windows_crash_monitor CTest target") class CrashMonitorTest(unittest.TestCase): def setUp(self): tmp = tempfile.TemporaryDirectory(prefix="leonida crash test ") self.addCleanup(tmp.cleanup) self.report = Path(tmp.name) / "private run" def run_fixture(self, mode, *args, seconds=10): env = dict(os.environ, LEONIDA_TEST_CRASH_MODE=mode) result = subprocess.run( [MONITOR, REPO, self.report, str(seconds), FIXTURE, subprocess.list2cmdline([str(FIXTURE), *args])], env=env, capture_output=True, timeout=30, ) return result.returncode & 0xffffffff def check_artifacts(self, code, exception): data = (self.report / "crash.dmp").read_bytes() self.assertEqual(data[:4], b"MDMP") count, offset = struct.unpack_from("