138 lines
5.5 KiB
Python
138 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Mutation guardrails for the consumed Phase-1.0O result."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import copy
|
|
import importlib.util
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
def load(path: Path):
|
|
spec = importlib.util.spec_from_file_location("phase10o", path)
|
|
assert spec and spec.loader
|
|
module = importlib.util.module_from_spec(spec)
|
|
sys.modules[spec.name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def require(value: bool, message: str) -> None:
|
|
if not value:
|
|
raise RuntimeError(message)
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
root = args.root.resolve()
|
|
validator = load(root / "tools/validate_retroarch_phase10o.py")
|
|
record = validator.load_json(root / "manifests/retroarch/phase-1.0o-write-free-device-result.json")
|
|
cases = []
|
|
|
|
def case(name):
|
|
def register(function):
|
|
cases.append((name, function)); return function
|
|
return register
|
|
|
|
@case("01 all current authorizations are false")
|
|
def _(): require(validator.all_false(record["current_authorizations"], validator.AUTHORIZATION_FIELDS), "authority active")
|
|
|
|
@case("02 reauthorization fails")
|
|
def _():
|
|
value = dict(record["current_authorizations"]); value["device_execution_authorized"] = True
|
|
require(not validator.all_false(value, validator.AUTHORIZATION_FIELDS), "reauthorization accepted")
|
|
|
|
@case("03 artifact is consumed and ineligible")
|
|
def _(): require(validator.artifact_is_consumed_and_ineligible(record["artifact"]), "artifact rejected")
|
|
|
|
@case("04 artifact eligibility fails")
|
|
def _():
|
|
value = dict(record["artifact"]); value["execution_eligible"] = True
|
|
require(not validator.artifact_is_consumed_and_ineligible(value), "eligible artifact accepted")
|
|
|
|
@case("05 artifact hash mutation fails")
|
|
def _():
|
|
value = dict(record["artifact"]); value["sha256"] = "0" * 64
|
|
require(not validator.artifact_is_consumed_and_ineligible(value), "wrong artifact accepted")
|
|
|
|
@case("06 authorization is consumed")
|
|
def _(): require(validator.authorization_is_consumed(record["authorization"]), "receipt rejected")
|
|
|
|
@case("07 reusable authority fails")
|
|
def _():
|
|
value = dict(record["authorization"]); value["authority_inherited_by_future_action"] = True
|
|
require(not validator.authorization_is_consumed(value), "reusable authority accepted")
|
|
|
|
@case("08 transport is exactly one shot")
|
|
def _(): require(validator.transport_is_exact_one_shot(record["transport"]), "transport rejected")
|
|
|
|
@case("09 retry fails")
|
|
def _():
|
|
value = dict(record["transport"]); value["retry_count"] = 1
|
|
require(not validator.transport_is_exact_one_shot(value), "retry accepted")
|
|
|
|
@case("10 reconnect fails")
|
|
def _():
|
|
value = dict(record["transport"]); value["reconnect_count"] = 1
|
|
require(not validator.transport_is_exact_one_shot(value), "reconnect accepted")
|
|
|
|
@case("11 protocol result is exact")
|
|
def _(): require(validator.protocol_result_is_exact(record["protocol_result"]), "protocol rejected")
|
|
|
|
@case("12 invented D13 fails")
|
|
def _():
|
|
value = copy.deepcopy(record["protocol_result"]); value["stages"].insert(-2, "D13"); value["frame_count"] += 1
|
|
require(not validator.protocol_result_is_exact(value), "invented D13 accepted")
|
|
|
|
@case("13 invented successful flip fails")
|
|
def _():
|
|
value = copy.deepcopy(record["protocol_result"]); value["raw_results"]["D07_flip_submit"] = 0
|
|
require(not validator.protocol_result_is_exact(value), "successful flip invented")
|
|
|
|
@case("14 invented errno fails")
|
|
def _():
|
|
value = copy.deepcopy(record["protocol_result"]); value["raw_results"]["D07_saved_errno"] = 22
|
|
require(not validator.protocol_result_is_exact(value), "errno invented")
|
|
|
|
@case("15 terminal ordering is preserved")
|
|
def _(): require(record["protocol_result"]["frame_after_terminal"] == "D04_SEQUENCE_25", "ordering lost")
|
|
|
|
@case("16 successful runner terminal classification is forbidden")
|
|
def _(): require(record["protocol_result"]["valid_terminal_frame_received_classification"] is False, "terminal success invented")
|
|
|
|
@case("17 source binding is bounded")
|
|
def _(): require(validator.source_binding_is_bounded(record["source_binding"]), "source binding rejected")
|
|
|
|
@case("18 visible presentation remains unproven")
|
|
def _():
|
|
value = dict(record["source_binding"]); value["visible_presentation"] = "PROVEN"
|
|
require(not validator.source_binding_is_bounded(value), "visibility invented")
|
|
|
|
@case("19 cleanup remains unproven")
|
|
def _():
|
|
value = dict(record["source_binding"]); value["complete_cleanup"] = "PROVEN"
|
|
require(not validator.source_binding_is_bounded(value), "cleanup invented")
|
|
|
|
@case("20 E104 remains a generic post-flip label")
|
|
def _(): require(record["source_binding"]["e104_is_generic_framebuffer_fail_label_after_early_flip_failure"] is True, "E104 overclaimed")
|
|
|
|
failures = []
|
|
for name, function in cases:
|
|
try:
|
|
function(); print(f"PASS {name}")
|
|
except Exception as error: # noqa: BLE001 - mutation harness
|
|
failures.append(f"{name}: {error}"); print(f"FAIL {name}: {error}")
|
|
if failures:
|
|
return 1
|
|
print(f"Phase-1.0O guardrails passed: {len(cases)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|