aboutsummaryrefslogtreecommitdiff
path: root/test/py/test_migration.py
diff options
context:
space:
mode:
authorMattias Nissler <122288598+mnissler-rivos@users.noreply.github.com>2023-08-31 11:38:55 +0200
committerGitHub <noreply@github.com>2023-08-31 10:38:55 +0100
commita7eedffe20bd6e480c9e2c65e68daef1beb2af05 (patch)
tree37f46c9cbf8de3fbb0622b7472157d60f1b8550f /test/py/test_migration.py
parent2e8ec2e17a5252d29bae849eb4ccd7ca6bab216a (diff)
downloadlibvfio-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_migration.py')
-rw-r--r--test/py/test_migration.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/test/py/test_migration.py b/test/py/test_migration.py
index 614a615..a6327d8 100644
--- a/test/py/test_migration.py
+++ b/test/py/test_migration.py
@@ -33,11 +33,11 @@ import errno
from unittest.mock import patch
ctx = None
-sock = 0
+client = None
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
@@ -54,7 +54,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):
@@ -73,10 +73,10 @@ def test_migration_bad_access(mock_trans, mock_quiesce):
checking for a register-sized access, otherwise we'll change migration
state without having quiesced.
"""
- global ctx, sock
+ global ctx, client
data = VFIO_DEVICE_STATE_V1_SAVING.to_bytes(c.sizeof(c.c_int), 'little')
- write_region(ctx, sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
+ write_region(ctx, client.sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
count=len(data)-1, data=data, expect=errno.EINVAL)
mock_trans.assert_not_called()
@@ -89,10 +89,10 @@ def test_migration_trans_sync(mock_trans, mock_quiesce):
Tests transitioning to the saving state.
"""
- global ctx, sock
+ global ctx, client
data = VFIO_DEVICE_STATE_V1_SAVING.to_bytes(c.sizeof(c.c_int), 'little')
- write_region(ctx, sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
+ write_region(ctx, client.sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
count=len(data), data=data)
ret = vfu_run_ctx(ctx)
@@ -105,10 +105,10 @@ def test_migration_trans_sync_err(mock_trans):
Tests the device returning an error when the migration state is written to.
"""
- global ctx, sock
+ global ctx, client
data = VFIO_DEVICE_STATE_V1_SAVING.to_bytes(c.sizeof(c.c_int), 'little')
- write_region(ctx, sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
+ write_region(ctx, client.sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
count=len(data), data=data, expect=errno.EPERM)
ret = vfu_run_ctx(ctx)
@@ -123,18 +123,18 @@ def test_migration_trans_async(mock_trans, mock_quiesce):
quiescing.
"""
- global ctx, sock
+ global ctx, client
mock_quiesce
data = VFIO_DEVICE_STATE_V1_SAVING.to_bytes(c.sizeof(c.c_int), 'little')
- write_region(ctx, sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
+ write_region(ctx, client.sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
count=len(data), data=data, rsp=False,
busy=True)
ret = vfu_device_quiesced(ctx, 0)
assert ret == 0
- get_reply(sock)
+ get_reply(client.sock)
ret = vfu_run_ctx(ctx)
assert ret == 0
@@ -149,10 +149,10 @@ def test_migration_trans_async_err(mock_trans, mock_quiesce):
the new migration state.
"""
- global ctx, sock
+ global ctx, client
data = VFIO_DEVICE_STATE_V1_RUNNING.to_bytes(c.sizeof(c.c_int), 'little')
- write_region(ctx, sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
+ write_region(ctx, client.sock, VFU_PCI_DEV_MIGR_REGION_IDX, offset=0,
count=len(data), data=data, rsp=False,
busy=True)
@@ -160,7 +160,7 @@ def test_migration_trans_async_err(mock_trans, mock_quiesce):
assert ret == 0
print("waiting for reply")
- get_reply(sock, errno.ENOTTY)
+ get_reply(client.sock, errno.ENOTTY)
print("received reply")
# ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: #