diff options
| author | David Matlack <dmatlack@google.com> | 2025-08-22 21:24:58 +0000 |
|---|---|---|
| committer | Alex Williamson <alex.williamson@redhat.com> | 2025-08-27 12:14:05 -0600 |
| commit | 50d8fe805f75a159551ddb6b04ecdad26ec50221 (patch) | |
| tree | d37a55bd1ad25bfdcb23703c94dfcf82822fcd68 | |
| parent | 924947804f2b9e564efdc814420d21b239df2dd4 (diff) | |
vfio: selftests: Add a helper for matching vendor+device IDs
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>
| -rw-r--r-- | tools/testing/selftests/vfio/lib/include/vfio_util.h | 7 | ||||
| -rw-r--r-- | tools/testing/selftests/vfio/vfio_pci_device_test.c | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/tools/testing/selftests/vfio/lib/include/vfio_util.h b/tools/testing/selftests/vfio/lib/include/vfio_util.h index 9c928fcc00e2..a51c971004cd 100644 --- a/tools/testing/selftests/vfio/lib/include/vfio_util.h +++ b/tools/testing/selftests/vfio/lib/include/vfio_util.h @@ -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 */ diff --git a/tools/testing/selftests/vfio/vfio_pci_device_test.c b/tools/testing/selftests/vfio/vfio_pci_device_test.c index 1b5c2ff77e3f..8856205d52a6 100644 --- a/tools/testing/selftests/vfio/vfio_pci_device_test.c +++ b/tools/testing/selftests/vfio/vfio_pci_device_test.c @@ -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); |
