From c34d6ec02bae297b9256ac45ff71da0e2d4b4bc1 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 10 Jun 2021 11:35:08 +0100 Subject: python tests: add msg() utility function (#562) Most tests need to send a request, process it, then retrieve the reply. Add a utility function to avoid lots of tedious boilerplate. Signed-off-by: John Levon Reviewed-by: Thanos Makatos --- test/py/test_device_get_info.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'test/py/test_device_get_info.py') diff --git a/test/py/test_device_get_info.py b/test/py/test_device_get_info.py index a778604..ea9251b 100644 --- a/test/py/test_device_get_info.py +++ b/test/py/test_device_get_info.py @@ -52,28 +52,19 @@ def test_device_get_info(): payload = struct.pack("II", 0, 0) - hdr = vfio_user_header(VFIO_USER_DEVICE_GET_INFO, size=len(payload)) - sock.send(hdr + payload) - vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + msg(ctx, sock, VFIO_USER_DEVICE_GET_INFO, payload, expect=errno.EINVAL) # bad argsz payload = vfio_user_device_info(argsz=8, flags=0, num_regions=0, num_irqs=0) - hdr = vfio_user_header(VFIO_USER_DEVICE_GET_INFO, size=len(payload)) - sock.send(hdr + payload) - vfu_run_ctx(ctx) - get_reply(sock, expect=errno.EINVAL) + msg(ctx, sock, VFIO_USER_DEVICE_GET_INFO, payload, expect=errno.EINVAL) # valid with larger argsz payload = vfio_user_device_info(argsz=32, flags=0, num_regions=0, num_irqs=0) - hdr = vfio_user_header(VFIO_USER_DEVICE_GET_INFO, size=len(payload)) - sock.send(hdr + payload) - vfu_run_ctx(ctx) - result = get_reply(sock) + result = msg(ctx, sock, VFIO_USER_DEVICE_GET_INFO, payload) (argsz, flags, num_regions, num_irqs) = struct.unpack("IIII", result) -- cgit v1.1