]> www.infradead.org Git - users/hch/misc.git/commitdiff
vfio: selftests: Add a helper for matching vendor+device IDs
authorDavid Matlack <dmatlack@google.com>
Fri, 22 Aug 2025 21:24:58 +0000 (21:24 +0000)
committerAlex Williamson <alex.williamson@redhat.com>
Wed, 27 Aug 2025 18:14:05 +0000 (12:14 -0600)
Add a helper function for matching a device against a given vendor and
device ID. This will be used in a subsequent commit to match devices
against drivers.

Acked-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: David Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20250822212518.4156428-12-dmatlack@google.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
tools/testing/selftests/vfio/lib/include/vfio_util.h
tools/testing/selftests/vfio/vfio_pci_device_test.c

index 9c928fcc00e2f53b3cd876859da00ceba2e290b2..a51c971004cdbe1fd38b915408c196539e03108f 100644 (file)
@@ -167,4 +167,11 @@ static inline void vfio_pci_msix_disable(struct vfio_pci_device *device)
 iova_t __to_iova(struct vfio_pci_device *device, void *vaddr);
 iova_t to_iova(struct vfio_pci_device *device, void *vaddr);
 
+static inline bool vfio_pci_device_match(struct vfio_pci_device *device,
+                                        u16 vendor_id, u16 device_id)
+{
+       return (vendor_id == vfio_pci_config_readw(device, PCI_VENDOR_ID)) &&
+               (device_id == vfio_pci_config_readw(device, PCI_DEVICE_ID));
+}
+
 #endif /* SELFTESTS_VFIO_LIB_INCLUDE_VFIO_UTIL_H */
index 1b5c2ff77e3f339b3bbcfe96bb35b118d5068c31..8856205d52a693fc6a5d4e6e0f2128048d71be22 100644 (file)
@@ -56,9 +56,7 @@ TEST_F(vfio_pci_device_test, config_space_read_write)
        /* Check that Vendor and Device match what the kernel reports. */
        vendor = read_pci_id_from_sysfs("vendor");
        device = read_pci_id_from_sysfs("device");
-
-       ASSERT_EQ(vendor, vfio_pci_config_readw(self->device, PCI_VENDOR_ID));
-       ASSERT_EQ(device, vfio_pci_config_readw(self->device, PCI_DEVICE_ID));
+       ASSERT_TRUE(vfio_pci_device_match(self->device, vendor, device));
 
        printf("Vendor: %04x, Device: %04x\n", vendor, device);