shader: accept argv and guard file and path errors in disasm_rdna2 with CLI suite #2338

Merged
Ammmae0x merged 1 commit from upstream-pr/2346 into main 2026-11-25 13:14:30 +00:00
Ammmae0x commented 2026-11-25 13:05:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-25T13:05:29Z.


Change

Update tools/disasm_rdna2.py CLI entry point and add a dedicated pure-Python unit and CLI validation suite (tests/disasm_rdna2_cli_check.py, registered as rdna2_cli_checks in CMakeLists.txt):

  • main(argv: list[str] | None = None) -> int forwards argv to parser.parse_args(argv).
  • Reject empty or whitespace-only --hex input via parser.error (exit code 2, no traceback).
  • Reject --output collisions with input .bin files (single-file and directory targets) using Path.resolve() and Path.samefile() so input binaries are never overwritten.
  • Guard --output directory checks, target file/directory reads, and atomic --output listing writes (tempfile.NamedTemporaryFile + Path.replace with finally temp cleanup) inside try/except OSError, suppressing partial output when any target fails and exiting cleanly with code 1 and zero raw tracebacks.

Verification

Verified on commit dac64774 (rebased onto upstream/main 14e8b6a5):

  • out/pe-env/Scripts/python.exe -B tests/disasm_rdna2_cli_check.py -> Ran 11 tests in 0.394s / OK (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py -> Ran 156 tests in 4.934s / OK (skipped=19) (exit 0; 19 LLVM cross-check tests skipped because LLVM_LIB is unset in this environment)
  • out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py -> form coverage checks passed (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Self-test passed. Checked 19 Markdown files and 453 links. (exit 0)
  • out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py -> Self-test passed. Checked 1631 tracked source, script and build/CI files: no bidirectional controls. (exit 0)

Evidence and follow-up

  • All fixtures in tests/disasm_rdna2_cli_check.py are synthetic RDNA 2 machine-code words constructed in-memory (s_nop, s_mov_b32 with 32-bit literal, s_endpgm, and truncated/trailing byte tails).
  • Negative controls cover missing targets, mixed valid + missing targets with --output, empty/whitespace/odd/invalid --hex, missing targets with no --hex, unreadable file/directory OSError paths, --output path collisions (direct, ..-resolved, directory-mode, and hardlink/samefile), existing-directory --output, unwritable parent paths, and atomic replace failure temp cleanup.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6605145825 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2346). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-25T13:05:29Z. --- ## Change Update `tools/disasm_rdna2.py` CLI entry point and add a dedicated pure-Python unit and CLI validation suite (`tests/disasm_rdna2_cli_check.py`, registered as `rdna2_cli_checks` in `CMakeLists.txt`): - `main(argv: list[str] | None = None) -> int` forwards `argv` to `parser.parse_args(argv)`. - Reject empty or whitespace-only `--hex` input via `parser.error` (exit code 2, no traceback). - Reject `--output` collisions with input `.bin` files (single-file and directory targets) using `Path.resolve()` and `Path.samefile()` so input binaries are never overwritten. - Guard `--output` directory checks, target file/directory reads, and atomic `--output` listing writes (`tempfile.NamedTemporaryFile` + `Path.replace` with `finally` temp cleanup) inside `try/except OSError`, suppressing partial output when any target fails and exiting cleanly with code 1 and zero raw tracebacks. ## Verification Verified on commit `dac64774` (rebased onto `upstream/main` `14e8b6a5`): - `out/pe-env/Scripts/python.exe -B tests/disasm_rdna2_cli_check.py` -> `Ran 11 tests in 0.394s` / `OK` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py` -> `Ran 156 tests in 4.934s` / `OK (skipped=19)` (exit 0; 19 LLVM cross-check tests skipped because `LLVM_LIB` is unset in this environment) - `out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py` -> `form coverage checks passed` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/docs_links_check.py` -> `Self-test passed. Checked 19 Markdown files and 453 links.` (exit 0) - `out/pe-env/Scripts/python.exe -B tests/bidi_controls_check.py` -> `Self-test passed. Checked 1631 tracked source, script and build/CI files: no bidirectional controls.` (exit 0) ## Evidence and follow-up - All fixtures in `tests/disasm_rdna2_cli_check.py` are synthetic RDNA 2 machine-code words constructed in-memory (`s_nop`, `s_mov_b32` with 32-bit literal, `s_endpgm`, and truncated/trailing byte tails). - Negative controls cover missing targets, mixed valid + missing targets with `--output`, empty/whitespace/odd/invalid `--hex`, missing targets with no `--hex`, unreadable file/directory `OSError` paths, `--output` path collisions (direct, `..`-resolved, directory-mode, and hardlink/`samefile`), existing-directory `--output`, unwritable parent paths, and atomic replace failure temp cleanup. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-25 14:04:54 +00:00
tedin7 commented 2026-11-25 14:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:13:57Z.

Review: COMMENTED


Review of head dac64774fd

Result: 0 P1, 0 P2.

Scope: tools/disasm_rdna2.py (main takes argv, returns an exit code, guards file and path errors, writes the listing atomically, refuses an output path that collides with an input), the new tests/disasm_rdna2_cli_check.py, and the rdna2_cli_checks CTest registration in CMakeLists.txt. The disassembly logic is unchanged and no ISA semantics are touched. Clean-room: only public code and in-repo fixtures are used.

Checked:

  • --hex accepts whitespace and rejects empty input.
  • A directory passed as --output is rejected.
  • A missing or unreadable input gives exit code 1 and no partial listing.
  • The temp file is removed on failure.
  • No other open PR touches tools/disasm_rdna2.py.

Commands run locally:

  • python3 -B tests/disasm_rdna2_cli_check.py: 11 tests OK
  • python3 tests/docs_links_check.py: OK (453 links)
  • python3 tests/bidi_controls_check.py: OK
  • git diff --check origin/main...HEAD: clean
  • Mutation 1: drop the not had_error guard on writing the listing. The suite FAILED (1 failure).
  • Mutation 2: return 1 if had_error else 0 changed to return 0. The suite FAILED (1 failure).
  • Mutation 3: disable the empty-hex check. The suite FAILED (4 failures).
  • All mutations were reverted with git checkout -- ..
  • python3 x2w_pipe.py win2025 2346 --wait 3600: Debug (dev preset) 40/40 PASS and Release -O2 40/40 PASS, including rdna2_cli_checks and rdna2_tools_check.
  • CI Build and test on Windows is SUCCESS.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6058264073 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2346#pullrequestreview-6058264073). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:13:57Z. **Review:** COMMENTED --- Review of head dac64774fd823aa2602d37882bca832314592750 Result: 0 P1, 0 P2. Scope: `tools/disasm_rdna2.py` (main takes argv, returns an exit code, guards file and path errors, writes the listing atomically, refuses an output path that collides with an input), the new `tests/disasm_rdna2_cli_check.py`, and the `rdna2_cli_checks` CTest registration in `CMakeLists.txt`. The disassembly logic is unchanged and no ISA semantics are touched. Clean-room: only public code and in-repo fixtures are used. Checked: - `--hex` accepts whitespace and rejects empty input. - A directory passed as `--output` is rejected. - A missing or unreadable input gives exit code 1 and no partial listing. - The temp file is removed on failure. - No other open PR touches `tools/disasm_rdna2.py`. Commands run locally: - `python3 -B tests/disasm_rdna2_cli_check.py`: 11 tests OK - `python3 tests/docs_links_check.py`: OK (453 links) - `python3 tests/bidi_controls_check.py`: OK - `git diff --check origin/main...HEAD`: clean - Mutation 1: drop the `not had_error` guard on writing the listing. The suite FAILED (1 failure). - Mutation 2: `return 1 if had_error else 0` changed to `return 0`. The suite FAILED (1 failure). - Mutation 3: disable the empty-hex check. The suite FAILED (4 failures). - All mutations were reverted with `git checkout -- .`. - `python3 x2w_pipe.py win2025 2346 --wait 3600`: Debug (dev preset) 40/40 PASS and Release -O2 40/40 PASS, including `rdna2_cli_checks` and `rdna2_tools_check`. - CI `Build and test on Windows` is SUCCESS. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2338
No description provided.