diff options
author | Mattias Nissler <122288598+mnissler-rivos@users.noreply.github.com> | 2023-08-31 11:38:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 10:38:55 +0100 |
commit | a7eedffe20bd6e480c9e2c65e68daef1beb2af05 (patch) | |
tree | 37f46c9cbf8de3fbb0622b7472157d60f1b8550f /test/py/test_device_get_region_io_fds.py | |
parent | 2e8ec2e17a5252d29bae849eb4ccd7ca6bab216a (diff) | |
download | libvfio-user-a7eedffe20bd6e480c9e2c65e68daef1beb2af05.zip libvfio-user-a7eedffe20bd6e480c9e2c65e68daef1beb2af05.tar.gz libvfio-user-a7eedffe20bd6e480c9e2c65e68daef1beb2af05.tar.bz2 |
Introduce client object in python tests (#772)
Thus far, the client end of the socket is the only piece of client state
tracked in tests, for which a global `socket` variable has been used. In
preparation to add more state, replace the `socket` global with a
`client` global object that groups all client state.
Signed-off-by: Mattias Nissler <mnissler@rivosinc.com>
Reviewed-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'test/py/test_device_get_region_io_fds.py')
-rw-r--r-- | test/py/test_device_get_region_io_fds.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/test/py/test_device_get_region_io_fds.py b/test/py/test_device_get_region_io_fds.py index 63b433f..47ce325 100644 --- a/test/py/test_device_get_region_io_fds.py +++ b/test/py/test_device_get_region_io_fds.py @@ -34,12 +34,12 @@ import os import struct ctx = None -sock = None +client = None fds = [] def test_device_get_region_io_fds_setup(): - global ctx, sock + global ctx, client ctx = vfu_create_ctx(flags=LIBVFIO_USER_FLAG_ATTACH_NB) assert ctx is not None @@ -71,7 +71,7 @@ def test_device_get_region_io_fds_setup(): ret = vfu_realize_ctx(ctx) assert ret == 0 - sock = connect_client(ctx) + client = connect_client(ctx) for i in range(0, 6): tmp = eventfd(0, 0) fds.append(tmp) @@ -86,7 +86,7 @@ def test_device_get_region_io_fds_bad_flags(): len(vfio_user_sub_region_ioeventfd()) * 5, flags=1, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=0) - msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=errno.EINVAL) @@ -97,7 +97,7 @@ def test_device_get_region_io_fds_bad_count(): len(vfio_user_sub_region_ioeventfd()) * 5, flags=0, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=1) - msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=errno.EINVAL) @@ -107,7 +107,7 @@ def test_device_get_region_io_fds_buffer_too_small(): argsz=len(vfio_user_region_io_fds_reply()) - 1, flags=0, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=1) - msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=errno.EINVAL) @@ -118,7 +118,7 @@ def test_device_get_region_io_fds_buffer_too_large(): index=VFU_PCI_DEV_BAR2_REGION_IDX, count=1) - msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=errno.EINVAL) @@ -127,7 +127,7 @@ def test_device_get_region_io_fds_no_fds(): payload = vfio_user_region_io_fds_request(argsz=512, flags=0, index=VFU_PCI_DEV_BAR1_REGION_IDX, count=0) - ret = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + ret = msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) reply, ret = vfio_user_region_io_fds_reply.pop_from_buffer(ret) @@ -143,7 +143,7 @@ def test_device_get_region_io_fds_no_regions_setup(): payload = vfio_user_region_io_fds_request(argsz=512, flags=0, index=VFU_PCI_DEV_BAR3_REGION_IDX, count=0) - msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=errno.EINVAL) @@ -152,7 +152,7 @@ def test_device_get_region_io_fds_region_no_mmap(): payload = vfio_user_region_io_fds_request(argsz=512, flags=0, index=VFU_PCI_DEV_BAR5_REGION_IDX, count=0) - ret = msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + ret = msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) reply, ret = vfio_user_region_io_fds_reply.pop_from_buffer(ret) @@ -168,7 +168,7 @@ def test_device_get_region_io_fds_region_out_of_range(): payload = vfio_user_region_io_fds_request(argsz=512, flags=0, index=512, count=0) - msg(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, + msg(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=errno.EINVAL) @@ -179,7 +179,7 @@ def test_device_get_region_io_fds_fds_read_write(): len(vfio_user_sub_region_ioeventfd()) * 10, flags=0, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=0) - newfds, ret = msg_fds(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, + newfds, ret = msg_fds(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) assert len(newfds) == 6 @@ -209,7 +209,7 @@ def test_device_get_region_io_fds_full(): len(vfio_user_sub_region_ioeventfd()) * 6, flags=0, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=0) - newfds, ret = msg_fds(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, + newfds, ret = msg_fds(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) reply, ret = vfio_user_region_io_fds_reply.pop_from_buffer(ret) @@ -238,7 +238,7 @@ def test_device_get_region_io_fds_fds_read_write_nothing(): argsz=len(vfio_user_region_io_fds_reply()), flags=0, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=0) - newfds, ret = msg_fds(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, + newfds, ret = msg_fds(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) assert len(newfds) == 0 @@ -263,7 +263,7 @@ def test_device_get_region_io_fds_fds_read_write_dupe_fd(): len(vfio_user_sub_region_ioeventfd()) * 8, flags=0, index=VFU_PCI_DEV_BAR2_REGION_IDX, count=0) - newfds, ret = msg_fds(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, + newfds, ret = msg_fds(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) reply, ret = vfio_user_region_io_fds_reply.pop_from_buffer(ret) assert len(newfds) == 7 @@ -337,7 +337,7 @@ def test_device_get_region_io_fds_invalid_fd(): ret = vfu_realize_ctx(ctx) assert ret == 0 - sock = connect_client(ctx) + client = connect_client(ctx) fds = [] @@ -370,7 +370,7 @@ def test_device_get_region_io_fds_invalid_fd(): len(vfio_user_sub_region_ioeventfd()) * 5, flags=0, index=VFU_PCI_DEV_BAR0_REGION_IDX, count=0) - newfds, ret = msg_fds(ctx, sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, + newfds, ret = msg_fds(ctx, client.sock, VFIO_USER_DEVICE_GET_REGION_IO_FDS, payload, expect=0) # two unique fds |