#!/usr/bin/env python3 """ AVM Dataset Panel — Cross-Language Dispatcher Runs each language's existing AVM test harness and reports pass/fail. Uses the native test infrastructure of each language (no fragile JSON protocol). Languages tracked: python, rust, julia, r, c, cpp, go, fortran, scala, octave Status key: ✅ pass ❌ fail ⚪ untested 🔧 not compiled 🚫 missing """ import subprocess import sys import os import json from typing import Dict, Optional ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) # ── Language test runners ─────────────────────────────────────────── LANGUAGES: Dict[str, Optional[dict]] = { "Python": { "runner": lambda: _run_python_test(), "expected_max": 10, }, "Julia": { "runner": lambda: _run_julia_test(), "expected_max": 12, }, "R": { "runner": lambda: _run_r_test(), "expected_max": 5, }, "Rust": { "runner": lambda: _run_rust_test(), "expected_max": 5, }, "C": { "runner": lambda: _run_c_test(), "expected_max": 9, }, "C++": { "runner": lambda: _run_cpp_test(), "expected_max": 9, }, "Go": { "runner": lambda: _run_go_test(), "expected_max": 10, }, "Fortran": { "runner": lambda: _run_fortran_test(), "expected_max": 9, }, "Scala": { "runner": lambda: _run_scala_test(), "expected_max": 10, }, "Octave": { "runner": lambda: _run_octave_test(), "expected_max": 10, }, } def _run_with_timeout(cmd: list, cwd: str = ROOT, timeout: int = 60) -> dict: """Run a command and return parsed output.""" try: result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True, timeout=timeout) lines = (result.stdout + result.stderr).splitlines() passes = sum(1 for l in lines if "✅" in l or "✓" in l or "PASS" in l.upper() or "passed" in l.lower()) fails = sum(1 for l in lines if "❌" in l or "✗" in l or "FAIL" in l.upper() or "failed" in l.lower()) return { "passes": passes, "fails": fails, "stdout": result.stdout[-500:] if result.stdout else "", "stderr": result.stderr[-500:] if result.stderr else "", "returncode": result.returncode, } except FileNotFoundError: return {"error": "not_found"} except subprocess.TimeoutExpired: return {"error": "timeout"} except Exception as e: return {"error": str(e)} def _run_python_test() -> dict: test_script = os.path.join(ROOT, "tests", "test_avm_python.py") if os.path.exists(test_script): return _run_with_timeout([sys.executable, test_script]) # Fallback: inline test script = ''' import sys; sys.path.insert(0, 'python') from avm import * s = run(State(), [push_q16(5*65536), push_q16(3*65536), prim(Prim.ADD_SAT_Q16), halt()], 100) assert s.halted, "not halted" assert s.stack[0].val == 8*65536, f"got {s.stack[0].val}" print(" ✅ basic_add") print("1/1 Python AVM tests passed") ''' return _run_with_timeout([sys.executable, "-c", script]) def _run_julia_test() -> dict: julia_test = os.path.join(ROOT, "tests", "test_avm_julia.jl") if os.path.exists(julia_test): return _run_with_timeout(["julia", julia_test]) # Inline test script = r""" include("/home/allaun/SilverSight/julia/CoreFormalism/Q16_16.jl") include("/home/allaun/SilverSight/julia/AVMIsa/avm.jl") using .Q16_16, .AVM passed = 0 function check(cond, msg) global passed if cond passed += 1; println(" ✅ $msg") else println(" ❌ $msg") end end s = AVM.State() prog = AVM.Instr[ AVM.push_q16(5*65536), AVM.push_q16(3*65536), AVM.Instr(9, Int32(AVM.ADD_SAT_Q16), false), AVM.Instr(10, Int32(0), false), ] for _ in 1:100 if s.halted; break; end global s = AVM.step(s, prog) end check(s.halted, "halted") check(length(s.stack) == 1, "stack depth == 1") if length(s.stack) == 1 check(s.stack[1] == 8*65536, "5+3=8") end println("\n$passed/4 Julia AVM tests passed") """ return _run_with_timeout(["julia", "-e", script]) def _run_r_test() -> dict: r_test = os.path.join(ROOT, "tests", "test_avm_r.r") if os.path.exists(r_test): return _run_with_timeout(["Rscript", r_test]) script = r""" source("/home/allaun/SilverSight/r/AVMIsa/avm.r") passed <- 0 check <- function(cond, msg) { if (cond) { passed <<- passed + 1; cat(" ✅", msg, "\n") } else { cat(" ❌", msg, "\n") } } s <- run(State(0), list(push_q16(5*65536), push_q16(3*65536), prim_instr(PRIM_ADD_Q16), halt_instr()), 100L) check(s[["halted"]], "halted") check(length(s[["stack"]]) == 1, "stack depth == 1") if (length(s[["stack"]]) == 1) { check(s[["stack"]][[1]]$val == 8*65536, "5+3=8") } cat("\n", passed, "/4 R AVM tests passed\n") """ return _run_with_timeout(["Rscript", "-e", script]) def _run_rust_test() -> dict: return _run_with_timeout(["cargo", "test", "--", "--nocapture"], cwd=os.path.join(ROOT, "rust")) def _run_c_test() -> dict: # Compile and run result = _run_with_timeout( ["sh", "-c", "cd /home/allaun/SilverSight/c && gcc -o /tmp/test_avm_c test_avm.c -lm && /tmp/test_avm_c"], timeout=30 ) return result def _run_cpp_test() -> dict: result = _run_with_timeout( ["sh", "-c", "cd /home/allaun/SilverSight/cpp && g++ -o /tmp/test_avm_cpp test_avm.cpp && /tmp/test_avm_cpp"], timeout=30 ) return result def _run_go_test() -> dict: return _run_with_timeout(["go", "test", "-v"], cwd=os.path.join(ROOT, "go")) def _run_fortran_test() -> dict: result = _run_with_timeout( ["sh", "-c", "cd /home/allaun/SilverSight/fortran && gfortran -o /tmp/test_avm_f90 test_avm.f90 avm.f90 && /tmp/test_avm_f90"], timeout=30 ) return result def _run_scala_test() -> dict: return _run_with_timeout( ["sh", "-c", "cd /home/allaun/SilverSight/scala && scala-cli run TestAVM.scala 2>/dev/null"], timeout=60 ) def _run_octave_test() -> dict: return _run_with_timeout( ["sh", "-c", "cd /home/allaun/SilverSight/octave && octave --no-gui -q test_avm.m 2>/dev/null"], timeout=30 ) # ── Panel ─────────────────────────────────────────────────────────── def build_panel(): print("=" * 90) print("AVM Dataset Panel — Cross-Language Dispatcher") print("=" * 90) print() print("Running all language test harnesses...") print() results = {} for lang_name, config in LANGUAGES.items(): print(f" [{lang_name:8s}] ", end="", flush=True) result = config["runner"]() results[lang_name] = result if "error" in result: print(f"🚫 {result['error']}") else: p = result.get("passes", 0) f = result.get("fails", 0) status = "✅" if f == 0 and result.get("returncode", -1) == 0 else "❌" print(f"{status} {p} passed, {f} failed (rc={result.get('returncode')})") # Summary table print() print("-" * 90) print(f"{'Language':12s} {'Status':8s} {'Passed':8s} {'Failed':8s} {'Return':8s} Notes") print("-" * 90) total_pass = 0 total_fail = 0 all_pass = True for lang_name, result in results.items(): if "error" in result: status = "🚫" passes = 0 fails = 0 rc = result["error"] all_pass = False else: passes = result.get("passes", 0) fails = result.get("fails", 0) rc = result.get("returncode", -1) status = "✅" if fails == 0 and rc == 0 else "❌" if fails > 0 or rc != 0: all_pass = False total_pass += passes total_fail += fails notes = result.get("stderr", "")[:60] if "error" not in result else "" print(f"{lang_name:12s} {status:8s} {passes:8d} {fails:8d} {str(rc):8s} {notes}") print("-" * 90) print(f"\nTotal: {total_pass} passed, {total_fail} failed across {len(LANGUAGES)} languages") print(f"All languages{' ' if all_pass else ' NOT '}consistent") print() print("=" * 90) if __name__ == "__main__": build_panel()