]> FriiDump Source - friidump.git/blob - tests/test_linux_rawio_contract.py
FriiDump 0.5.3.16 candidate: add native reports and Linux Xbox support
[friidump.git] / tests / test_linux_rawio_contract.py
1 #!/usr/bin/env python3
2 from pathlib import Path
3 import sys
4
5 root = Path(__file__).resolve().parents[1]
6 main_c = (root / "src" / "friidump.c").read_text(encoding="utf-8")
7 rawio_c = (root / "src" / "linux_rawio.c").read_text(encoding="utf-8")
8 dvd_drive_c = (root / "libfriidump" / "dvd_drive.c").read_text(encoding="utf-8")
9 dumper_c = (root / "libfriidump" / "dumper.c").read_text(encoding="utf-8")
10 windows_utils_c = (root / "libfriidump" / "xbox_ref" / "utils.c").read_text(encoding="utf-8")
11 cmake = (root / "CMakeLists.txt").read_text(encoding="utf-8")
12 linux_doc = (root / "docs" / "LINUX.md").read_text(encoding="utf-8")
13 helper = (root / "validation" / "friidump-linux-rawio-capability.sh").read_text(encoding="utf-8")
14 validator = (
15     root
16     / "validation"
17     / "friidump-v0.5.3.16-pf1-candidate21-linux-live-validation.sh"
18 ).read_text(encoding="utf-8")
19
20 checks = {
21     "runtime reads CapEff": 'strncmp(line, "CapEff:", 7)' in rawio_c,
22     "CAP_SYS_RAWIO bit is explicit": "FRIIDUMP_LINUX_CAP_SYS_RAWIO 17" in (root / "src" / "linux_rawio.h").read_text(encoding="utf-8"),
23     "vendor path has runtime preflight": "friidump_linux_rawio_preflight" in main_c,
24     "root execution is refused": "refuses this Linux vendor-command path while running as root" in main_c,
25     "missing capability is explained": "Linux vendor-command authorization is unavailable" in main_c,
26     "build emits raw-I/O warning": "Linux vendor-command paths require CAP_SYS_RAWIO" in cmake,
27     "helper installs exact file capability": "sudo setcap cap_sys_rawio=ep" in helper,
28     "helper verifies capability": "FRIIDUMP LINUX RAW-I/O CAPABILITY INSTALL: PASS" in helper,
29     "helper warns rebuild clears capability": "rebuilding, replacing, copying, or re-extracting" in helper,
30     "validator has capability phase": "capability_phase" in validator,
31     "validator normalizes future timestamps": "Future source timestamp preflight" in validator,
32     "preflight note buffer covers long executable paths": "char note[1536]" in main_c,
33     "fallback executable path is bounded without snprintf": "fallback_dir" in main_c and "suffix_len" in main_c,
34     "Linux documentation names CAP_SYS_RAWIO": "CAP_SYS_RAWIO" in linux_doc,
35     "Linux documentation forbids whole-process sudo": "Do not run FriiDump itself with `sudo`" in linux_doc,
36     "Linux media cycle releases door lock": "CDROM_LOCKDOOR, locked ? 1 : 0" in dvd_drive_c and "dvd_set_door_lock (dvd, false)" in dvd_drive_c,
37     "Linux media cycle restores door lock": "dvd_set_door_lock (dvd, true)" in dvd_drive_c,
38     "Linux media-cycle failure remains recoverable": "the door remains unlocked for recovery" in dvd_drive_c,
39     "Linux documentation explains software tray cycle": "CDROM_LOCKDOOR" in linux_doc and "software tray cycle" in linux_doc,
40     "Linux Xbox handshake uses explicit SG_IO": "#include <scsi/sg.h>" in dvd_drive_c and "io.interface_id = 'S'" in dvd_drive_c and "ioctl (dvd -> fd, SG_IO, &io)" in dvd_drive_c,
41     "Linux Xbox handshake preserves explicit CDB lengths": "io.cmd_len = (unsigned char) cdb_len" in dvd_drive_c and '"9-mode-select-sticky-descrambling"' in dvd_drive_c,
42     "Linux Xbox handshake preserves Windows timeouts": "120000" in dvd_drive_c and "10000" in dvd_drive_c,
43     "Linux Xbox handshake emits transport diagnostics": "[XBOX-SGIO] step=%s" in dvd_drive_c and "host=0x%04X" in dvd_drive_c and "driver=0x%04X" in dvd_drive_c,
44     "Linux media-cycle evidence reaches persistent log": 'xbox_ref_log_fprintf (stderr, "[XBOX] Linux media-cycle released' in dvd_drive_c and 'xbox_ref_log_fprintf (stderr, "[XBOX] Linux media-cycle restored' in dvd_drive_c,
45     "generic RecoveryKick removed": "RecoveryKick(" not in windows_utils_c and "recovery_kick" not in dvd_drive_c and "recovery_kick" not in dumper_c,
46     "Windows state sequence ported": "dvd_xbox_prepare_game_view" in dvd_drive_c and "Entry state appears locked/video; attempting the full handshake directly without a media transition" in dvd_drive_c,
47     "Windows refresh cadence exact": "dvd_refresh_volume (dvd);" in dvd_drive_c and "dvd_sleep_ms (2000);" in dvd_drive_c and "dvd_wait_ready (dvd, 30000)" in dvd_drive_c,
48     "single tray-cycle recovery": "performing one tray-cycle recovery and retry" in dvd_drive_c and "dvd_media_cycle (dvd, NULL)" in dvd_drive_c,
49     "portable dumper uses shared Windows sequence": dumper_c.count("disc_xbox_prepare_game_view") >= 2 and "Windows sequence 1/4" in dumper_c and "Windows sequence 4/4" in dumper_c,
50 }
51
52 failed = []
53 for label, ok in checks.items():
54     print(f"{'PASS' if ok else 'FAIL'}: {label}")
55     if not ok:
56         failed.append(label)
57
58 if failed:
59     raise SystemExit("Linux raw-I/O contract failed: " + ", ".join(failed))
60
61 print("LINUX RAW-I/O SOURCE/DOCUMENTATION CONTRACT: PASS")