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>
This commit is contained in:
David Matlack
2025-08-22 21:24:57 +00:00
committed by Alex Williamson
parent 346cd58f1f
commit 924947804f
2 changed files with 21 additions and 1 deletions

View File

@@ -129,6 +129,7 @@ FIXTURE_TEARDOWN(vfio_pci_irq_test)
TEST_F(vfio_pci_irq_test, enable_trigger_disable)
{
bool msix = variant->irq_index == VFIO_PCI_MSIX_IRQ_INDEX;
int msi_eventfd;
u32 count;
u64 value;
int i;
@@ -147,8 +148,15 @@ TEST_F(vfio_pci_irq_test, enable_trigger_disable)
printf("MSI%s: enabled %d interrupts\n", msix ? "-x" : "", count);
for (i = 0; i < count; i++) {
msi_eventfd = self->device->msi_eventfds[i];
fcntl_set_nonblock(msi_eventfd);
ASSERT_EQ(-1, read(msi_eventfd, &value, 8));
ASSERT_EQ(EAGAIN, errno);
vfio_pci_irq_trigger(self->device, variant->irq_index, i);
ASSERT_EQ(8, read(self->device->msi_eventfds[i], &value, 8));
ASSERT_EQ(8, read(msi_eventfd, &value, 8));
ASSERT_EQ(1, value);
}