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_pci_ext_caps.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_pci_ext_caps.py')
-rw-r--r-- | test/py/test_pci_ext_caps.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/test/py/test_pci_ext_caps.py b/test/py/test_pci_ext_caps.py index c425c8b..53af9df 100644 --- a/test/py/test_pci_ext_caps.py +++ b/test/py/test_pci_ext_caps.py @@ -224,37 +224,37 @@ def test_find_ext_caps(): def test_pci_ext_cap_write_hdr(): - sock = connect_client(ctx) + client = connect_client(ctx) # struct pcie_ext_cap_hdr offset = cap_offsets[0] data = b'\x01' - write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + write_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, count=len(data), data=data, expect=errno.EPERM) # struct pcie_ext_cap_vsc_hdr also offset = cap_offsets[1] + 4 - write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + write_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, count=len(data), data=data, expect=errno.EPERM) - disconnect_client(ctx, sock) + client.disconnect(ctx) def test_pci_ext_cap_readonly(): - sock = connect_client(ctx) + client = connect_client(ctx) # start of vendor payload offset = cap_offsets[1] + 8 data = b'\x01' - write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + write_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, count=len(data), data=data, expect=errno.EPERM) offset = cap_offsets[1] + 8 - payload = read_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, - count=5) + payload = read_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, + offset=offset, count=5) assert payload == b'abcde' - disconnect_client(ctx, sock) + client.disconnect(ctx) def test_pci_ext_cap_callback(): @@ -262,42 +262,42 @@ def test_pci_ext_cap_callback(): # FIXME assignment to PCI config space from callback is ignored if is_32bit(): return - sock = connect_client(ctx) + client = connect_client(ctx) # start of vendor payload offset = cap_offsets[2] + 8 data = b"Hello world." - payload = read_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, - count=len(data)) + payload = read_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, + offset=offset, count=len(data)) assert payload == data data = b"Bye world." - write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + write_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, count=len(data), data=data) - payload = read_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, - count=len(data)) + payload = read_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, + offset=offset, count=len(data)) assert payload == data - disconnect_client(ctx, sock) + client.disconnect(ctx) def test_pci_ext_cap_write_dsn(): - sock = connect_client(ctx) + client = connect_client(ctx) data = struct.pack("II", 1, 2) offset = cap_offsets[0] + 4 - write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + write_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, count=len(data), data=data, expect=errno.EPERM) - payload = read_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, - count=len(data)) + payload = read_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, + offset=offset, count=len(data)) # unchanged! assert payload == struct.pack("II", 4, 8) - disconnect_client(ctx, sock) + client.disconnect(ctx) def test_pci_ext_cap_write_vendor(): @@ -306,20 +306,20 @@ def test_pci_ext_cap_write_vendor(): if is_32bit(): return - sock = connect_client(ctx) + client = connect_client(ctx) data = struct.pack("II", 0x1, 0x2) # start of vendor payload offset = cap_offsets[2] + 8 - write_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, + write_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, count=len(data), data=data) - payload = read_region(ctx, sock, VFU_PCI_DEV_CFG_REGION_IDX, offset=offset, - count=len(data)) + payload = read_region(ctx, client.sock, VFU_PCI_DEV_CFG_REGION_IDX, + offset=offset, count=len(data)) assert payload == data - disconnect_client(ctx, sock) + client.disconnect(ctx) def test_pci_ext_cap_cleanup(): |