aboutsummaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
authorJag Raman <jag.raman@oracle.com>2022-06-07 16:21:40 -0400
committerGitHub <noreply@github.com>2022-06-07 21:21:40 +0100
commita767ebd126157c4aa55ff0fe5786681507fb7ea8 (patch)
tree6876e347860a2ab1871d0e413312fe507fd006d6 /test/py
parentd307dbcab74aef3680ba99d7f836f2bc0b4bc81e (diff)
downloadlibvfio-user-a767ebd126157c4aa55ff0fe5786681507fb7ea8.zip
libvfio-user-a767ebd126157c4aa55ff0fe5786681507fb7ea8.tar.gz
libvfio-user-a767ebd126157c4aa55ff0fe5786681507fb7ea8.tar.bz2
irq: inform device of IRQ mask & unmask via callback (#694)
Client masks or unmasks a device IRQ using the VFIO_USER_DEVICE_SET_IRQS message. Inform the device of such changes to the IRQ state. Signed-off-by: Jagannathan Raman <jag.raman@oracle.com> Reviewed-by: John Levon <john.levon@nutanix.com>
Diffstat (limited to 'test/py')
-rw-r--r--test/py/libvfio_user.py19
-rw-r--r--test/py/test_device_set_irqs.py19
2 files changed, 38 insertions, 0 deletions
diff --git a/test/py/libvfio_user.py b/test/py/libvfio_user.py
index 4bdb761..76d9315 100644
--- a/test/py/libvfio_user.py
+++ b/test/py/libvfio_user.py
@@ -624,6 +624,11 @@ lib.vfu_create_ioeventfd.argtypes = (c.c_void_p, c.c_uint32, c.c_int,
lib.vfu_device_quiesced.argtypes = (c.c_void_p, c.c_int)
+vfu_dev_irq_state_cb_t = c.CFUNCTYPE(None, c.c_void_p, c.c_uint32,
+ c.c_bool, use_errno=True)
+lib.vfu_setup_irq_state_callback.argtypes = (c.c_void_p, c.c_int,
+ vfu_dev_irq_state_cb_t)
+
def to_byte(val):
"""Cast an int to a byte value."""
@@ -1030,6 +1035,20 @@ def vfu_setup_device_nr_irqs(ctx, irqtype, count):
return lib.vfu_setup_device_nr_irqs(ctx, irqtype, count)
+def irq_state(ctx, vector, mask):
+ pass
+
+
+@vfu_dev_irq_state_cb_t
+def __irq_state(ctx, vector, mask):
+ irq_state(ctx, vector, mask)
+
+
+def vfu_setup_irq_state_callback(ctx, irqtype, cb=__irq_state):
+ assert ctx is not None
+ return lib.vfu_setup_irq_state_callback(ctx, irqtype, cb)
+
+
def vfu_pci_init(ctx, pci_type=VFU_PCI_TYPE_EXPRESS,
hdr_type=PCI_HEADER_TYPE_NORMAL):
assert ctx is not None
diff --git a/test/py/test_device_set_irqs.py b/test/py/test_device_set_irqs.py
index 382804a..7525b30 100644
--- a/test/py/test_device_set_irqs.py
+++ b/test/py/test_device_set_irqs.py
@@ -27,6 +27,8 @@
# DAMAGE.
#
+from unittest.mock import patch
+
from libvfio_user import *
import errno
import os
@@ -53,6 +55,9 @@ def test_device_set_irqs_setup():
ret = vfu_setup_device_nr_irqs(ctx, VFU_DEV_MSIX_IRQ, 2048)
assert ret == 0
+ vfu_setup_irq_state_callback(ctx, VFU_DEV_MSIX_IRQ)
+ assert ret == 0
+
ret = vfu_realize_ctx(ctx)
assert ret == 0
@@ -308,6 +313,20 @@ def test_device_set_irqs_enable_trigger_bool():
assert struct.unpack("Q", os.read(fd2, 8))[0] == 9
+@patch('libvfio_user.irq_state')
+def test_irq_state(mock_irq_state):
+ assert mock_irq_state.call_count == 0
+
+ payload = vfio_irq_set(argsz=argsz, flags=VFIO_IRQ_SET_DATA_NONE |
+ VFIO_IRQ_SET_ACTION_MASK,
+ index=VFU_DEV_MSIX_IRQ,
+ start=0, count=1)
+
+ msg(ctx, sock, VFIO_USER_DEVICE_SET_IRQS, payload)
+
+ assert mock_irq_state.call_count == 1
+
+
def test_device_set_irqs_cleanup():
vfu_destroy_ctx(ctx)