Extend simulation runtime coverage and kinematics support
This commit is contained in:
99
scripts/generate_userkins_report.py
Normal file
99
scripts/generate_userkins_report.py
Normal file
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate deterministic evidence for statically linked userk and ugenser."""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
INPUTS = {
|
||||
"userk_source": "linuxcnc/src/emc/kinematics/userkfuncs.c",
|
||||
"ugenser_source": "linuxcnc/src/emc/kinematics/ugenserkins.c",
|
||||
"genser_source": "linuxcnc/src/emc/kinematics/genserkins.c",
|
||||
"genser_functions": "linuxcnc/src/emc/kinematics/genserfuncs.c",
|
||||
"userk_config": "linuxcnc/configs/sim/axis/vismach/scara/scara.ini",
|
||||
"ugenser_config": "linuxcnc/configs/sim/axis/vismach/puma/puma560.ini",
|
||||
"ugenser_dh": "linuxcnc/configs/sim/axis/vismach/puma/puma560_dh.hal",
|
||||
"implementation": "wasm-core/src/sim_userkins.c",
|
||||
"header": "wasm-core/include/sim_kinematics.h",
|
||||
"test": "wasm-core/tests/sim_userkins_test.c",
|
||||
}
|
||||
|
||||
|
||||
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") == "userkins-samples.v1":
|
||||
return item
|
||||
raise RuntimeError("runner did not emit userkins-samples.v1")
|
||||
|
||||
|
||||
def generate(root: Path, output: Path) -> dict[str, object]:
|
||||
root = root.resolve()
|
||||
native = run_json([str(root / "build-native/sim_userkins_test")], root)
|
||||
wasm = run_json(["node", str(root / "build-wasm/sim_userkins_wasm_test.js")], root)
|
||||
userk_config = (root / INPUTS["userk_config"]).read_text(encoding="utf-8")
|
||||
ugenser_config = (root / INPUTS["ugenser_config"]).read_text(encoding="utf-8")
|
||||
ugenser_source = (root / INPUTS["ugenser_source"]).read_text(encoding="utf-8")
|
||||
report = {
|
||||
"schema": "userkins-kinematics-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": "shipped-scara-userk-slot", "kind": "real", "path": INPUTS["userk_config"], "scan": "kinstype==2 (userk" in userk_config, "implementation": "identity template", "coordinates": "XYZCAB"},
|
||||
{"id": "shipped-puma560-genser", "kind": "real", "path": INPUTS["ugenser_config"], "scan": "KINEMATICS= genserkins" in ugenser_config, "implementation": "ugenser static adapter over genser", "coordinates": "XYZABC"},
|
||||
{"id": "static-descriptor-regression", "kind": "derived", "path": INPUTS["test"], "implementations": ["userk.identity", "ugenser.static"], "purpose": "ABI/capability checks, FK/IK calls, switch slot binding, and native/WASM comparison"},
|
||||
],
|
||||
"static_contract": {
|
||||
"abi_version": native["abi_version"],
|
||||
"capabilities": {"forward": 1, "inverse": 2, "static": 4, "sample_mask": native["capabilities"]},
|
||||
"implementations": {"1": "identity", "2": "genser"},
|
||||
"switch_binding": {"slot": 2, "active_after_select": native["active_mode"]},
|
||||
"dynamic_host_loading": "forbidden; paths, slash-delimited names, and host shared libraries return SIM_KIN_ERR_DYNAMIC_MODULE",
|
||||
},
|
||||
"ugenser_scope": {
|
||||
"legacy_cli_status": "excluded",
|
||||
"source_warning_present": "Declining usage" in ugenser_source and "functioning in its current state is doubtful" in ugenser_source,
|
||||
"adaptation": "reuse the verified statically linked genser FK/IK implementation; do not port gettimeofday, stdin, or HAL process lifecycle",
|
||||
},
|
||||
"error_boundaries": {"abi_version": -710, "capability": -711, "dynamic_module": -712, "missing_or_uninitialized_module": -708},
|
||||
"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["identity"]["state_hash"], native["ugenser"]["state_hash"]] == [wasm["identity"]["state_hash"], wasm["ugenser"]["state_hash"]],
|
||||
"state_hash_stable": native["identity"]["state_hash"] == native["identity"]["repeat_hash"] and native["ugenser"]["state_hash"] == native["ugenser"]["repeat_hash"],
|
||||
},
|
||||
"native_wasm": {"status": "passed", "native_command": "build-native/sim_userkins_test", "wasm_command": "node build-wasm/sim_userkins_wasm_test.js"},
|
||||
"oracle": {"status": "blocked", "reason": "linuxcnc/unit_tests/kinematics is absent from the locked source; the deprecated ugenser CLI is not an approved replacement", "blocked_samples": ["userk identity template", "ugenser static adapter", "ABI mismatch", "capability mismatch", "dynamic module rejection", "uninitialized module"]},
|
||||
}
|
||||
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/userkins-kinematics.report.json"))
|
||||
args = parser.parse_args()
|
||||
report = generate(args.repo_root, args.repo_root / args.output)
|
||||
print(f"userkins={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