mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
ps_oracle: exit 77 when the oracle becomes unavailable during run() (PS-ORACLE-UNAVAILABLE-EXIT)
main() caught Unavailable only around the Oracle constructor. A missing AMD clang (assemble) or a vk_harness exit 77 raised from run() escaped as a traceback with exit 1. run() now returns 77 with the message on stderr, as the module docstring documents. Test: Cli.test_unavailable_during_run_is_77 (fails on the old code), plus a ValueError case that still returns 2.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
"""tools/ps_oracle.py: the msgpack subset, the PAL ELF rewrite that puts new pixel-shader code in a pipeline binary,
|
||||
the binary file format, and (with LEONIDA_PS_ORACLE_BUILD set to a runtime build and an AMD GPU selected) a real
|
||||
draw with patched code. Standard library only."""
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
@ -280,6 +282,42 @@ class Cli(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
self.assertEqual(P.main(["--build", d, "--show-template"]), 77)
|
||||
|
||||
def _run_with_failing_oracle(self, error):
|
||||
"""main() with an Oracle whose run() raises `error`; returns (exit code, stdout, stderr)."""
|
||||
class FakeOracle:
|
||||
wave64, device = True, ""
|
||||
|
||||
def __init__(self, *a, **k):
|
||||
pass
|
||||
|
||||
def run(self, lines, sets):
|
||||
raise error
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
asm = os.path.join(d, "prog.txt")
|
||||
with open(asm, "w", encoding="utf-8") as f:
|
||||
f.write("s_endpgm\n")
|
||||
out, err = io.StringIO(), io.StringIO()
|
||||
with patch.object(P, "Oracle", FakeOracle), contextlib.redirect_stdout(out), \
|
||||
contextlib.redirect_stderr(err):
|
||||
code = P.main(["--build", d, "--asm", asm])
|
||||
return code, out.getvalue(), err.getvalue()
|
||||
|
||||
def test_unavailable_during_run_is_77(self):
|
||||
# assemble() without an AMD clang, or vk_harness returning 77, raises Unavailable from run()
|
||||
code, _, err = self._run_with_failing_oracle(P.Unavailable("no AMD clang (test)"))
|
||||
self.assertEqual(code, 77)
|
||||
self.assertEqual(err, "ps_oracle unavailable: no AMD clang (test)\n")
|
||||
self.assertNotIn("Traceback", err)
|
||||
|
||||
def test_value_error_during_run_is_still_2(self):
|
||||
code, _, err = self._run_with_failing_oracle(ValueError("the assembler rejected the code"))
|
||||
self.assertEqual(code, 2)
|
||||
self.assertEqual(err, "ps_oracle: the assembler rejected the code\n")
|
||||
|
||||
def test_json_overwriting_an_input_is_refused(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
asm = os.path.join(d, "prog.txt")
|
||||
|
||||
@ -833,6 +833,9 @@ def main(argv=None):
|
||||
return 0
|
||||
try:
|
||||
px = o.run(lines, sets)
|
||||
except Unavailable as e: # no clang or no vk_harness result while running: the documented 77
|
||||
print(f"ps_oracle unavailable: {e}", file=sys.stderr)
|
||||
return 77
|
||||
except (ValueError, KeyError, IndexError, TypeError) as e:
|
||||
print(f"ps_oracle: {e}", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
Reference in New Issue
Block a user