97 lines
4.8 KiB
Python
97 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic evidence for xyzac/xyzbc TRT kinematics."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
INPUTS = {
|
|
"xyzac_source": "linuxcnc/src/emc/kinematics/xyzac-trt-kins.c",
|
|
"xyzbc_source": "linuxcnc/src/emc/kinematics/xyzbc-trt-kins.c",
|
|
"trt_source": "linuxcnc/src/emc/kinematics/trtfuncs.c",
|
|
"xyzac_config": "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini",
|
|
"xyzbc_config": "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzbc-trt.ini",
|
|
"implementation": "wasm-core/src/sim_kinematics.c",
|
|
"test": "wasm-core/tests/sim_kinematics_test.c",
|
|
}
|
|
|
|
|
|
def sha256(path: Path) -> str:
|
|
return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
|
|
|
|
def run_sample(command: list[str], root: Path) -> dict[str, object]:
|
|
completed = subprocess.run(command, cwd=root, check=False, text=True, capture_output=True)
|
|
if completed.returncode != 0:
|
|
raise RuntimeError(f"{command[0]} exited {completed.returncode}: {completed.stderr.strip()}")
|
|
for line in reversed(completed.stdout.splitlines()):
|
|
if line.startswith("{"):
|
|
return json.loads(line)
|
|
raise RuntimeError(f"{command[0]} did not emit a TRT sample")
|
|
|
|
|
|
def generate(root: Path, output: Path) -> dict[str, object]:
|
|
root = root.resolve()
|
|
native_all = run_sample([str(root / "build-native/sim_kinematics_test")], root)
|
|
wasm_all = run_sample(["node", str(root / "build-wasm/sim_kinematics_wasm_test.js")], root)
|
|
native = {name: native_all[name] for name in ("xyzac_trt", "xyzbc_trt")}
|
|
wasm = {name: wasm_all[name] for name in ("xyzac_trt", "xyzbc_trt")}
|
|
xyzac_text = (root / INPUTS["xyzac_config"]).read_text(encoding="utf-8")
|
|
xyzbc_text = (root / INPUTS["xyzbc_config"]).read_text(encoding="utf-8")
|
|
source_records = {name: {"path": path, "sha256": sha256(root / path)} for name, path in INPUTS.items()}
|
|
native_json = json.dumps(native, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
wasm_json = json.dumps(wasm, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
|
report = {
|
|
"schema": "trt-kinematics-report.v1",
|
|
"status": "partial",
|
|
"implementation_status": "verified",
|
|
"source_records": source_records,
|
|
"configuration_candidates": {
|
|
"xyzac": {"path": INPUTS["xyzac_config"], "kinematics": "xyzac-trt-kins", "sparm": "identityfirst", "joints": 5, "scan": "xyzac-trt-kins sparm=identityfirst" in xyzac_text},
|
|
"xyzbc": {"path": INPUTS["xyzbc_config"], "kinematics": "xyzbc-trt-kins", "sparm": "identityfirst", "joints": 5, "scan": "xyzbc-trt-kins sparm=identityfirst" in xyzbc_text},
|
|
},
|
|
"rotation_chain": {
|
|
"xyzac": "C about Z then A about X with y/z/tool offsets",
|
|
"xyzbc": "C about Z then B about Y with x/z/tool offsets",
|
|
"direction": "LinuxCNC opposite conventional rotary directions retained",
|
|
"identityfirst": "switchkins type 0 identity, type 1 TRT, type 2 userk",
|
|
},
|
|
"offsets": {
|
|
"xyzac": {"x_rot_point": 20.0, "y_offset": 3.0, "tool_offset": 100.0},
|
|
"xyzbc": {"x_offset": 5.0, "z_offset": 2.0, "tool_offset": 50.0},
|
|
},
|
|
"samples": {"native": native, "wasm": wasm, "byte_identical_json": native_json == wasm_json},
|
|
"boundaries": {
|
|
"xyzac_round_trip": "verified",
|
|
"xyzbc_round_trip": "verified",
|
|
"xyzbc_b_90_singular": "SIM_KIN_ERR_SINGULAR verified",
|
|
"missing_required_axis": "SIM_KIN_ERR_CONFIGURATION verified by existing contract tests",
|
|
"state_hash": "native/WASM identical",
|
|
},
|
|
"oracle": {"status": "blocked", "reason": "linuxcnc/unit_tests/kinematics is absent from the locked source"},
|
|
"native_wasm": {"status": "passed", "native_command": "build-native/sim_kinematics_test", "wasm_command": "node build-wasm/sim_kinematics_wasm_test.js"},
|
|
}
|
|
report["report_sha256"] = hashlib.sha256(json.dumps(report, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")).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/trt-kinematics.report.json"))
|
|
args = parser.parse_args()
|
|
report = generate(args.repo_root, args.repo_root / args.output)
|
|
print(f"trt={report['status']} native_wasm={report['native_wasm']['status']} oracle={report['oracle']['status']}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|