38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
import json
|
|
import subprocess
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
import generate_motion_report
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class MotionRuntimeTests(unittest.TestCase):
|
|
def test_native_motion_binary(self):
|
|
binary = ROOT / "build-native/sim_motion_queue_test"
|
|
if not binary.is_file():
|
|
self.skipTest("native build has not been generated")
|
|
result = subprocess.run([str(binary)], cwd=ROOT, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
self.assertEqual(result.returncode, 0, result.stderr.decode(errors="replace"))
|
|
|
|
def test_wasm_exports_motion_api(self):
|
|
module = ROOT / "build-wasm/linuxcnc-sim-core.js"
|
|
if not module.is_file():
|
|
self.skipTest("WASM build has not been generated")
|
|
text = module.read_text(encoding="utf-8")
|
|
for symbol in ("sim_motion_init", "sim_motion_enqueue", "sim_motion_step", "sim_motion_state_hash", "sim_motion_canonical"):
|
|
self.assertIn(symbol, text)
|
|
|
|
def test_report_contract(self):
|
|
report = json.loads((ROOT / "coverage/motion-runtime.report.json").read_text(encoding="utf-8"))
|
|
self.assertEqual(report["schema"], "motion-runtime-report.v1")
|
|
self.assertGreater(report["inputs"]["file_count"], 0)
|
|
self.assertEqual(report["outputs"]["file_count"], len(generate_motion_report.OUTPUTS))
|
|
self.assertTrue(report["canonical"]["byte_identical"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|