From 561b3092c73b1b45756630fac73b182a3de0fdff Mon Sep 17 00:00:00 2001 From: John Levon Date: Wed, 14 Jul 2021 12:22:33 +0100 Subject: check vfu_run_ctx() in python tests (#582) Verify that the return value from vfu_run_ctx() is what we're expecting, rather than just driving on in case of error. Signed-off-by: John Levon Reviewed-by: Thanos Makatos --- test/py/libvfio_user.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/py/libvfio_user.py b/test/py/libvfio_user.py index ff5c1cd..8cd1c5d 100644 --- a/test/py/libvfio_user.py +++ b/test/py/libvfio_user.py @@ -34,6 +34,7 @@ from collections import namedtuple from types import SimpleNamespace import ctypes as c +import errno import json import mmap import os @@ -481,7 +482,9 @@ def disconnect_client(ctx, sock): sock.close() # notice client closed connection - vfu_run_ctx(ctx) + ret = vfu_run_ctx(ctx) + assert ret == -1 + assert c.get_errno() == errno.ENOTCONN def get_reply(sock, expect=0): buf = sock.recv(4096) @@ -500,7 +503,9 @@ def msg(ctx, sock, cmd, payload, expect=0, fds=None): else: sock.send(hdr + payload) - vfu_run_ctx(ctx) + ret = vfu_run_ctx(ctx) + assert ret >= 0 + return get_reply(sock, expect=expect) def get_pci_header(ctx): @@ -541,10 +546,8 @@ def access_region(ctx, sock, is_write, region, offset, count, payload += data cmd = VFIO_USER_REGION_WRITE if is_write else VFIO_USER_REGION_READ - hdr = vfio_user_header(cmd, size=len(payload)) - sock.send(hdr + payload) - vfu_run_ctx(ctx) - result = get_reply(sock, expect=expect) + + result = msg(ctx, sock, cmd, payload, expect=expect) if is_write: return None -- cgit v1.1