tests: report the failed load in the relocation-free control instead of a TypeError #1816

Merged
default-cybe merged 1 commit from upstream-pr/1823 into main 2026-11-24 19:24:31 +00:00
default-cybe commented 2026-11-24 19:15:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by default-cybe on 2026-11-24T19:15:59Z.


Change

In tests/cpu/native_reloc_free_check.py, the unreserved control loads the
DYNAMIC_BASE-cleared copy with LoadLibraryExW. If that load fails, the child
reports base: None and the GetLastError code. The diagnostic then formatted
free['base'] with :#x, so cpu_native_reloc_free stopped with:

TypeError: unsupported format string passed to NoneType.__format__

That error hides the Win32 error the child had reported. The test now prints the
whole child result, which is what the RELOCS_STRIPPED control a few lines below
already does:

AssertionError: DYNAMIC_BASE cleared / windows: unreserved control failed: {'base': None, 'preferred': 1941100888064, 'error': 126, 'pairs': 249, 'matches': 0}

This changes the failure message only. The pass condition is unchanged, and the
change has no effect on a host where the load works. It is an independent
problem in the check added for #77 and adjusted in #1040. One line changed.

Verification

Commit 757cea99 on ecc6e6ce. Windows 11 build 26300, portable MSVC 14.52 (no
Visual Studio install), Debug preset. I built only the four inputs:

cmake --build --preset dev --target pe_map cpu_import_original cpu_import_provider cpu_register_probe
ctest --preset dev --no-tests=error -R '^cpu_native_reloc_free$' -V
  • On this host the debug CRT (ucrtbased.dll) is not in System32, so the
    unreserved LoadLibraryExW fails with 126 (ERROR_MOD_NOT_FOUND). Before the
    change the test failed with the TypeError above. After the change it fails with
    the AssertionError above, which names error 126.
  • With the debug CRT made loadable (os.add_dll_directory for the toolchain and
    UCRT folders, through a sitecustomize.py outside the repository), the test passes
    with the change: the copy loads at its preferred base when nothing is reserved,
    the reserved cases match 249 of 249 call_mix results under Windows and pe_map,
    and the RELOCS_STRIPPED case is refused with error 487 and "relocations stripped".
  • I also ran a deterministic check. It calls check() on the real fixtures and
    replaces child so the unreserved control returns
    {'base': None, 'error': 126, ...}. On main it raises the TypeError. With
    the change it raises an AssertionError that contains 'base': None and
    'error': 126.

Tested: cpu_native_reloc_free with and without a loadable debug CRT, and the
forced-failure check above before and after the change.

Not tested: the Release preset, a host with Visual Studio installed (debug CRT
in System32), and the CI pr preset. That preset does not select this test.

Evidence and follow-up

