Skip to content

Commit 78a4815

Browse files
committed
Add skipped tests demonstrating that errors in Buffer.close (for example) are not raised.
1 parent 4754292 commit 78a4815

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

cuda_core/tests/memory_ipc/test_errors.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import pickle
66
import re
77

8+
import pytest
89
from cuda.core.experimental import Buffer, Device, DeviceMemoryResource, DeviceMemoryResourceOptions
9-
from cuda.core.experimental._utils.cuda_utils import CUDAError
10+
from cuda.core.experimental._utils.cuda_utils import CUDAError, driver
1011

1112
CHILD_TIMEOUT_SEC = 20
1213
NBYTES = 64
@@ -141,3 +142,63 @@ def CHILD_ACTION(self, queue):
141142
def ASSERT(self, exc_type, exc_msg):
142143
assert exc_type is RuntimeError
143144
assert re.match(r"Memory resource [a-z0-9-]+ was not found", exc_msg)
145+
146+
147+
def test_error_in_close_memory_resource(ipc_memory_resource):
148+
"""Test that errors when closing a memory resource are raised."""
149+
mr = ipc_memory_resource
150+
driver.cuMemPoolDestroy(mr.handle)
151+
with pytest.raises(CUDAError, match=".*CUDA_ERROR_INVALID_VALUE.*"):
152+
mr.close()
153+
154+
155+
@pytest.mark.skip("Errors are ignored")
156+
def test_error_in_close_buffer(ipc_memory_resource):
157+
"""Test that errors when closing a memory buffer are raised."""
158+
mr = ipc_memory_resource
159+
buffer = mr.allocate(NBYTES)
160+
driver.cuMemFree(buffer.handle)
161+
with pytest.raises(CUDAError, match=".*CUDA_ERROR_INVALID_VALUE.*"):
162+
buffer.close()
163+
164+
165+
@pytest.mark.skip("Errors are ignored")
166+
class TestErrorInCloseImportedMemoryResource(ChildErrorHarness):
167+
"""Test that errors when closing an imported memory resource are raised."""
168+
169+
def PARENT_ACTION(self, queue):
170+
pass
171+
172+
def CHILD_ACTION(self, queue):
173+
try:
174+
driver.cuMemPoolDestroy(self.mr.handle)
175+
except Exception: # noqa: S110
176+
pass
177+
else:
178+
self.mr.close()
179+
180+
def ASSERT(self, exc_type, exc_msg):
181+
assert exc_type is CUDAError
182+
assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg)
183+
184+
185+
@pytest.mark.skip("Errors are ignored")
186+
class TestErrorInCloseImportedBuffer(ChildErrorHarness):
187+
"""Test that errors when closing an imported memory resource are raised."""
188+
189+
def PARENT_ACTION(self, queue):
190+
self.buffer = self.mr.allocate(NBYTES)
191+
queue.put(self.buffer)
192+
193+
def CHILD_ACTION(self, queue):
194+
buffer = queue.get(timeout=CHILD_TIMEOUT_SEC)
195+
try:
196+
driver.cuMemFree(buffer.handle)
197+
except Exception: # noqa: S110
198+
pass
199+
else:
200+
buffer.close()
201+
202+
def ASSERT(self, exc_type, exc_msg):
203+
assert exc_type is CUDAError
204+
assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg)

0 commit comments

Comments
 (0)