Skip to content

Commit 669e608

Browse files
authored
test(helpers): narrow EGL device probe catch to MissingFunctionException (#3020)
select_headless_egl_device_for_cuda caught `except Exception: return None`, which violates the "Capability probes must not swallow real bugs" rule in cuda_core/tests/AGENTS.md. A real failure (ctypes drift, a pyglet internal rename, a transient EGL error) was swallowed and turned into None, which makes the caller fall back to EGL device 0 -- the broken path on the multi-GPU systems #2865 fixes -- so the test re-failed with the original CUDA_ERROR_INVALID_DEVICE and no sign the fix ran. The only genuine "extension not available" signal is pyglet.gl.lib.MissingFunctionException: link_EGL returns a stub for an unresolvable entry point, and the stub raises it when called. Narrow the catch to that type and let everything else propagate. EGL_FALSE returns are already handled as "no match", and the caller already skips when libEGL is absent, so no ImportError handling is needed. Follow-up to #2865. Refs #2864.
1 parent 608a37d commit 669e608

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

  • cuda_python_test_helpers/cuda_python_test_helpers

‎cuda_python_test_helpers/cuda_python_test_helpers/graphics.py‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ def select_headless_egl_device_for_cuda(cuda_device_ordinal: int) -> int | None:
3939
"""
4040
egl_cuda_device_nv = 0x323A
4141

42+
from pyglet.gl.lib import MissingFunctionException
43+
from pyglet.libs.egl import egl, eglext
44+
from pyglet.libs.egl.lib import link_EGL
45+
46+
egl_query_device_attrib_ext = link_EGL(
47+
"eglQueryDeviceAttribEXT",
48+
egl.EGLBoolean,
49+
[eglext.EGLDeviceEXT, egl.EGLint, ctypes.POINTER(ctypes.c_ssize_t)],
50+
)
51+
52+
# link_EGL returns a stub for an unresolvable entry point that raises
53+
# MissingFunctionException when called, so that is the only "extension not
54+
# available" signal. Anything else is a real bug and must propagate.
4255
try:
43-
from pyglet.libs.egl import egl, eglext
44-
from pyglet.libs.egl.lib import link_EGL
45-
46-
egl_query_device_attrib_ext = link_EGL(
47-
"eglQueryDeviceAttribEXT",
48-
egl.EGLBoolean,
49-
[eglext.EGLDeviceEXT, egl.EGLint, ctypes.POINTER(ctypes.c_ssize_t)],
50-
)
51-
5256
num_devices = egl.EGLint()
5357
if not eglext.eglQueryDevicesEXT(0, None, ctypes.byref(num_devices)) or num_devices.value <= 0:
5458
return None
@@ -62,7 +66,7 @@ def select_headless_egl_device_for_cuda(cuda_device_ordinal: int) -> int | None:
6266
found = egl_query_device_attrib_ext(devices[index], egl_cuda_device_nv, ctypes.byref(queried_ordinal))
6367
if found and queried_ordinal.value == cuda_device_ordinal:
6468
return index
65-
except Exception:
69+
except MissingFunctionException:
6670
return None
6771

6872
return None

0 commit comments

Comments
 (0)