summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/vfio/lib
diff options
context:
space:
mode:
authorDavid Matlack <dmatlack@google.com>2025-08-22 21:24:57 +0000
committerAlex Williamson <alex.williamson@redhat.com>2025-08-27 12:14:04 -0600
commit924947804f2b9e564efdc814420d21b239df2dd4 (patch)
treec65cebe89fcdc1c7038c4451758618e8dcb79c4f /tools/testing/selftests/vfio/lib
parent346cd58f1fb588f8ff193d76cf0bb455446ace03 (diff)
vfio: selftests: Enable asserting MSI eventfds not firing
Make it possible to assert that a given MSI eventfd did _not_ fire by adding a helper to mark an eventfd non-blocking. Demonstrate this in vfio_pci_device_test by asserting the MSI eventfd did not fire before vfio_pci_irq_trigger(). Acked-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: David Matlack <dmatlack@google.com> Link: https://lore.kernel.org/r/20250822212518.4156428-11-dmatlack@google.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'tools/testing/selftests/vfio/lib')
-rw-r--r--tools/testing/selftests/vfio/lib/include/vfio_util.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/testing/selftests/vfio/lib/include/vfio_util.h b/tools/testing/selftests/vfio/lib/include/vfio_util.h
index db08646c2819..9c928fcc00e2 100644
--- a/tools/testing/selftests/vfio/lib/include/vfio_util.h
+++ b/tools/testing/selftests/vfio/lib/include/vfio_util.h
@@ -2,6 +2,7 @@
#ifndef SELFTESTS_VFIO_LIB_INCLUDE_VFIO_UTIL_H
#define SELFTESTS_VFIO_LIB_INCLUDE_VFIO_UTIL_H
+#include <fcntl.h>
#include <string.h>
#include <linux/vfio.h>
#include <linux/list.h>
@@ -130,6 +131,17 @@ void vfio_pci_irq_enable(struct vfio_pci_device *device, u32 index,
void vfio_pci_irq_disable(struct vfio_pci_device *device, u32 index);
void vfio_pci_irq_trigger(struct vfio_pci_device *device, u32 index, u32 vector);
+static inline void fcntl_set_nonblock(int fd)
+{
+ int r;
+
+ r = fcntl(fd, F_GETFL, 0);
+ VFIO_ASSERT_NE(r, -1, "F_GETFL failed for fd %d\n", fd);
+
+ r = fcntl(fd, F_SETFL, r | O_NONBLOCK);
+ VFIO_ASSERT_NE(r, -1, "F_SETFL O_NONBLOCK failed for fd %d\n", fd);
+}
+
static inline void vfio_pci_msi_enable(struct vfio_pci_device *device,
u32 vector, int count)
{