Re: [PATCH RFC 17/33] vfio: selftests: Enable asserting MSI eventfds not firing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 30, 2025 at 5:24 AM Sairaj Kodilkar <sarunkod@xxxxxxx> wrote:
>
> On 5/24/2025 5:00 AM, David Matlack wrote:
> > 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().
> >
> > Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
> > ---
> >   tools/testing/selftests/vfio/lib/include/vfio_util.h | 12 ++++++++++++
> >   tools/testing/selftests/vfio/vfio_pci_device_test.c  | 10 +++++++++-
> >   2 files changed, 21 insertions(+), 1 deletion(-)
> >
> > diff --git a/tools/testing/selftests/vfio/lib/include/vfio_util.h b/tools/testing/selftests/vfio/lib/include/vfio_util.h
> > index ab96a6628f0e..2b96be07f182 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>
> > @@ -116,6 +117,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);
>
> fcntl F_GETFL does not expect argument

Good point, this could simply be:

  r = fcntl(fd, F_GETFL);

>
> > +     VFIO_ASSERT_NE(r, -1, "F_GETFL failed for fd %d\n", fd);
>
> May be print errno as well  ?

All of the VFIO_ASSERT*() macros print errno by default [1], since
it's relevant often enough.

The idea to print errno by default came from the KVM selftests [2]. In
a future series I'd like to find a way to share the assert code
between the KVM and VFIO selftests since there's a lot of overlap and
the KVM selftests also support useful things like backtraces on
assertion failures that I'd love to have in VFIO selftests.

[1] https://github.com/dmatlack/linux/blob/44c8e1e805698286e43cf2a471f540eee75e94a1/tools/testing/selftests/vfio/lib/include/vfio_util.h#L30
[2] https://github.com/dmatlack/linux/blob/44c8e1e805698286e43cf2a471f540eee75e94a1/tools/testing/selftests/kvm/lib/assert.c#L79





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux