Extend simulation runtime coverage and kinematics support
This commit is contained in:
90
scripts/generate_kinematics_registry_report.py
Normal file
90
scripts/generate_kinematics_registry_report.py
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate deterministic evidence for the static kinematics registry."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
INPUTS = {
|
||||
"linuxcnc_header": "linuxcnc/src/emc/kinematics/kinematics.h",
|
||||
"sim_header": "wasm-core/include/sim_kinematics.h",
|
||||
"implementation": "wasm-core/src/sim_kinematics_registry.c",
|
||||
"kinematics_implementation": "wasm-core/src/sim_kinematics.c",
|
||||
"test": "wasm-core/tests/sim_kinematics_registry_test.c",
|
||||
"config_xyzac": "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini",
|
||||
"config_genser": "linuxcnc/configs/sim/axis/vismach/puma/puma560.ini",
|
||||
"config_pentapod": "linuxcnc/configs/sim/axis/pentapod/pentapod.ini",
|
||||
}
|
||||
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def run_json(command: list[str], root: Path) -> dict[str, object]:
|
||||
result = subprocess.run(command, cwd=root, check=False, text=True, capture_output=True)
|
||||
if result.returncode:
|
||||
raise RuntimeError(f"{command[0]} exited {result.returncode}: {result.stderr.strip()}")
|
||||
for line in result.stdout.splitlines():
|
||||
if line.lstrip().startswith("{"):
|
||||
item = json.loads(line)
|
||||
if item.get("schema") == "kinematics-registry-samples.v1":
|
||||
return item
|
||||
raise RuntimeError("runner did not emit kinematics-registry-samples.v1")
|
||||
|
||||
|
||||
def generate(root: Path, output: Path) -> dict[str, object]:
|
||||
root = root.resolve()
|
||||
native = run_json([str(root / "build-native/sim_kinematics_registry_test")], root)
|
||||
wasm = run_json(["node", str(root / "build-wasm/sim_kinematics_registry_wasm_test.js")], root)
|
||||
report = {
|
||||
"schema": "kinematics-registry-report.v1",
|
||||
"status": "partial",
|
||||
"implementation_status": "verified",
|
||||
"source_records": {name: {"path": path, "sha256": sha256(root / path)} for name, path in INPUTS.items()},
|
||||
"configuration_candidates": [
|
||||
{"id": "xyzac-trt", "kind": "real", "path": INPUTS["config_xyzac"], "type": 2, "coordinates": "XYZAC", "parameters": ["offsets", "tool", "limits"]},
|
||||
{"id": "genser-puma560", "kind": "real", "path": INPUTS["config_genser"], "type": 13, "coordinates": "XYZABC", "parameters": ["DH", "solver", "limits"]},
|
||||
{"id": "pentapod", "kind": "real", "path": INPUTS["config_pentapod"], "type": 18, "coordinates": "XYZAB", "parameters": ["geometry", "tool", "solver", "limits"]},
|
||||
],
|
||||
"registry": {
|
||||
"abi_version": 1,
|
||||
"entry_count": native["count"],
|
||||
"verified_entries": native["verified"],
|
||||
"capability_union": native["capability_union"],
|
||||
"parameter_union": native["parameter_union"],
|
||||
"state_hash": native["registry_hash"],
|
||||
"capabilities": {"forward": 1, "inverse": 2, "identity": 4, "iterative": 8, "switchable": 16, "extra_joints": 32, "duplicate_coordinates": 64},
|
||||
"parameters": {"mapping": 1, "limits": 2, "offsets": 4, "tool": 8, "pivot": 16, "geometry": 32, "DH": 64, "solver": 128},
|
||||
},
|
||||
"validation": {"lookup_status": native["lookup_status"], "iterative_genser_and_DH_status": native["iterative_require"], "type_mismatch": native["type_mismatch"], "coordinate_error": native["coordinate_error"], "joint_error": native["joint_error"], "unknown_name": native["unknown_name"], "path_name": native["path_name"], "range_error": native["range_error"], "capability_error": native["capability_error"], "parameter_error": native["parameter_error"]},
|
||||
"samples": {
|
||||
"native": native,
|
||||
"wasm": wasm,
|
||||
"byte_identical_json": json.dumps(native, sort_keys=True, separators=(",", ":")) == json.dumps(wasm, sort_keys=True, separators=(",", ":")),
|
||||
"state_hash_identical": native["registry_hash"] == wasm["registry_hash"],
|
||||
},
|
||||
"native_wasm": {"status": "passed", "native_command": "build-native/sim_kinematics_registry_test", "wasm_command": "node build-wasm/sim_kinematics_registry_wasm_test.js"},
|
||||
"oracle": {"status": "blocked", "reason": "linuxcnc/unit_tests/kinematics is absent from the locked source", "blocked_samples": ["18-entry registry", "capability requirements", "parameter masks", "real config validation", "unknown/path names"]},
|
||||
}
|
||||
report["report_sha256"] = hashlib.sha256(json.dumps(report, sort_keys=True, separators=(",", ":")).encode()).hexdigest()
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(json.dumps(report, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8")
|
||||
return report
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parents[1])
|
||||
parser.add_argument("--output", type=Path, default=Path("coverage/kinematics-registry.report.json"))
|
||||
args = parser.parse_args()
|
||||
report = generate(args.repo_root, args.repo_root / args.output)
|
||||
print(f"kinematics_registry={report['status']} native_wasm={report['native_wasm']['status']} oracle={report['oracle']['status']}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user