Skip to content

Commit 2794230

Browse files
committed
test(cuda.core): extend pack_host_copy_args coverage
Pin the GPU-free path for a Buffer without a memory resource, cover the src > dst overlap and its adjacent boundary, and check OverflowError for out-of-range int addresses as well as nbytes.
1 parent f118388 commit 2794230

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎cuda_core/tests/test_host_copy.py‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
import pytest
1111

12-
from cuda.core import HOST_COPY_FN, Device, LegacyPinnedMemoryResource, host_launch, pack_host_copy_args
12+
from cuda.core import HOST_COPY_FN, Buffer, Device, LegacyPinnedMemoryResource, host_launch, pack_host_copy_args
1313

1414
N = 4096
1515

@@ -107,6 +107,14 @@ def test_pack_host_copy_args_takes_addresses_from_objects(init_cuda):
107107
assert struct.unpack("@PPN", pack_host_copy_args(dst, pinned, N)) == (dst_address, int(pinned.handle), N)
108108

109109

110+
@pytest.mark.agent_authored(model="claude-opus-5-5")
111+
def test_pack_host_copy_args_accepts_buffer_without_memory_resource():
112+
src = np.arange(N, dtype=np.uint8)
113+
dst = np.zeros(N, dtype=np.uint8)
114+
buffer = Buffer.from_handle(dst.ctypes.data, N, owner=dst)
115+
assert struct.unpack("@PPN", pack_host_copy_args(buffer, src, N)) == (dst.ctypes.data, src.ctypes.data, N)
116+
117+
110118
@pytest.mark.agent_authored(model="claude-opus-5-5")
111119
def test_pack_host_copy_args_checks_bounds(init_cuda):
112120
small = np.zeros(N - 1, dtype=np.uint8)
@@ -164,7 +172,10 @@ def test_pack_host_copy_args_rejects_overlap():
164172
view = memoryview(data)
165173
with pytest.raises(ValueError, match="overlap"):
166174
pack_host_copy_args(view[1:], view, N - 1)
175+
with pytest.raises(ValueError, match="overlap"):
176+
pack_host_copy_args(view, view[1:], N - 1)
167177
pack_host_copy_args(view[N // 2 :], view, N // 2)
178+
pack_host_copy_args(view, view[N // 2 :], N // 2)
168179

169180

170181
@pytest.mark.agent_authored(model="claude-opus-5-5")
@@ -173,7 +184,11 @@ def test_pack_host_copy_args_rejects_null_address():
173184
pack_host_copy_args(0, bytearray(N), N)
174185

175186

187+
@pytest.mark.parametrize(
188+
("dst", "nbytes"),
189+
[(0x1000, -1), (0x1000, 1 << 64), (-1, 1), (1 << 64, 1)],
190+
)
176191
@pytest.mark.agent_authored(model="claude-opus-5-5")
177-
def test_pack_host_copy_args_rejects_negative_nbytes():
192+
def test_pack_host_copy_args_rejects_out_of_range_int(dst, nbytes):
178193
with pytest.raises(OverflowError):
179-
pack_host_copy_args(bytearray(N), bytearray(N), -1)
194+
pack_host_copy_args(dst, 0x2000, nbytes)

0 commit comments

Comments
 (0)