diff options
| author | shelbykb2 <80599220+shelbykb2@users.noreply.github.com> | 2026-11-21 13:16:17 -0700 |
|---|---|---|
| committer | shelbykb2 <80599220+shelbykb2@users.noreply.github.com> | 2026-11-21 13:27:44 -0700 |
| commit | 8ea0e072dccc5d957235a71d7c1ee3816e839c08 (patch) | |
| tree | fe298b7f5e68bfa59f6f00a9c0f23000646c2bb0 /runtime/src/pe_loader.cpp | |
| parent | dcf5f44879ffa7cc1a1b61e284568b03c39d9885 (diff) | |
tests: repair the stale stdin handle pytest's fd capture leaves on Windows; mutation test without cwd=HERE
On Windows `python -m pytest tests` fails at random places with
"OSError: [WinError 6] The handle is invalid" (subprocess.py, _make_inheritable).
pytest's default fd capture replaces fd 0 with os.dup2(), which closes the
handle fd 0 had, but the process's STD_INPUT_HANDLE keeps that number.
subprocess starts from GetStdHandle(), so a child that has its output captured
but is given no stdin=/input= (23 of the 25 call sites in tests/) gets a closed
handle, or, once the number has been reused, some unrelated file. Logged per
hook, the same number was a file, a pipe and invalid within one two-test
session. In conftest._has_amdgpu the OSError is caught, so a working llvm-mc
was reported as missing and all of test_translate.py skipped.
Fix in one place: when tests/conftest.py loads (before its llvm-mc probe) and
STD_INPUT_HANDLE is not fd 0's handle, point it at a NUL handle of our own.
Nothing happens on Linux, with -s or --capture=sys, or without pytest: there
the two handles are equal (checked for python -I <file>, python -m unittest
and unittest discover with console, NUL and pipe stdin), so the stdlib entry
points cannot hit this and need nothing. Per-call stdin=DEVNULL was the
alternative; the next new test would bring the failure back. A config file
forcing --capture=sys would change what is captured for everyone.
_has_amdgpu keeps catching OSError: a candidate that is not a program arrives
as a plain OSError (WinError 216), and it must be skipped, not crash collection.
Only stdin is repaired. STD_OUTPUT_HANDLE and STD_ERROR_HANDLE go stale the
same way, but fd 1 and fd 2 change handles for every test phase, and every
test that redirects a child's output redirects both streams, so subprocess
never reads those two. A test that redirects only one (stdout=PIPE alone,
check_output) would still fail under fd capture: use capture_output=True.
Separately, run_semantics() started its child with cwd=tests/semantic. Windows
refuses a working directory over 258 characters (WinError 267), so the mutation
tests failed in a checkout in a deep folder (measured with a 250-character
root, where tests/semantic is 265). The child now finds test_ps_semantics
through PYTHONPATH.
Tested on Windows 11, Python 3.14.7, pytest 9.2.0, main d51bddc:
- pytest tests, two runs each. Before: 6 and 44 failed without LLVM_MC, 94 and
6 failed with it. After: 6 failed, 823 passed, 65 skipped without, and
6 failed, 883 passed, 4 skipped, 1 xfailed with, both runs. The 6 are
test_rtti_scan needing pefile, which is not installed here; the skip reasons
are unchanged (ffmpeg, SCARAB_REF, llvm-mc).
- STD_INPUT_HANDLE forced to a number that is never valid, LLVM_MC set:
44 failed and all 61 translator tests skipped before (the probe rejected
llvm-mc), same as the clean run after. The unforced 94-failure run above has
50 of them in conftest's Shader.validate (spirv-as).
- A copy with a 250-character root: test_mutations 14 failed before, passes after.
- Ubuntu (WSL), Python 3.14.4: unittest discover -s tests/semantic and the
python -I tests/test_*.py loop print the same before and after.
No GPU involved. AI-assisted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/pe_loader.cpp')
0 files changed, 0 insertions, 0 deletions