Some device drivers may not have the capability to trigger MSI/MSI-X
interrupts from software. Add checks to skip the send_msi test and
the MSI portion of the mix_and_match test when the driver's send_msi
callback is NULL, allowing these drivers to still run the DMA tests.

Signed-off-by: Rubin Du <[email protected]>
---
 .../selftests/vfio/lib/include/libvfio/vfio_pci_device.h  | 3 +++
 tools/testing/selftests/vfio/vfio_pci_driver_test.c       | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h 
b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
index 2858885a89bb..a497fc990924 100644
--- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
+++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
@@ -74,6 +74,9 @@ static inline void fcntl_set_nonblock(int fd)
 {
        int r;
 
+       if (fd == -1)
+               return;
+
        r = fcntl(fd, F_GETFL, 0);
        VFIO_ASSERT_NE(r, -1, "F_GETFL failed for fd %d\n", fd);
 
diff --git a/tools/testing/selftests/vfio/vfio_pci_driver_test.c 
b/tools/testing/selftests/vfio/vfio_pci_driver_test.c
index afa0480ddd9b..8269da741b67 100644
--- a/tools/testing/selftests/vfio/vfio_pci_driver_test.c
+++ b/tools/testing/selftests/vfio/vfio_pci_driver_test.c
@@ -14,6 +14,8 @@ static const char *device_bdf;
 #define ASSERT_NO_MSI(_eventfd) do {                   \
        u64 __value;                                    \
                                                        \
+       if (_eventfd == -1)                             \
+               break;                                  \
        ASSERT_EQ(-1, read(_eventfd, &__value, 8));     \
        ASSERT_EQ(EAGAIN, errno);                       \
 } while (0)
@@ -175,6 +177,9 @@ TEST_F(vfio_pci_driver_test, send_msi)
 {
        u64 value;
 
+       if (self->device->driver.ops->send_msi == NULL)
+               SKIP(return, "Device does not support MSI\n");
+
        vfio_pci_driver_send_msi(self->device);
        ASSERT_EQ(8, read(self->msi_fd, &value, 8));
        ASSERT_EQ(1, value);
@@ -201,6 +206,9 @@ TEST_F(vfio_pci_driver_test, mix_and_match)
                                       self->dst_iova,
                                       self->size);
 
+               if (self->device->driver.ops->send_msi == NULL)
+                       continue;
+
                vfio_pci_driver_send_msi(self->device);
                ASSERT_EQ(8, read(self->msi_fd, &value, 8));
                ASSERT_EQ(1, value);
-- 
2.43.0


Reply via email to