No new fixture. Error 126 on this host comes from the portable toolchain (the
debug CRT is on PATH, and Python's DLL search ignores PATH). It is not a bug in
the loader or in pe_map, so this PR changes only the message.

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. (No new fixture; the failure path is the subject of the change.)
  • I updated README/docs when a capability or build requirement changed. (Not needed.)
  • I did not include game files, dumps, distribution links or secrets.

AI use: I prepared this change with Conclave (model cliproxy/claude-opus-5-5).
It found the issue, wrote the one-line change and ran the checks listed above
on my machine.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589488811 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1823). Originally posted by [default-cybe](https://github.com/default-cybe) on 2026-11-24T19:15:59Z. --- ## Change In `tests/cpu/native_reloc_free_check.py`, the unreserved control loads the `DYNAMIC_BASE`-cleared copy with `LoadLibraryExW`. If that load fails, the child reports `base: None` and the `GetLastError` code. The diagnostic then formatted `free['base']` with `:#x`, so `cpu_native_reloc_free` stopped with: ```text TypeError: unsupported format string passed to NoneType.__format__ ``` That error hides the Win32 error the child had reported. The test now prints the whole child result, which is what the `RELOCS_STRIPPED` control a few lines below already does: ```text AssertionError: DYNAMIC_BASE cleared / windows: unreserved control failed: {'base': None, 'preferred': 1941100888064, 'error': 126, 'pairs': 249, 'matches': 0} ``` This changes the failure message only. The pass condition is unchanged, and the change has no effect on a host where the load works. It is an independent problem in the check added for #77 and adjusted in #1040. One line changed. ## Verification Commit 757cea99 on ecc6e6ce. Windows 11 build 26300, portable MSVC 14.52 (no Visual Studio install), Debug preset. I built only the four inputs: ```powershell cmake --build --preset dev --target pe_map cpu_import_original cpu_import_provider cpu_register_probe ctest --preset dev --no-tests=error -R '^cpu_native_reloc_free$' -V ``` - On this host the debug CRT (`ucrtbased.dll`) is not in System32, so the unreserved `LoadLibraryExW` fails with 126 (`ERROR_MOD_NOT_FOUND`). Before the change the test failed with the `TypeError` above. After the change it fails with the `AssertionError` above, which names error 126. - With the debug CRT made loadable (`os.add_dll_directory` for the toolchain and UCRT folders, through a `sitecustomize.py` outside the repository), the test passes with the change: the copy loads at its preferred base when nothing is reserved, the reserved cases match 249 of 249 `call_mix` results under Windows and `pe_map`, and the `RELOCS_STRIPPED` case is refused with error 487 and "relocations stripped". - I also ran a deterministic check. It calls `check()` on the real fixtures and replaces `child` so the unreserved control returns `{'base': None, 'error': 126, ...}`. On `main` it raises the `TypeError`. With the change it raises an `AssertionError` that contains `'base': None` and `'error': 126`. **Tested:** `cpu_native_reloc_free` with and without a loadable debug CRT, and the forced-failure check above before and after the change. **Not tested:** the Release preset, a host with Visual Studio installed (debug CRT in System32), and the CI `pr` preset. That preset does not select this test. ## Evidence and follow-up No new fixture. Error 126 on this host comes from the portable toolchain (the debug CRT is on PATH, and Python's DLL search ignores PATH). It is not a bug in the loader or in `pe_map`, so this PR changes only the message. ## 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. (No new fixture; the failure path is the subject of the change.) - [x] I updated README/docs when a capability or build requirement changed. (Not needed.) - [x] I did not include game files, dumps, distribution links or secrets. **AI use:** I prepared this change with Conclave (model `cliproxy/claude-opus-5-5`). It found the issue, wrote the one-line change and ran the checks listed above on my machine.
upstream-sync closed this pull request 2026-11-24 20:00:48 +00:00
tedin7 commented 2026-11-24 20:00:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:23:29Z.

Review: COMMENTED


Reviewed commit 757cea99979cd25e723c4d688347958ce417284b (tests/cpu/native_reloc_free_check.py): no P1/P2 findings.

When the unreserved DYNAMIC_BASE-cleared LoadLibraryExW control fails, the child returns {"base": None, "preferred": <int>, "error": <win32_err>, ...}. Printing the whole free dict in AssertionError avoids the NoneType.__format__ TypeError on {free['base']:#x} and preserves the Win32 error code, matching the RELOCS_STRIPPED unreserved control below it. The pass condition (free["base"] != free["preferred"]) is unchanged, and line 131 remains safe because preferred is always a non-zero VirtualAlloc integer.

Verification

  • Linux checks:
    • git diff --check origin/main...HEAD — passed
    • python3 -B tests/bidi_controls_check.py — passed (1313 tracked files, no bidirectional controls)
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at 757cea99979cd25e723c4d688347958ce417284b:
    • Debug (--preset dev):
      • cmake --build --preset dev --target cpu_import_original cpu_import_provider cpu_register_probe pe_map -- -j 8 (3.18s)
      • ctest --preset dev -R '^cpu_native_reloc_free$' --parallel 6 --no-tests=error --output-on-failure — 1/1 passed (cpu_native_reloc_free 1.17s)
    • Release /O2 (--preset release):
      • cmake --build --preset release --target cpu_import_original cpu_import_provider cpu_register_probe pe_map -- -j 8 (0.29s)
      • ctest --preset release -R '^cpu_native_reloc_free$' --parallel 6 --no-tests=error --output-on-failure — 1/1 passed (cpu_native_reloc_free 1.22s)
  • Mutation checks (Windows Server 2025, --preset dev, -R '^cpu_native_reloc_free$'):
    • Forced LoadLibraryExW failure on the unreserved control (image + ".missing") with the PR change: failed with AssertionError: DYNAMIC_BASE cleared / windows: unreserved control failed: {'base': None, 'preferred': 2192559374336, 'error': 126, 'pairs': 249, 'matches': 0}.
    • Same forced load failure with the diagnostic reverted to main's {free['base']:#x}: failed with TypeError: unsupported format string passed to NoneType.__format__.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045854659 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1823#pullrequestreview-6045854659). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:23:29Z. **Review:** COMMENTED --- Reviewed commit `757cea99979cd25e723c4d688347958ce417284b` (`tests/cpu/native_reloc_free_check.py`): no P1/P2 findings. When the unreserved `DYNAMIC_BASE`-cleared `LoadLibraryExW` control fails, the child returns `{"base": None, "preferred": <int>, "error": <win32_err>, ...}`. Printing the whole `free` dict in `AssertionError` avoids the `NoneType.__format__` `TypeError` on `{free['base']:#x}` and preserves the Win32 error code, matching the `RELOCS_STRIPPED` unreserved control below it. The pass condition (`free["base"] != free["preferred"]`) is unchanged, and line 131 remains safe because `preferred` is always a non-zero `VirtualAlloc` integer. ### Verification - **Linux checks**: - `git diff --check origin/main...HEAD` — passed - `python3 -B tests/bidi_controls_check.py` — passed (`1313` tracked files, no bidirectional controls) - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)** at `757cea99979cd25e723c4d688347958ce417284b`: - **Debug (`--preset dev`)**: - `cmake --build --preset dev --target cpu_import_original cpu_import_provider cpu_register_probe pe_map -- -j 8` (`3.18s`) - `ctest --preset dev -R '^cpu_native_reloc_free$' --parallel 6 --no-tests=error --output-on-failure` — **1/1 passed** (`cpu_native_reloc_free` `1.17s`) - **Release `/O2` (`--preset release`)**: - `cmake --build --preset release --target cpu_import_original cpu_import_provider cpu_register_probe pe_map -- -j 8` (`0.29s`) - `ctest --preset release -R '^cpu_native_reloc_free$' --parallel 6 --no-tests=error --output-on-failure` — **1/1 passed** (`cpu_native_reloc_free` `1.22s`) - **Mutation checks (Windows Server 2025, `--preset dev`, `-R '^cpu_native_reloc_free$'`)**: - Forced `LoadLibraryExW` failure on the unreserved control (`image + ".missing"`) with the PR change: failed with `AssertionError: DYNAMIC_BASE cleared / windows: unreserved control failed: {'base': None, 'preferred': 2192559374336, 'error': 126, 'pairs': 249, 'matches': 0}`. - Same forced load failure with the diagnostic reverted to `main`'s `{free['base']:#x}`: failed with `TypeError: unsupported format string passed to NoneType.__format__`. 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!1816
No description provided.