aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/py/libvfio_user.py1
-rw-r--r--test/py/test_setup_region.py35
2 files changed, 36 insertions, 0 deletions
diff --git a/test/py/libvfio_user.py b/test/py/libvfio_user.py
index 70986fa..ff5c1cd 100644
--- a/test/py/libvfio_user.py
+++ b/test/py/libvfio_user.py
@@ -156,6 +156,7 @@ VFU_REGION_FLAG_READ = 1
VFU_REGION_FLAG_WRITE = 2
VFU_REGION_FLAG_RW = (VFU_REGION_FLAG_READ | VFU_REGION_FLAG_WRITE)
VFU_REGION_FLAG_MEM = 4
+VFU_REGION_FLAG_ALWAYS_CB = 8
VFIO_USER_F_DMA_REGION_READ = (1 << 0)
VFIO_USER_F_DMA_REGION_WRITE = (1 << 1)
diff --git a/test/py/test_setup_region.py b/test/py/test_setup_region.py
index 0bf120d..c42100f 100644
--- a/test/py/test_setup_region.py
+++ b/test/py/test_setup_region.py
@@ -114,5 +114,40 @@ def test_setup_region_bad_migr():
assert ret == -1
assert c.get_errno() == errno.EINVAL
+def test_setup_region_cfg_always_cb_nocb():
+ ret = vfu_setup_region(ctx, index=VFU_PCI_DEV_CFG_REGION_IDX,
+ size=PCI_CFG_SPACE_EXP_SIZE, cb=None,
+ flags=(VFU_REGION_FLAG_RW |
+ VFU_REGION_FLAG_ALWAYS_CB))
+ assert ret == -1
+ assert c.get_errno() == errno.EINVAL
+
+@vfu_region_access_cb_t
+def pci_cfg_region_cb(ctx, buf, count, offset, is_write):
+ if not is_write:
+ for i in range(count):
+ buf[i] = 0xcc
+
+ return count
+
+def test_setup_region_cfg_always_cb():
+ global ctx
+
+ ret = vfu_setup_region(ctx, index=VFU_PCI_DEV_CFG_REGION_IDX,
+ size=PCI_CFG_SPACE_EXP_SIZE, cb=pci_cfg_region_cb,
+ flags=(VFU_REGION_FLAG_RW |
+ VFU_REGION_FLAG_ALWAYS_CB))
+ assert ret == 0
+
+ ret = vfu_realize_ctx(ctx)
+ assert ret == 0
+
+ sock = connect_client(ctx)
+
+ payload = read_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=0, count=2)
+ assert payload == b'\xcc\xcc'
+
+ disconnect_client(ctx, sock)
+
def test_setup_region_cleanup():
vfu_destroy_ctx(ctx)