Skip to content

Commit adfb7e5

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

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

cuda_core/tests/memory_ipc/test_errors.py

Lines changed: 58 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,59 @@ 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+
driver.cuMemPoolDestroy(self.mr.handle)
174+
self.mr.close()
175+
176+
def ASSERT(self, exc_type, exc_msg):
177+
assert exc_type is CUDAError
178+
assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg)
179+
180+
181+
@pytest.mark.skip("Errors are ignored")
182+
class TestErrorInCloseImportedBuffer(ChildErrorHarness):
183+
"""Test that errors when closing an imported memory resource are raised."""
184+
185+
def PARENT_ACTION(self, queue):
186+
self.buffer = self.mr.allocate(NBYTES)
187+
queue.put(self.buffer)
188+
189+
def CHILD_ACTION(self, queue):
190+
buffer = queue.get(timeout=CHILD_TIMEOUT_SEC)
191+
try:
192+
driver.cuMemFree(buffer.handle)
193+
except Exception: # noqa: S110
194+
pass
195+
else:
196+
buffer.close()
197+
198+
def ASSERT(self, exc_type, exc_msg):
199+
assert exc_type is CUDAError
200+
assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg)

0 commit comments

Comments
 (0)