From 8e231d2a9a9b17d25848bf85d4b7e222e142953f Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Sat, 14 Oct 2023 23:53:03 +0200 Subject: [PATCH] I tried many ways, thought I found one, but did not. --- tests/test_buffer_mapping.py | 234 +++++++++++++++++++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 tests/test_buffer_mapping.py diff --git a/tests/test_buffer_mapping.py b/tests/test_buffer_mapping.py new file mode 100644 index 00000000..2bc2ac24 --- /dev/null +++ b/tests/test_buffer_mapping.py @@ -0,0 +1,234 @@ +"""This part is somewhat tricky so we dedicate a test module on it. + +The tricky part for implementing the buffer data mapping, as specified by +the WebGPU API, is that its not trivial (at all) to provide an array-like object +for which numpy views can be created, and which we can invalidate in such +a way that the views become un-usable. + +We spend the first part of this module demonstrating what techniques +do NOT work. In the second part we demonstrate the working of the used +technique. In the third part we test the buffer mapping API itself. + +""" + +import ctypes + +import numpy as np + +from testutils import run_tests +import pytest + + +ALLOW_SEGFAULTS = False + + +# %%%%%%%%%% 1. What does NOT work + + +def test_fail_array_interface_with_ctypes_array(): + # Create an array-like object using __array_interface__, + # with a ctypes array to hold the data, via a real address pointer. + # We cannot invalidate the base array-like object. + + class ArrayLike: + def __init__(self): + size = 100 + offset = 0 + itemsize = 1 + self._data = (ctypes.c_uint8 * size)() + + readonly = False + typestr = "