Skip to content

shader_disasm: reset FAILED in main() and record read OSError in one() - #6190

Open
markankamaransheogarat-sys wants to merge 1 commit into
ItsNotRexed:mainfrom
markankamaransheogarat-sys:fix/shader-disasm-failed-reset-and-read-oserror
Open

markankamaransheogarat-sys wants to merge 1 commit into
ItsNotRexed:mainfrom
markankamaransheogarat-sys:fix/shader-disasm-failed-reset-and-read-oserror

Conversation

@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor

Summary

  • tools/shader_disasm.py:
    • Clear module-level FAILED at the start of main(argv=None) so repeated in-process calls do not fail from stale errors left by an earlier run.
    • Catch OSError when reading .fssm files in one() and record (path, e.strerror or str(e)) in FAILED (returning "failed") so an unreadable input fails cleanly via fail(...) instead of raising an unhandled traceback.
  • tests/test_shader_disasm.py: add FailedStateAndReadErrorTests covering stale FAILED reset across main() calls and PermissionError on an .fssm input.

Verification

  • python3 -m compileall -q tools/shader_disasm.py tests/test_shader_disasm.py -> passed.
  • python3 -I tests/test_shader_disasm.py -v -> Ran 31 tests in 1.890s -> OK.

AI-assisted.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Two overlapping calls to main(argv) can lose a read error at 47f2fb5c. Run A reads two synthetic shaders. One read fails. Before A checks its results, run B starts with a separate input and output directory. B clears the shared FAILED list. A prints {'failed': 1, 'clean': 1} and returns 0. Expected: A exits with status 1 and identifies bad.fssm. B returns 0.

The same input on this head gives status 1 when A runs alone. The parent 561b65a8 raises PermissionError for the read. All 31 tests in py -3.14 -I tests/test_shader_disasm.py pass on the head.

Keep the failure details local to each invocation. For example, each worker can return its result and diagnostic to the caller that owns it.

Reproduction on Windows: run the script below from the repository root with py -3.14 -I -. The events control the order. The read error uses the same kind of synthetic failure as the PR test.

import builtins, concurrent.futures, runpy, sys, tempfile, threading
from pathlib import Path
from unittest.mock import patch
sys.path.insert(0, "tools")
import shader_disasm as s
sample = runpy.run_path("tests/test_shader_disasm.py")["fssm"]()
recorded, resume = threading.Event(), threading.Event()
original_one, original_open = s.one, builtins.open
def wrapped_one(path, *args, **kwargs):
    result = original_one(path, *args, **kwargs)
    if result == "failed":
        recorded.set()
        assert resume.wait(10)
    return result
def opened(path, *args, **kwargs):
    if Path(path).name == "bad.fssm":
        raise PermissionError(13, "synthetic read failure", path)
    return original_open(path, *args, **kwargs)
with tempfile.TemporaryDirectory() as tmp:
    root = Path(tmp)
    for run, names in (("A", ["bad", "good"]), ("B", ["good"])):
        (root / run).mkdir()
        for name in names:
            (root / run / (name + ".fssm")).write_bytes(sample)
    def invoke(run):
        return s.main([str(root/run), "--out", str(root/(run+"-out")), "--backend", "python", "--jobs", "1"])
    with patch.object(s, "one", wrapped_one), patch.object(s, "open", opened, create=True), concurrent.futures.ThreadPoolExecutor(1) as pool:
        a = pool.submit(invoke, "A")
        try:
            assert recorded.wait(10)
            print("B status", invoke("B"))
        finally:
            resume.set()
        print("A status", a.result())

AI-assisted.

@leozinhoszg

Copy link
Copy Markdown
Contributor

Tested 47f2fb5c on Windows 11 Pro (26200), CPython 3.14.7, CPU only, no game files: pass with notes.

  • Ran tests/test_shader_disasm.py (31 OK), test_missing_input_exit_codes.py, test_fssm_crosscheck.py and test_rdna2_decode.py. All pass. compileall and git diff --check are clean. I also used a real Windows lock instead of the mock: a synthetic corpus of 30 good and 5 locked .fssm files, --backend python --jobs 8. Exit code 1 and one line, 5 shader(s) produced no disassembly, first ...: Permission denied (on main: a PermissionError traceback). The 30 good listings are written. No .tmp and no listing for the locked files is left behind. The old listing of a locked shader and a stale .s both survive, because the run stops before pruning.
  • Calling main() three times in sequence in one process (5 locked, then 1, then 0) gives exit 1 with count 5, exit 1 with count 1, then 0 with stale .s pruned. Overlapping calls are a different matter, as shdann shows above: the module-level FAILED is shared, so a second main() can clear the first one's entry. For context, the only caller today runs the tool as a subprocess (make_game.py:1027), so concurrent in-process calls only happen in tests. Returning each failure from one() to the main() that started it, as shdann suggests, would remove the shared state and the need for FAILED.clear(). Without FAILED.clear() (tools/shader_disasm.py:194), both new tests fail on the stale entry. Without the try (:152-157), the read test fails with PermissionError. With main's whole file put back, both fail with TypeError because main() takes no argv.
  • Nit: test_unreadable_fssm_reports_clean_error_via_failed clears shader_disasm.FAILED only when it passes (tests/test_shader_disasm.py:513). self.addCleanup(shader_disasm.FAILED.clear) would also clear it on failure. The comment at tools/shader_disasm.py:31 still says "first stderr line", but entries can now be read errors too.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants