Skip to content

Commit 8812d2b

Browse files
committed
test(cuda.core): expose pinned allocation OOM and retain its traceback
Signed-off-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent 1d9b2d7 commit 8812d2b

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎cuda_core/tests/helpers/oom_diagnostics.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ def record_if_oom(item, call, report, recorder=None, snapshot=None):
524524
if not recorder.matches(exc_text):
525525
return None
526526

527+
# A later native crash can prevent pytest from printing its failure summary.
528+
exc_text = f"{exc_text}\n\noriginal traceback:\n{report.longreprtext}"
527529
text = recorder.capture(item.nodeid, call.when, exc_text, item.config.rootpath, snapshot=snapshot)
528530
if text is None:
529531
return None

‎cuda_core/tests/test_helpers.py‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def test_patterngen_values():
112112
# driver, and only through the side-effect-free prefix of the checker.
113113

114114

115-
def _fake_report(failed):
116-
return types.SimpleNamespace(failed=failed)
115+
def _fake_report(failed, longreprtext=""):
116+
return types.SimpleNamespace(failed=failed, longreprtext=longreprtext)
117117

118118

119119
def _fake_call(exc_text, when="call"):
@@ -180,6 +180,32 @@ def test_oom_diagnostics_write_an_artifact_naming_the_failing_test(tmp_path, mon
180180
assert "tests/test_x.py::test_first" in text
181181

182182

183+
@pytest.mark.agent_authored(model="gpt-6")
184+
def test_oom_diagnostics_preserve_original_traceback_immediately(tmp_path):
185+
def fail_cuda_sync():
186+
raise RuntimeError(OOM_MARKER)
187+
188+
with pytest.raises(RuntimeError) as excinfo:
189+
fail_cuda_sync()
190+
191+
lines = []
192+
item = _fake_item(tmp_path)
193+
item.config.pluginmanager.get_plugin = lambda _: types.SimpleNamespace(write_line=lines.append)
194+
report = _fake_report(True, longreprtext=str(excinfo.getrepr()))
195+
text = record_if_oom(
196+
item,
197+
types.SimpleNamespace(excinfo=excinfo, when="teardown"),
198+
report,
199+
recorder=OomDiagnosticsRecorder(),
200+
snapshot=_NO_CONTEXT_SNAPSHOT,
201+
)
202+
203+
written = (tmp_path / DEFAULT_FILENAME).read_text(encoding="utf-8")
204+
assert "fail_cuda_sync" in written
205+
assert report.longreprtext in written
206+
assert text in lines
207+
208+
183209
@pytest.mark.agent_authored(model="claude-sonnet-5")
184210
def test_oom_diagnostics_summary_points_at_the_artifact(tmp_path):
185211
# The report is emitted beside the failing test, thousands of lines above

‎cuda_core/tests/test_memory.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ def test_pinned_memory_resource_kernel_access(init_cuda, pool):
12751275

12761276
n = 1024
12771277
mr = create_pinned_memory_resource_or_xfail(options, xfail_device=device)
1278-
buffer = _allocate_pinned_buffer_or_xfail(mr, n * ctypes.sizeof(ctypes.c_int), device=device)
1278+
buffer = mr.allocate(n * ctypes.sizeof(ctypes.c_int), stream=device.default_stream)
12791279
stream = device.default_stream
12801280
stream.sync()
12811281
data = (ctypes.c_int * n).from_address(int(buffer.handle))

0 commit comments

Comments
 (0)