aboutsummaryrefslogtreecommitdiff
path: root/test/py/test_device_get_region_info.py
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-06-10 11:35:08 +0100
committerGitHub <noreply@github.com>2021-06-10 11:35:08 +0100
commitc34d6ec02bae297b9256ac45ff71da0e2d4b4bc1 (patch)
tree1ca0d1f797bb38ffa06a2f132d613fa0e3785fa3 /test/py/test_device_get_region_info.py
parentb665c3982c1efe2bb896fc8b556d24bcf996435a (diff)
downloadlibvfio-user-c34d6ec02bae297b9256ac45ff71da0e2d4b4bc1.zip
libvfio-user-c34d6ec02bae297b9256ac45ff71da0e2d4b4bc1.tar.gz
libvfio-user-c34d6ec02bae297b9256ac45ff71da0e2d4b4bc1.tar.bz2
python tests: add msg() utility function (#562)
Most tests need to send a request, process it, then retrieve the reply. Add a utility function to avoid lots of tedious boilerplate. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'test/py/test_device_get_region_info.py')
-rw-r--r--test/py/test_device_get_region_info.py38
1 files changed, 10 insertions, 28 deletions
diff --git a/test/py/test_device_get_region_info.py b/test/py/test_device_get_region_info.py
index 4209cfb..710efd8 100644
--- a/test/py/test_device_get_region_info.py
+++ b/test/py/test_device_get_region_info.py
@@ -76,10 +76,8 @@ def test_device_get_region_info_short_write():
payload = struct.pack("II", 0, 0)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- get_reply(sock, expect=errno.EINVAL)
+ msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload,
+ expect=errno.EINVAL)
def test_device_get_region_info_bad_argsz():
@@ -87,10 +85,8 @@ def test_device_get_region_info_bad_argsz():
index=VFU_PCI_DEV_BAR1_REGION_IDX, cap_offset=0,
size=0, offset=0)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- get_reply(sock, expect=errno.EINVAL)
+ msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload,
+ expect=errno.EINVAL)
def test_device_get_region_info_bad_index():
@@ -98,10 +94,8 @@ def test_device_get_region_info_bad_index():
index=VFU_PCI_DEV_NUM_REGIONS, cap_offset=0,
size=0, offset=0)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- get_reply(sock, expect=errno.EINVAL)
+ msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload,
+ expect=errno.EINVAL)
def test_device_get_region_info_larger_argsz():
@@ -109,10 +103,7 @@ def test_device_get_region_info_larger_argsz():
index=VFU_PCI_DEV_BAR1_REGION_IDX, cap_offset=0,
size=0, offset=0)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- result = get_reply(sock)
+ result = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload)
assert(len(result) == argsz)
@@ -133,10 +124,7 @@ def test_device_get_region_info_small_argsz_caps():
index=VFU_PCI_DEV_BAR2_REGION_IDX, cap_offset=0,
size=0, offset=0)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- result = get_reply(sock)
+ result = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload)
info, _ = vfio_region_info.pop_from_buffer(result)
@@ -163,10 +151,7 @@ def test_device_get_region_info_caps():
size=0, offset=0)
payload = bytes(payload) + b'\0' * (80 - 32)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- result = get_reply(sock)
+ result = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload)
info, result = vfio_region_info.pop_from_buffer(result)
cap, result = vfio_region_info_cap_sparse_mmap.pop_from_buffer(result)
@@ -201,10 +186,7 @@ def test_device_get_region_info_migr():
size=0, offset=0)
payload = bytes(payload) + b'\0' * (80 - 32)
- hdr = vfio_user_header(VFIO_USER_DEVICE_GET_REGION_INFO, size=len(payload))
- sock.send(hdr + payload)
- vfu_run_ctx(ctx)
- result = get_reply(sock)
+ result = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_INFO, payload)
info, result = vfio_region_info.pop_from_buffer(result)
mcap, result = vfio_region_info_cap_type.pop_from_buffer(result)