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_request_errors.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_request_errors.py')
-rw-r--r-- | test/py/test_request_errors.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/test/py/test_request_errors.py b/test/py/test_request_errors.py index 79af0f2..c25a715 100644 --- a/test/py/test_request_errors.py +++ b/test/py/test_request_errors.py @@ -33,12 +33,12 @@ import errno import os ctx = None -sock = None +client = None argsz = len(vfio_irq_set()) def setup_function(function): - global ctx, sock + global ctx, client ctx = vfu_create_ctx(flags=LIBVFIO_USER_FLAG_ATTACH_NB) assert ctx is not None @@ -64,7 +64,7 @@ def setup_function(function): ret = vfu_realize_ctx(ctx) assert ret == 0 - sock = connect_client(ctx) + client = connect_client(ctx) def teardown_function(function): @@ -77,9 +77,9 @@ def test_too_small(): hdr = struct.pack("HHIII", 0xbad1, VFIO_USER_DEVICE_SET_IRQS, SIZEOF_VFIO_USER_HEADER - 1, VFIO_USER_F_TYPE_COMMAND, 0) - sock.send(hdr) + client.sock.send(hdr) vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + get_reply(client.sock, expect=errno.EINVAL) def test_too_large(): @@ -87,9 +87,9 @@ def test_too_large(): hdr = struct.pack("HHIII", 0xbad1, VFIO_USER_DEVICE_SET_IRQS, SERVER_MAX_MSG_SIZE + 1, VFIO_USER_F_TYPE_COMMAND, 0) - sock.send(hdr) + client.sock.send(hdr) vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + get_reply(client.sock, expect=errno.EINVAL) def test_unsolicited_reply(): @@ -97,24 +97,24 @@ def test_unsolicited_reply(): hdr = struct.pack("HHIII", 0xbad2, VFIO_USER_DEVICE_SET_IRQS, SIZEOF_VFIO_USER_HEADER, VFIO_USER_F_TYPE_REPLY, 0) - sock.send(hdr) + client.sock.send(hdr) vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + get_reply(client.sock, expect=errno.EINVAL) def test_bad_command(): hdr = vfio_user_header(VFIO_USER_MAX, size=1) - sock.send(hdr + b'\0') + client.sock.send(hdr + b'\0') vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + get_reply(client.sock, expect=errno.EINVAL) def test_no_payload(): hdr = vfio_user_header(VFIO_USER_DEVICE_SET_IRQS, size=0) - sock.send(hdr) + client.sock.send(hdr) vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + get_reply(client.sock, expect=errno.EINVAL) def test_bad_request_closes_fds(): @@ -126,10 +126,10 @@ def test_bad_request_closes_fds(): fd2 = eventfd() hdr = vfio_user_header(VFIO_USER_DEVICE_SET_IRQS, size=len(payload)) - sock.sendmsg([hdr + payload], [(socket.SOL_SOCKET, socket.SCM_RIGHTS, - struct.pack("II", fd1, fd2))]) + client.sock.sendmsg([hdr + payload], [(socket.SOL_SOCKET, + socket.SCM_RIGHTS, struct.pack("II", fd1, fd2))]) vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + get_reply(client.sock, expect=errno.EINVAL) # # It's a little cheesy, but this is just ensuring no fd's remain open past @@ -149,8 +149,8 @@ def test_disconnected_socket(mock_quiesce, mock_reset): """Tests that calling vfu_run_ctx on a disconnected socket results in resetting the context and returning ENOTCONN.""" - global ctx, sock - sock.close() + global ctx, client + client.sock.close() vfu_run_ctx(ctx, errno.ENOTCONN) @@ -165,8 +165,8 @@ def test_disconnected_socket_quiesce_busy(mock_quiesce): """Tests that calling vfu_run_ctx on a disconnected socket results in resetting the context which returns EBUSY.""" - global ctx, sock - sock.close() + global ctx, client + client.sock.close() vfu_run_ctx(ctx, errno.EBUSY) @@ -194,16 +194,16 @@ def test_reply_fail_quiesce_busy(mock_get_pending_bytes, mock_quiesce, mock_reset): """Tests failing to reply and the quiesce callback returning EBUSY.""" - global ctx, sock + global ctx, client def get_pending_bytes_side_effect(ctx): - sock.close() + client.sock.close() return 0 mock_get_pending_bytes.side_effect = get_pending_bytes_side_effect # read the get_pending_bytes register, it should close the socket causing # the reply to fail - read_region(ctx, sock, VFU_PCI_DEV_MIGR_REGION_IDX, + read_region(ctx, client.sock, VFU_PCI_DEV_MIGR_REGION_IDX, vfio_user_migration_info.pending_bytes.offset, vfio_user_migration_info.pending_bytes.size, rsp=False, busy=True) @@ -227,7 +227,7 @@ def test_reply_fail_quiesce_busy(mock_get_pending_bytes, mock_quiesce, mock_reset.assert_called_once_with(ctx, VFU_RESET_LOST_CONN) try: - get_reply(sock) + get_reply(client.sock) except OSError as e: assert e.errno == errno.EBADF else: |