aboutsummaryrefslogtreecommitdiff
path: root/test/py/test_negotiate.py
diff options
context:
space:
mode:
authorJohn Levon <levon@movementarian.org>2021-10-22 13:56:38 +0100
committerGitHub <noreply@github.com>2021-10-22 13:56:38 +0100
commit7fd786fa7f0023e7bf74618c6ebc3999f5736bc6 (patch)
tree79a152071fe31d3f6bd0b5e1fbecabc310e3c895 /test/py/test_negotiate.py
parent3111d8ec3ed5557b64434778fb2596908235bfa2 (diff)
downloadlibvfio-user-7fd786fa7f0023e7bf74618c6ebc3999f5736bc6.zip
libvfio-user-7fd786fa7f0023e7bf74618c6ebc3999f5736bc6.tar.gz
libvfio-user-7fd786fa7f0023e7bf74618c6ebc3999f5736bc6.tar.bz2
run python code through flake8 (#613)
Aside from general style goodness, this found a couple of accidental re-definitions, so it's worth taking the pain now. Also, only run rstlint as part of pre-push. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Diffstat (limited to 'test/py/test_negotiate.py')
-rw-r--r--test/py/test_negotiate.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/test/py/test_negotiate.py b/test/py/test_negotiate.py
index 524f59f..0541d0e 100644
--- a/test/py/test_negotiate.py
+++ b/test/py/test_negotiate.py
@@ -29,13 +29,11 @@
from libvfio_user import *
import errno
-import json
-import os
-import socket
import struct
ctx = None
+
def client_version_json(expect=0, json=''):
sock = connect_sock()
@@ -50,15 +48,17 @@ def client_version_json(expect=0, json=''):
return payload
+
def test_server_setup():
global ctx
ctx = vfu_create_ctx()
- assert ctx != None
+ assert ctx is not None
ret = vfu_realize_ctx(ctx)
assert ret == 0
+
def test_short_write():
sock = connect_sock()
hdr = vfio_user_header(VFIO_USER_VERSION, size=0)
@@ -67,6 +67,7 @@ def test_short_write():
vfu_attach_ctx(ctx, expect=errno.EINVAL)
get_reply(sock, expect=errno.EINVAL)
+
def test_long_write():
sock = connect_sock()
hdr = vfio_user_header(VFIO_USER_VERSION, size=SERVER_MAX_MSG_SIZE + 1)
@@ -76,6 +77,7 @@ def test_long_write():
assert ret == -1
assert c.get_errno() == errno.EINVAL
+
def test_bad_command():
sock = connect_sock()
@@ -86,6 +88,7 @@ def test_bad_command():
vfu_attach_ctx(ctx, expect=errno.EINVAL)
get_reply(sock, expect=errno.EINVAL)
+
def test_invalid_major():
sock = connect_sock()
@@ -96,6 +99,7 @@ def test_invalid_major():
vfu_attach_ctx(ctx, expect=errno.EINVAL)
get_reply(sock, expect=errno.EINVAL)
+
def test_invalid_json_missing_NUL():
sock = connect_sock()
@@ -107,45 +111,55 @@ def test_invalid_json_missing_NUL():
vfu_attach_ctx(ctx, expect=errno.EINVAL)
get_reply(sock, expect=errno.EINVAL)
+
def test_invalid_json_missing_closing_brace():
client_version_json(errno.EINVAL, b"{")
+
def test_invalid_json_missing_closing_quote():
client_version_json(errno.EINVAL, b'"')
+
def test_invalid_json_bad_capabilities_object():
client_version_json(errno.EINVAL, b'{ "capabilities": "23" }')
+
def test_invalid_json_bad_max_fds():
client_version_json(errno.EINVAL,
b'{ "capabilities": { "max_msg_fds": "foo" } }')
-def test_invalid_json_bad_max_fds():
+
+def test_invalid_json_bad_max_fds2():
client_version_json(errno.EINVAL,
b'{ "capabilities": { "max_msg_fds": -1 } }')
-def test_invalid_json_bad_max_fds2():
+
+def test_invalid_json_bad_max_fds3():
client_version_json(errno.EINVAL,
b'{ "capabilities": { "max_msg_fds": %d } }' %
(VFIO_USER_CLIENT_MAX_FDS_LIMIT + 1))
+
def test_invalid_json_bad_migration_object():
client_version_json(errno.EINVAL,
b'{ "capabilities": { "migration": "23" } }')
+
def test_invalid_json_bad_pgsize():
client_version_json(errno.EINVAL, b'{ "capabilities": ' +
b'{ "migration": { "pgsize": "foo" } } }')
+
#
# FIXME: need vfu_setup_device_migration_callbacks() to be able to test this
# failure mode.
#
-def test_invalid_json_bad_pgsize():
+def test_invalid_json_bad_pgsize2():
if False:
client_version_json(errno.EINVAL,
b'{ "capabilities": { "migration": { "pgsize": 4095 } } }')
+
def test_valid_negotiate_no_json():
sock = connect_sock()
@@ -167,12 +181,14 @@ def test_valid_negotiate_no_json():
disconnect_client(ctx, sock)
+
def test_valid_negotiate_empty_json():
client_version_json(json=b'{}')
# notice client closed connection
vfu_run_ctx(ctx)
+
def test_valid_negotiate_json():
client_version_json(json=bytes(
'{ "capabilities": { "max_msg_fds": %s, "max_data_xfer_size": %u } }' %
@@ -182,5 +198,6 @@ def test_valid_negotiate_json():
# notice client closed connection
vfu_run_ctx(ctx)
+
def test_destroying():
vfu_destroy_ctx(ctx)