Skip to content

Commit 12e928d

Browse files
Added a test to exercise API exported function (get_event_ref).
1 parent 1fd69cd commit 12e928d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

dpctl/tests/test_sycl_event.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,26 @@ def test_addressof_ref():
195195
ev = dpctl.SyclEvent()
196196
ref = ev.addressof_ref()
197197
assert type(ref) is int
198+
199+
200+
def test_cpython_api():
201+
import ctypes
202+
import sys
203+
204+
ev = dpctl.SyclEvent()
205+
mod = sys.modules[ev.__class__.__module__]
206+
# get capsule storign get_event_ref function ptr
207+
ev_ref_fn_cap = mod.__pyx_capi__["get_event_ref"]
208+
# construct Python callable to invoke "get_event_ref"
209+
cap_ptr_fn = ctypes.pythonapi.PyCapsule_GetPointer
210+
cap_ptr_fn.restype = ctypes.c_void_p
211+
cap_ptr_fn.argtypes = [ctypes.py_object, ctypes.c_char_p]
212+
ev_ref_fn_ptr = cap_ptr_fn(
213+
ev_ref_fn_cap, b"DPCTLSyclEventRef (struct PySyclEventObject *)"
214+
)
215+
callable_maker = ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.py_object)
216+
get_event_ref_fn = callable_maker(ev_ref_fn_ptr)
217+
218+
r2 = ev.addressof_ref()
219+
r1 = get_event_ref_fn(ev)
220+
assert r1 == r2

0 commit comments

Comments
 (0)