|
8 | 8 | conda, CUDA_HOME, and the canary probe. |
9 | 9 | """ |
10 | 10 |
|
| 11 | +import json |
| 12 | +import os |
| 13 | + |
11 | 14 | 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 |
12 | 17 |
|
13 | 18 | from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL |
14 | 19 | from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import ( |
15 | 20 | _DRIVER_ONLY_LIBNAMES, |
16 | 21 | _load_driver_lib_no_cache, |
17 | 22 | _load_lib_no_cache, |
18 | 23 | ) |
| 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") |
19 | 28 |
|
20 | 29 | _MODULE = "cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib" |
21 | 30 |
|
@@ -110,3 +119,34 @@ def test_load_lib_no_cache_does_not_dispatch_ctk_lib_to_driver_path(mocker): |
110 | 119 | _load_lib_no_cache("cudart") |
111 | 120 |
|
112 | 121 | 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