43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
import subprocess
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class PosemathRuntimeTests(unittest.TestCase):
|
|
def test_native_posemath_binary(self):
|
|
binary = ROOT / "build-native/sim_posemath_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_posemath_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_posemath_normalize", "sim_posemath_dot", "sim_posemath_line_point",
|
|
"sim_posemath_segment_validate", "sim_posemath_segment_point",
|
|
"sim_tp_init", "sim_tp_step", "sim_tp_state_hash"):
|
|
self.assertIn(symbol, text)
|
|
|
|
def test_report_records_inputs_outputs_and_determinism(self):
|
|
report = __import__("json").loads((ROOT / "coverage/posemath-runtime.report.json").read_text(encoding="utf-8"))
|
|
self.assertEqual(report["schema"], "posemath-runtime-report.v2")
|
|
self.assertGreater(report["inputs"]["file_count"], 0)
|
|
self.assertGreater(report["outputs"]["file_count"], 0)
|
|
self.assertTrue(report["determinism"]["byte_identical"])
|
|
self.assertTrue(report["determinism"]["state_hash_identical"])
|
|
|
|
def test_posemath_source_is_linked(self):
|
|
cmake = (ROOT / "wasm-core/CMakeLists.txt").read_text(encoding="utf-8")
|
|
self.assertIn("posemath.cc", cmake)
|
|
self.assertIn("target_link_libraries(sim_core PUBLIC sim_posemath)", cmake)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|