|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
| 5 | +import ctypes |
5 | 6 | import sys |
6 | 7 | import time |
7 | 8 | import types |
@@ -360,7 +361,11 @@ def test_oom_diagnostics_probe_basics_is_live_and_cheap(init_cuda): |
360 | 361 | # --------------------------------------------------------------------------- |
361 | 362 |
|
362 | 363 | import pytest |
363 | | -from cuda_python_test_helpers.graphics import is_gl_context_unavailable, open_gl_window |
| 364 | +from cuda_python_test_helpers.graphics import ( |
| 365 | + gl_context_not_on_nvidia_gpu_reason, |
| 366 | + is_gl_context_unavailable, |
| 367 | + open_gl_window, |
| 368 | +) |
364 | 369 |
|
365 | 370 |
|
366 | 371 | @pytest.mark.thread_unsafe(reason="patches the process-wide pyglet module") |
@@ -437,3 +442,28 @@ def test_is_gl_context_unavailable_accepts_genuine(exc): |
437 | 442 | ) |
438 | 443 | def test_is_gl_context_unavailable_rejects_unrelated(exc): |
439 | 444 | assert is_gl_context_unavailable(exc) is False |
| 445 | + |
| 446 | + |
| 447 | +def _patch_gl_vendor(monkeypatch, vendor): |
| 448 | + # Only GL_VENDOR is answered; any other query (e.g. GL_RENDERER) returns NULL. |
| 449 | + gl = types.SimpleNamespace( |
| 450 | + GL_VENDOR=1, |
| 451 | + GL_RENDERER=2, |
| 452 | + glGetString=lambda name: ctypes.c_char_p(vendor if name == 1 else None), |
| 453 | + ) |
| 454 | + monkeypatch.setitem(sys.modules, "pyglet.gl", types.SimpleNamespace(gl=gl)) |
| 455 | + |
| 456 | + |
| 457 | +@pytest.mark.thread_unsafe(reason="patches the process-wide pyglet.gl module") |
| 458 | +def test_gl_context_not_on_nvidia_gpu_reason_accepts_nvidia(monkeypatch): |
| 459 | + _patch_gl_vendor(monkeypatch, b"NVIDIA Corporation") |
| 460 | + assert gl_context_not_on_nvidia_gpu_reason() is None |
| 461 | + |
| 462 | + |
| 463 | +@pytest.mark.thread_unsafe(reason="patches the process-wide pyglet.gl module") |
| 464 | +@pytest.mark.parametrize("vendor", [b"AMD", b"Mesa", None]) |
| 465 | +def test_gl_context_not_on_nvidia_gpu_reason_rejects_other_vendors(monkeypatch, vendor): |
| 466 | + _patch_gl_vendor(monkeypatch, vendor) |
| 467 | + reason = gl_context_not_on_nvidia_gpu_reason() |
| 468 | + assert reason is not None |
| 469 | + assert "not on an NVIDIA GPU" in reason |
0 commit comments