40 lines
1.6 KiB
Python
40 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
import json
|
|
import subprocess
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class HalRuntimeTests(unittest.TestCase):
|
|
def test_native_hal_binary(self):
|
|
binary = ROOT / "build-native/sim_hal_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_header_declares_error_boundary(self):
|
|
header = (ROOT / "wasm-core/include/sim_hal.h").read_text(encoding="utf-8")
|
|
for token in ("SIM_HAL_ERR_TYPE", "SIM_HAL_ERR_FUNCTION", "SIM_HAL_ERR_REAL_EXCLUDED", "sim_hal_step", "sim_hal_register_corexy_by_hal", "sim_hal_corexy_transform"):
|
|
self.assertIn(token, header)
|
|
|
|
def test_wasm_exports_hal_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_hal_register_pin", "sim_hal_register_thread", "sim_hal_step"):
|
|
self.assertIn(symbol, text)
|
|
|
|
def test_corexy_hal_report(self):
|
|
report = json.loads((ROOT / "coverage/corexy-hal.report.json").read_text(encoding="utf-8"))
|
|
self.assertEqual(report["schema"], "corexy-hal-report.v1")
|
|
self.assertTrue(report["native_wasm"]["byte_identical_json"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|