#629 sets WER LocalDumps for python.exe in each Windows e2e job, and a crashing pytest-xdist worker still left no dump. The pytest controllers of the runner are born with the error mode 0x0003 (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX), every child inherits the mode of its parent, and a process with SEM_NOGPFAULTERRORBOX (0x0002) never invokes Windows Error Reporting, so no worker crash reached LocalDumps. https://learn.microsoft.com/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode The "Windows Error Reporting keeps a full dump..." step of each Windows job now also exports INVPW_WER_DUMPS=<the dumps folder> to $GITHUB_ENV. tests/conftest.py calls tests/_wer_error_mode.py in pytest_configure (the controller and every xdist worker run it): when that variable names an existing folder on Windows, the process clears bit 0x0002 of its error mode and keeps the others, and appends "pid <n> error mode born 0x.., now 0x.." to invpw-evidence/dumps/error-mode.log. Nothing is written to stdout or stderr, and nothing happens on Linux or in a job that did not set LocalDumps. Tests: the rule test of the Windows jobs (tests/test_every_windows_job_keeps_a_dump_of_a_crashing_python.py) now requires the export in the LocalDumps step of every Windows job, with the folder of DumpFolder and no other place that sets it (red on the previous e2e.yml, naming the job); a real child python born with 0x0003 (and 0x8003, 0x0002, 0x0001, 0x0000) ends with the born mode minus 0x0002 and leaves its evidence line, and without the variable or with a missing folder the mode is unchanged (tests/test_every_pytest_process_clears_the_gp_fault_error_box_on_windows.py, a Windows file: only the row of Windows names it, min_tests 4061 on Linux, 4073 on Windows).
57 lines
3.0 KiB
Python
57 lines
3.0 KiB
Python
"""Every pytest process of a Windows job that keeps WER dumps lets Windows Error Reporting see its crash: the bit SEM_NOGPFAULTERRORBOX of its error mode is cleared.
|
|
|
|
A process whose error mode carries SEM_NOGPFAULTERRORBOX (0x0002) never invokes Windows Error Reporting when it dies from an unhandled exception, so the
|
|
LocalDumps key of python.exe that e2e.yml sets (a full dump into ``$RUNNER_TEMP/invpw-evidence/dumps/python``) is never read: the pytest controllers of the
|
|
runner are born with 0x0003 (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX), and every child inherits the mode of its parent, so every xdist worker is born
|
|
with it too and a worker that crashes leaves no dump.
|
|
https://learn.microsoft.com/windows/win32/api/errhandlingapi/nf-errhandlingapi-seterrormode
|
|
|
|
``clear_for_wer_dumps()``: tests/conftest.py calls it in ``pytest_configure``, which the controller and every xdist worker run. It acts only when ALL of this
|
|
holds, so nothing changes on a developer's machine, on Linux, or in a job that did not set LocalDumps:
|
|
|
|
* the system is Windows;
|
|
* ``$INVPW_WER_DUMPS`` (the one variable the "Windows Error Reporting keeps a full dump..." step of each Windows job of e2e.yml exports to ``$GITHUB_ENV``) names an
|
|
existing folder: the folder the dumps go to.
|
|
|
|
It clears bit 0x0002 and keeps every other bit of the mode, and appends one line to ``error-mode.log`` in the parent of that folder (``invpw-evidence/dumps``, inside the evidence the job
|
|
uploads): ``pid <n> error mode born 0x<hex>, now 0x<hex>``, so the evidence shows the bit was cleared in every process. It writes nothing to stdout or stderr, and it
|
|
never raises: a failure is a line of that log, not a failed test.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
#: The variable the Windows jobs export: the folder LocalDumps of python.exe writes to.
|
|
ENV_VAR = "INVPW_WER_DUMPS"
|
|
LOG_NAME = "error-mode.log"
|
|
#: SEM_NOGPFAULTERRORBOX: the process is not reported to Windows Error Reporting.
|
|
SEM_NOGPFAULTERRORBOX = 0x0002
|
|
|
|
|
|
def clear_for_wer_dumps(environ=None) -> None:
|
|
environ = os.environ if environ is None else environ
|
|
if sys.platform != "win32":
|
|
return
|
|
folder = environ.get(ENV_VAR)
|
|
if not folder or not os.path.isdir(folder):
|
|
return
|
|
log = Path(folder).resolve().parent / LOG_NAME
|
|
try:
|
|
import ctypes
|
|
kernel32 = ctypes.WinDLL("kernel32")
|
|
kernel32.GetErrorMode.restype = ctypes.c_uint
|
|
kernel32.SetErrorMode.argtypes = [ctypes.c_uint]
|
|
kernel32.SetErrorMode.restype = ctypes.c_uint
|
|
born = kernel32.GetErrorMode()
|
|
kernel32.SetErrorMode(born & ~SEM_NOGPFAULTERRORBOX)
|
|
line = "pid %d error mode born 0x%04x, now 0x%04x\n" % (os.getpid(), born, kernel32.GetErrorMode())
|
|
except Exception as exc: # best effort: the evidence says what went wrong, the test run goes on
|
|
line = "pid %d error mode not cleared: %s: %s\n" % (os.getpid(), type(exc).__name__, exc)
|
|
try:
|
|
with open(log, "a", encoding="utf-8") as handle:
|
|
handle.write(line)
|
|
except OSError:
|
|
pass
|