Skip to content

Commit ba23547

Browse files
cpcloudcursoragent
andcommitted
test(pathfinder): add real-loading tests for driver libs
Run "cuda" and "nvml" through the actual OS loader in spawned child processes, following the same pattern as test_load_nvidia_dynamic_lib. Results are tracked via INFO summary lines for CI/QA log inspection. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3bd1b0e commit ba23547

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

cuda_pathfinder/tests/test_driver_lib_loading.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@
88
conda, CUDA_HOME, and the canary probe.
99
"""
1010

11+
import json
12+
import os
13+
1114
import pytest
15+
import spawned_process_runner
16+
from child_load_nvidia_dynamic_lib_helper import build_child_process_failed_for_libname_message, child_process_func
1217

1318
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL
1419
from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import (
1520
_DRIVER_ONLY_LIBNAMES,
1621
_load_driver_lib_no_cache,
1722
_load_lib_no_cache,
1823
)
24+
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell
25+
26+
STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "see_what_works")
27+
assert STRICTNESS in ("see_what_works", "all_must_work")
1928

2029
_MODULE = "cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib"
2130

@@ -110,3 +119,34 @@ def test_load_lib_no_cache_does_not_dispatch_ctk_lib_to_driver_path(mocker):
110119
_load_lib_no_cache("cudart")
111120

112121
mock_driver.assert_not_called()
122+
123+
124+
# ---------------------------------------------------------------------------
125+
# Real loading tests (spawned child process for isolation)
126+
# ---------------------------------------------------------------------------
127+
128+
129+
@pytest.mark.parametrize("libname", sorted(_DRIVER_ONLY_LIBNAMES))
130+
def test_real_load_driver_lib(info_summary_append, libname):
131+
"""Load a real driver library in a child process.
132+
133+
This complements the mock tests above: it exercises the actual OS
134+
loader path and logs results via INFO for CI/QA inspection.
135+
"""
136+
timeout = 120 if IS_WINDOWS else 30
137+
result = spawned_process_runner.run_in_spawned_child_process(child_process_func, args=(libname,), timeout=timeout)
138+
139+
def raise_child_process_failed():
140+
raise RuntimeError(build_child_process_failed_for_libname_message(libname, result))
141+
142+
if result.returncode != 0:
143+
raise_child_process_failed()
144+
assert not result.stderr
145+
if result.stdout.startswith("CHILD_LOAD_NVIDIA_DYNAMIC_LIB_HELPER_DYNAMIC_LIB_NOT_FOUND_ERROR:"):
146+
if STRICTNESS == "all_must_work":
147+
raise_child_process_failed()
148+
info_summary_append(f"Not found: {libname=!r}")
149+
else:
150+
abs_path = json.loads(result.stdout.rstrip())
151+
info_summary_append(f"abs_path={quote_for_shell(abs_path)}")
152+
assert os.path.isfile(abs_path)

0 commit comments

Comments
 (0)