Skip to content

Commit fea6f8a

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

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

cuda_core/tests/memory_ipc/test_errors.py

Lines changed: 65 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,66 @@ 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.xfail
156+
@pytest.mark.filterwarnings("ignore") # Test incorrectly warns
157+
def test_error_in_close_buffer(ipc_memory_resource):
158+
"""Test that errors when closing a memory buffer are raised."""
159+
mr = ipc_memory_resource
160+
buffer = mr.allocate(NBYTES)
161+
driver.cuMemFree(buffer.handle)
162+
with pytest.raises(CUDAError, match=".*CUDA_ERROR_INVALID_VALUE.*"):
163+
buffer.close()
164+
165+
166+
@pytest.mark.xfail
167+
@pytest.mark.filterwarnings("ignore") # Test incorrectly warns
168+
class TestErrorInCloseImportedMemoryResource(ChildErrorHarness):
169+
"""Test that errors when closing an imported memory resource are raised."""
170+
171+
def PARENT_ACTION(self, queue):
172+
pass
173+
174+
def CHILD_ACTION(self, queue):
175+
try:
176+
driver.cuMemPoolDestroy(self.mr.handle)
177+
except Exception: # noqa: S110
178+
pass
179+
else:
180+
self.mr.close()
181+
182+
def ASSERT(self, exc_type, exc_msg):
183+
assert exc_type is CUDAError
184+
assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg)
185+
186+
187+
@pytest.mark.xfail
188+
@pytest.mark.filterwarnings("ignore") # Test incorrectly warns
189+
class TestErrorInCloseImportedBuffer(ChildErrorHarness):
190+
"""Test that errors when closing an imported buffer are raised."""
191+
192+
def PARENT_ACTION(self, queue):
193+
self.buffer = self.mr.allocate(NBYTES)
194+
queue.put(self.buffer)
195+
196+
def CHILD_ACTION(self, queue):
197+
buffer = queue.get(timeout=CHILD_TIMEOUT_SEC)
198+
try:
199+
driver.cuMemFree(buffer.handle)
200+
except Exception: # noqa: S110
201+
pass
202+
else:
203+
buffer.close()
204+
205+
def ASSERT(self, exc_type, exc_msg):
206+
assert exc_type is CUDAError
207+
assert re.match(r"CUDA_ERROR_INVALID_VALUE", exc_msg)

0 commit comments

Comments
 (0)