Skip to content

Commit 1bab5d9

Browse files
committed
test: cover non-VMM buffers and reuse subprocess runner
Signed-off-by: Rui Luo <[email protected]>
1 parent 2fe1140 commit 1bab5d9

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

‎cuda_core/tests/test_memory.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1907,6 +1907,26 @@ def test_vmm_modify_allocation_rejects_non_buffer(init_cuda):
19071907
mr.modify_allocation(object(), 4096)
19081908

19091909

1910+
@pytest.mark.agent_authored(model="gpt-6-sol")
1911+
def test_vmm_modify_allocation_rejects_non_vmm_buffer(init_cuda):
1912+
"""modify_allocation rejects non-VMM Buffers without closing them."""
1913+
mr = _vmm_resource(_vmm_device_or_skip())
1914+
stream = init_cuda.create_stream()
1915+
try:
1916+
buf = init_cuda.memory_resource.allocate(64, stream=stream)
1917+
try:
1918+
assert isinstance(buf, Buffer)
1919+
assert not isinstance(buf, VirtualMemoryBuffer)
1920+
with pytest.raises(TypeError, match="buf must be a VirtualMemoryBuffer"):
1921+
mr.modify_allocation(buf, 4096)
1922+
assert not buf.is_closed
1923+
finally:
1924+
buf.close(stream=stream)
1925+
stream.sync()
1926+
finally:
1927+
stream.close()
1928+
1929+
19101930
@pytest.mark.agent_authored(model="claude-fable-5-1")
19111931
def test_vmm_buffers_alive_at_shutdown_are_freed_quietly(init_cuda):
19121932
"""Buffers still referenced at interpreter exit are freed without a warning or an error."""

‎cuda_core/tests/test_utils_dlpack.py‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"""
99

1010
import ctypes
11-
import subprocess
12-
import sys
1311
from pathlib import Path
1412

1513
try:
@@ -18,6 +16,7 @@
1816
ml_dtypes = None
1917
import numpy as np
2018
import pytest
19+
from cuda_python_test_helpers.subprocess_runner import run_python_snippet
2120

2221
from cuda.core._dlpack import DLDeviceType
2322
from cuda.core.utils import StridedMemoryView
@@ -409,7 +408,10 @@ def _assert_bfloat16_without_ml_dtypes():
409408
@pytest.mark.agent_authored(model="gpt-6-sol")
410409
def test_from_dlpack_bfloat16_requires_ml_dtypes():
411410
"""kDLBfloat without ml_dtypes raises on ``.dtype`` access."""
412-
check = """
411+
# Only the parent needs this helper; the child loads this file from an empty directory.
412+
from helpers.child_processes import child_timeout_sec
413+
414+
check = f"""
413415
import numpy
414416
import runpy
415417
import sys
@@ -423,12 +425,9 @@ def find_spec(self, fullname, path=None, target=None):
423425
raise ModuleNotFoundError("No module named 'ml_dtypes'")
424426
425427
sys.meta_path.insert(0, _BlockMlDtypes())
426-
runpy.run_path(sys.argv[1])["_assert_bfloat16_without_ml_dtypes"]()
428+
runpy.run_path({str(Path(__file__).resolve())!r})["_assert_bfloat16_without_ml_dtypes"]()
427429
"""
428-
subprocess.run( # noqa: S603 - trusted interpreter and in-tree test file
429-
(sys.executable, "-I", "-c", check, str(Path(__file__).resolve())),
430-
check=True,
431-
)
430+
run_python_snippet(check, timeout=child_timeout_sec())
432431

433432

434433
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)