11# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22# SPDX-License-Identifier: Apache-2.0
33
4- import json
54import os
65import platform
76import subprocess
@@ -75,9 +74,6 @@ def test_find_nvidia_dynamic_lib_returns_existing_path_without_loading(info_summ
7574
7675
7776def test_find_matches_load_in_subprocess (info_summary_append ):
78- # Single representative libname is enough to exercise the consistency
79- # claim (see issue #757); per-libname coverage is provided by the
80- # parametrized find/load tests independently.
8177 libname = "cudart"
8278 find_nvidia_dynamic_lib .cache_clear ()
8379 timeout = 120 if IS_WINDOWS else 30
@@ -102,9 +98,6 @@ def test_find_matches_load_in_subprocess(info_summary_append):
10298
10399
104100def test_find_nvidia_dynamic_lib_propagates_subprocess_not_found_message (monkeypatch ):
105- # End-to-end of the structured-error path: the subprocess child encodes
106- # DynamicLibNotFoundError into the JSON payload; the parent re-raises
107- # with the original message preserved.
108101 find_nvidia_dynamic_lib .cache_clear ()
109102 expected = "child loader said: cudart could not be located"
110103
@@ -120,35 +113,17 @@ def fake_run(mode, libname, *, timeout, error_label):
120113 find_nvidia_dynamic_lib ("cudart" )
121114
122115
123- def test_find_nvidia_dynamic_lib_falls_back_when_subprocess_not_found_omits_message (monkeypatch ):
124- find_nvidia_dynamic_lib .cache_clear ()
125-
126- def fake_run (mode , libname , * , timeout , error_label ):
127- return DynamicLibSubprocessPayload (status = STATUS_NOT_FOUND , abs_path = None , error = None )
128-
129- monkeypatch .setattr (find_nvidia_dynamic_lib_module , "run_dynamic_lib_subprocess" , fake_run )
130- with pytest .raises (DynamicLibNotFoundError , match = r"could not locate 'cudart'" ):
131- find_nvidia_dynamic_lib ("cudart" )
132-
133-
134116_DOES_NOT_LOAD_PROBE = textwrap .dedent (
135117 """
136- import json
137- import os
138118 import sys
139-
140119 from cuda.pathfinder import DynamicLibNotFoundError, find_nvidia_dynamic_lib
141-
142120 libname = sys.argv[1]
143121 try:
144122 find_nvidia_dynamic_lib(libname)
145- find_status = "found"
146123 except DynamicLibNotFoundError:
147- find_status = "not-found"
148-
124+ print("not-found"); sys.exit(0)
149125 with open("/proc/self/maps") as f:
150- maps = f.read()
151- print(json.dumps({"find_status": find_status, "loaded": ("lib" + libname) in maps}))
126+ print("loaded" if ("lib" + libname) in f.read() else "ok")
152127 """
153128).strip ()
154129
@@ -157,9 +132,9 @@ def test_find_nvidia_dynamic_lib_does_not_load_in_caller_process():
157132 if IS_WINDOWS or not os .path .exists ("/proc/self/maps" ):
158133 pytest .skip ("Requires /proc/self/maps for in-process load detection" )
159134
135+ # Run in a fresh interpreter so other pathfinder tests in the same
136+ # pytest process can't have pre-loaded the library.
160137 libname = "cudart"
161- # Run in a fresh interpreter so test ordering / other pathfinder tests
162- # in the same process can't have pre-loaded the library.
163138 result = subprocess .run ( # noqa: S603 - trusted argv: current interpreter + inline probe
164139 [sys .executable , "-c" , _DOES_NOT_LOAD_PROBE , libname ],
165140 capture_output = True ,
@@ -168,7 +143,7 @@ def test_find_nvidia_dynamic_lib_does_not_load_in_caller_process():
168143 check = False ,
169144 )
170145 assert result .returncode == 0 , f"probe failed:\n stdout={ result .stdout !r} \n stderr={ result .stderr !r} "
171- payload = json . loads ( result .stdout .strip ().splitlines ()[- 1 ])
172- if payload [ "find_status" ] == "not-found" :
146+ verdict = result .stdout .strip ().splitlines ()[- 1 ]
147+ if verdict == "not-found" :
173148 pytest .skip (f"{ libname } not available on this host" )
174- assert payload [ "loaded" ] is False , "find_nvidia_dynamic_lib must not load the library into the caller process"
149+ assert verdict == "ok" , f "find_nvidia_dynamic_lib must not load the library into the caller process ( { verdict = } ) "
0 commit comments