Implement WebAssembly runtime and kinematics coverage
This commit is contained in:
37
scripts/test_interpreter_runtime.py
Normal file
37
scripts/test_interpreter_runtime.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
import generate_interpreter_report
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class InterpreterRuntimeTests(unittest.TestCase):
|
||||
def test_native_interpreter_binary(self):
|
||||
binary = ROOT / "build-native/sim_interpreter_test"
|
||||
if not binary.is_file():
|
||||
self.skipTest("native build has not been generated")
|
||||
import subprocess
|
||||
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_interpreter_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_interpreter_init", "sim_interpreter_execute", "sim_interpreter_canonical", "sim_interpreter_state_hash"):
|
||||
self.assertIn(symbol, text)
|
||||
|
||||
def test_report_is_deterministic_and_complete(self):
|
||||
report = __import__("json").loads((ROOT / "coverage/interpreter-runtime.report.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(report["schema"], "interpreter-runtime-report.v1")
|
||||
self.assertGreater(report["inputs"]["file_count"], 0)
|
||||
self.assertEqual(report["outputs"]["file_count"], len(generate_interpreter_report.OUTPUTS))
|
||||
self.assertTrue(report["canonical"]["byte_identical"])
|
||||
self.assertTrue(report["canonical"]["state_hash_identical"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user