java_object_identity_native_suite.py
tests/java_object_identity_native_suite.py · 41 line(s) · py
#!/usr/bin/env python3
"""Run the SLeeLa-native Java Object identity smoke program."""
from __future__ import annotations
import os
import pathlib
import subprocess
import sys
ROOT = pathlib.Path(__file__).resolve().parents[1]
BINARY = pathlib.Path(os.environ.get("SLEELA_BIN", ROOT / "impl/build/sleela"))
SOURCE = ROOT / "tests/java_object_identity_native.sleela"
EXPECTED = [
"BOUND=true",
"IDENTITY-EQUAL=true",
"DISTINCT-HEAP=false",
"HASH-STABLE=true",
"CLASS=sample.Widget",
"MONITOR=false",
]
DIAGNOSTIC_PREFIXES = ("[memory-manager]", "[security]", "[defender]", "verification: PASS (")
def main() -> int:
if not BINARY.is_file():
raise FileNotFoundError(f"SLeeLa executable not found: {BINARY}")
result = subprocess.run([str(BINARY), "run", str(SOURCE)], cwd=ROOT,
env=os.environ.copy(), text=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = [line for line in result.stdout.replace("\r\n", "\n").splitlines()
if not line.startswith(DIAGNOSTIC_PREFIXES)]
while output and not output[-1].strip():
output.pop()
if result.returncode != 0 or output != EXPECTED:
print(f"FAIL: exit={result.returncode}; expected={EXPECTED!r}; actual={output!r}", file=sys.stderr)
print(result.stdout, file=sys.stderr)
return 1
print(f"PASS: SLeeLa-native Java Object identity ({len(EXPECTED)} assertions)")
return 0
if __name__ == "__main__":
raise SystemExit(main())