diff options
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: |