Files
linuxcncWebWASM/scripts/test_hal_runtime.py

34 lines
1.3 KiB
Python

#!/usr/bin/env python3
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"):
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)
if __name__ == "__main__":
unittest.main()