#!/usr/bin/env python3 """Verify a sandbox's deliberate uncaught exception, never arbitrary failure.""" import re import resource import signal import subprocess import sys def main() -> int: executable, expected_code = sys.argv[1:] # These examples deliberately terminate; avoid writing core dumps. resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) result = subprocess.run([executable], capture_output=True, text=True, timeout=25) sys.stdout.write(result.stdout) sys.stderr.write(result.stderr) diagnostic = rf"Error: .*\(code No\.: \d+ \[{re.escape(expected_code)}\]\)" if result.returncode == -signal.SIGABRT and re.search(diagnostic, result.stderr): print(f"Verified expected exception: {expected_code}") return 0 print( f"Expected SIGABRT with SERiF error {expected_code}; got exit {result.returncode}", file=sys.stderr, ) return 1 if __name__ == '__main__': raise SystemExit(main())