Skip to content

Commit 293258d

Browse files
committed
test: fail checkpoint coverage on missing bindings
Ensure checkpoint tests distinguish missing required cuda.bindings symbols from genuinely unsupported environments.
1 parent 88363f8 commit 293258d

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

cuda_bindings/tests/test_cuda.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,26 @@ def test_cuCheckpointProcessGetState_failure():
861861
assert state is None
862862

863863

864+
@pytest.mark.skipif(not supportsCudaAPI("cuCheckpointProcessGetState"), reason="When API was introduced")
865+
def test_cuCheckpoint_required_bindings_present():
866+
required_bindings = (
867+
"cuCheckpointProcessCheckpoint",
868+
"cuCheckpointProcessGetRestoreThreadId",
869+
"cuCheckpointProcessGetState",
870+
"cuCheckpointProcessLock",
871+
"cuCheckpointProcessRestore",
872+
"cuCheckpointProcessUnlock",
873+
"CUcheckpointGpuPair",
874+
"CUcheckpointLockArgs",
875+
"CUprocessState",
876+
"CUcheckpointRestoreArgs",
877+
)
878+
879+
missing = [name for name in required_bindings if not hasattr(cuda, name)]
880+
881+
assert missing == []
882+
883+
864884
def test_private_function_pointer_inspector():
865885
from cuda.bindings._bindings.cydriver import _inspect_function_pointer
866886

cuda_core/tests/test_checkpoint.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ def _checkpoint_available():
3333
try:
3434
checkpoint._get_driver()
3535
return True
36-
except RuntimeError:
37-
return False
36+
except RuntimeError as exc:
37+
if _checkpoint_unavailable_can_skip(str(exc)):
38+
return False
39+
raise
40+
41+
42+
def _checkpoint_unavailable_can_skip(message):
43+
return message.startswith(
44+
(
45+
"CUDA checkpointing is not supported by the installed NVIDIA driver.",
46+
"CUDA checkpointing requires cuda.bindings with CUDA checkpoint API support. Found cuda.bindings ",
47+
)
48+
)
3849

3950

4051
needs_checkpoint = pytest.mark.skipif(
@@ -384,6 +395,37 @@ def test_public_symbols(self):
384395
assert checkpoint.__all__ == ["Process"]
385396
assert not hasattr(checkpoint, "ProcessStateType")
386397

398+
def test_checkpoint_available_skips_unsupported_driver(self, monkeypatch):
399+
def raise_unsupported_driver():
400+
raise RuntimeError("CUDA checkpointing is not supported by the installed NVIDIA driver.")
401+
402+
monkeypatch.setattr(checkpoint, "_get_driver", raise_unsupported_driver)
403+
404+
assert not _checkpoint_available()
405+
406+
def test_checkpoint_available_skips_old_bindings(self, monkeypatch):
407+
def raise_old_bindings():
408+
raise RuntimeError(
409+
"CUDA checkpointing requires cuda.bindings with CUDA checkpoint API support. "
410+
"Found cuda.bindings 12.7.0."
411+
)
412+
413+
monkeypatch.setattr(checkpoint, "_get_driver", raise_old_bindings)
414+
415+
assert not _checkpoint_available()
416+
417+
def test_checkpoint_available_fails_missing_required_bindings(self, monkeypatch):
418+
def raise_missing_binding():
419+
raise RuntimeError(
420+
"CUDA checkpointing requires cuda.bindings with CUDA checkpoint API support. "
421+
"Missing: CUcheckpointRestoreArgs"
422+
)
423+
424+
monkeypatch.setattr(checkpoint, "_get_driver", raise_missing_binding)
425+
426+
with pytest.raises(RuntimeError, match="Missing: CUcheckpointRestoreArgs"):
427+
_checkpoint_available()
428+
387429
def test_pid_is_read_only(self):
388430
proc = checkpoint.Process(1)
389431
assert proc.pid == 1

0 commit comments

Comments
 (0)