diff options
author | John Levon <john.levon@nutanix.com> | 2021-05-26 12:26:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 12:26:54 +0100 |
commit | bc8ae1ddf3af34113040345a256a8787443cdbb8 (patch) | |
tree | 93cf97e5be2ff55b0a799330470590feccafe4d5 /test/py | |
parent | 7aca16a2cf2b00b11fbdb51829b47c3838eeb151 (diff) | |
download | libvfio-user-bc8ae1ddf3af34113040345a256a8787443cdbb8.zip libvfio-user-bc8ae1ddf3af34113040345a256a8787443cdbb8.tar.gz libvfio-user-bc8ae1ddf3af34113040345a256a8787443cdbb8.tar.bz2 |
python tests: add VFIO_USER_DEVICE_GET_IRQ_INFO (#500)
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'test/py')
-rw-r--r-- | test/py/libvfio_user.py | 10 | ||||
-rw-r--r-- | test/py/test_device_get_irq_info.py | 149 |
2 files changed, 159 insertions, 0 deletions
diff --git a/test/py/libvfio_user.py b/test/py/libvfio_user.py index 31e9767..fb201dd 100644 --- a/test/py/libvfio_user.py +++ b/test/py/libvfio_user.py @@ -83,6 +83,8 @@ VFIO_REGION_SUBTYPE_MIGRATION = 1 VFIO_REGION_INFO_CAP_SPARSE_MMAP = 1 VFIO_REGION_INFO_CAP_TYPE = 2 +VFIO_IRQ_INFO_EVENTFD = (1 << 0) + VFIO_IRQ_SET_DATA_NONE = (1 << 0) VFIO_IRQ_SET_DATA_BOOL = (1 << 1) VFIO_IRQ_SET_DATA_EVENTFD = (1 << 2) @@ -235,6 +237,14 @@ class iovec_t(Structure): ("iov_len", c.c_int) ] +class vfio_irq_info(Structure): + _fields_ = [ + ("argsz", c.c_uint), + ("flags", c.c_uint), + ("index", c.c_uint), + ("count", c.c_uint), + ] + class vfio_irq_set(Structure): _fields_ = [ ("argsz", c.c_uint), diff --git a/test/py/test_device_get_irq_info.py b/test/py/test_device_get_irq_info.py new file mode 100644 index 0000000..8283083 --- /dev/null +++ b/test/py/test_device_get_irq_info.py @@ -0,0 +1,149 @@ +# +# Copyright (c) 2021 Nutanix Inc. All rights reserved. +# +# Authors: John Levon <john.levon@nutanix.com> +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Nutanix nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH +# DAMAGE. +# + +from libvfio_user import * +import errno + +ctx = None +sock = None + +argsz = len(vfio_irq_info()) + +def test_device_get_irq_info_setup(): + global ctx, sock + + ctx = vfu_create_ctx(flags=LIBVFIO_USER_FLAG_ATTACH_NB) + assert ctx != None + + ret = vfu_pci_init(ctx) + assert ret == 0 + + ret = vfu_setup_device_nr_irqs(ctx, VFU_DEV_REQ_IRQ, 1) + assert ret == 0 + ret = vfu_setup_device_nr_irqs(ctx, VFU_DEV_ERR_IRQ, 1) + assert ret == 0 + ret = vfu_setup_device_nr_irqs(ctx, VFU_DEV_MSIX_IRQ, 2048) + assert ret == 0 + + ret = vfu_realize_ctx(ctx) + assert ret == 0 + + sock = connect_client(ctx) + +def test_device_get_irq_info_bad_in(): + payload = struct.pack("II", 0, 0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + sock.send(hdr + payload) + vfu_run_ctx(ctx) + get_reply(sock, expect=errno.EINVAL) + + # bad argsz + payload = vfio_irq_info(argsz=8, flags=0, index=VFU_DEV_REQ_IRQ, + count=0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + sock.send(hdr + payload) + vfu_run_ctx(ctx) + get_reply(sock, expect=errno.EINVAL) + + # bad index + payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_NUM_IRQS, + count=0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + sock.send(hdr + payload) + vfu_run_ctx(ctx) + get_reply(sock, expect=errno.EINVAL) + +def test_device_get_irq_info(): + + # valid with larger argsz + + payload = vfio_irq_info(argsz=argsz + 16, flags=0, index=VFU_DEV_REQ_IRQ, + count=0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + + sock.send(hdr + payload) + vfu_run_ctx(ctx) + get_reply(sock) + + payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_REQ_IRQ, + count=0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + + sock.send(hdr + payload) + vfu_run_ctx(ctx) + result = get_reply(sock) + + info, _ = vfio_irq_info.pop_from_buffer(result) + + assert info.argsz == argsz + assert info.flags == VFIO_IRQ_INFO_EVENTFD + assert info.index == VFU_DEV_REQ_IRQ + assert info.count == 1 + + payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_ERR_IRQ, + count=0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + + sock.send(hdr + payload) + vfu_run_ctx(ctx) + result = get_reply(sock) + + info, _ = vfio_irq_info.pop_from_buffer(result) + + assert info.argsz == argsz + assert info.flags == VFIO_IRQ_INFO_EVENTFD + assert info.index == VFU_DEV_ERR_IRQ + assert info.count == 1 + + payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_MSIX_IRQ, + count=0) + + hdr = vfio_user_header(VFIO_USER_DEVICE_GET_IRQ_INFO, size=len(payload)) + + sock.send(hdr + payload) + vfu_run_ctx(ctx) + result = get_reply(sock) + + info, _ = vfio_irq_info.pop_from_buffer(result) + + assert info.argsz == argsz + assert info.flags == VFIO_IRQ_INFO_EVENTFD + assert info.index == VFU_DEV_MSIX_IRQ + assert info.count == 2048 + +def test_device_get_irq_info_cleanup(): + disconnect_client(ctx, sock) + + vfu_destroy_ctx(ctx) |