aboutsummaryrefslogtreecommitdiff
path: root/test/py/test_request_errors.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_request_errors.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_request_errors.py')
-rw-r--r--test/py/test_request_errors.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/test/py/test_request_errors.py b/test/py/test_request_errors.py
index fe6f29e..a734bab 100644
--- a/test/py/test_request_errors.py
+++ b/test/py/test_request_errors.py
@@ -28,21 +28,20 @@
#
from libvfio_user import *
-import ctypes as c
import errno
import os
-import sys
ctx = None
sock = None
argsz = len(vfio_irq_set())
+
def test_request_errors_setup():
global ctx, sock
ctx = vfu_create_ctx(flags=LIBVFIO_USER_FLAG_ATTACH_NB)
- assert ctx != None
+ assert ctx is not None
ret = vfu_pci_init(ctx)
assert ret == 0
@@ -55,6 +54,7 @@ def test_request_errors_setup():
sock = connect_client(ctx)
+
def test_too_small():
# struct vfio_user_header
hdr = struct.pack("HHIII", 0xbad1, VFIO_USER_DEVICE_SET_IRQS,
@@ -64,6 +64,7 @@ def test_too_small():
vfu_run_ctx(ctx)
get_reply(sock, expect=errno.EINVAL)
+
def test_too_large():
# struct vfio_user_header
hdr = struct.pack("HHIII", 0xbad1, VFIO_USER_DEVICE_SET_IRQS,
@@ -73,6 +74,7 @@ def test_too_large():
vfu_run_ctx(ctx)
get_reply(sock, expect=errno.EINVAL)
+
def test_unsolicited_reply():
# struct vfio_user_header
hdr = struct.pack("HHIII", 0xbad2, VFIO_USER_DEVICE_SET_IRQS,
@@ -82,6 +84,7 @@ def test_unsolicited_reply():
vfu_run_ctx(ctx)
get_reply(sock, expect=errno.EINVAL)
+
def test_bad_command():
hdr = vfio_user_header(VFIO_USER_MAX, size=1)
@@ -89,12 +92,14 @@ def test_bad_command():
vfu_run_ctx(ctx)
get_reply(sock, expect=errno.EINVAL)
+
def test_no_payload():
hdr = vfio_user_header(VFIO_USER_DEVICE_SET_IRQS, size=0)
sock.send(hdr)
vfu_run_ctx(ctx)
get_reply(sock, expect=errno.EINVAL)
+
def test_bad_request_closes_fds():
payload = vfio_irq_set(argsz=argsz, flags=VFIO_IRQ_SET_ACTION_TRIGGER |
VFIO_IRQ_SET_DATA_BOOL, index=VFU_DEV_MSIX_IRQ,
@@ -120,5 +125,6 @@ def test_bad_request_closes_fds():
os.close(fd1)
os.close(fd2)
+
def test_request_errors_cleanup():
vfu_destroy_ctx(ctx)