tools/testing/selftests/vfio/vfio_pci_device_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/vfio/vfio_pci_device_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/vfio/vfio_pci_device_test.c- Extension
.c- Size
- 4637 bytes
- Lines
- 184
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hstdlib.hsys/ioctl.hsys/mman.hlinux/limits.hlinux/pci_regs.hlinux/sizes.hlinux/vfio.hlibvfio.hkselftest_harness.h
Detected Declarations
function main
Annotated Snippet
if (!(bar->info.flags & VFIO_REGION_INFO_FLAG_MMAP)) {
printf("BAR %d does not support mmap()\n", i);
ASSERT_EQ(NULL, bar->vaddr);
continue;
}
/*
* BARs that support mmap() should be automatically mapped by
* vfio_pci_device_init().
*/
ASSERT_NE(NULL, bar->vaddr);
ASSERT_NE(0, bar->info.size);
printf("BAR %d mapped at %p (size 0x%llx)\n", i, bar->vaddr, bar->info.size);
}
}
FIXTURE(vfio_pci_irq_test) {
struct iommu *iommu;
struct vfio_pci_device *device;
};
FIXTURE_VARIANT(vfio_pci_irq_test) {
int irq_index;
};
FIXTURE_VARIANT_ADD(vfio_pci_irq_test, msi) {
.irq_index = VFIO_PCI_MSI_IRQ_INDEX,
};
FIXTURE_VARIANT_ADD(vfio_pci_irq_test, msix) {
.irq_index = VFIO_PCI_MSIX_IRQ_INDEX,
};
FIXTURE_SETUP(vfio_pci_irq_test)
{
self->iommu = iommu_init(default_iommu_mode);
self->device = vfio_pci_device_init(device_bdf, self->iommu);
}
FIXTURE_TEARDOWN(vfio_pci_irq_test)
{
vfio_pci_device_cleanup(self->device);
iommu_cleanup(self->iommu);
}
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;
if (msix)
count = self->device->msix_info.count;
else
count = self->device->msi_info.count;
count = min(count, MAX_TEST_MSI);
if (!count)
SKIP(return, "MSI%s: not supported\n", msix ? "-x" : "");
vfio_pci_irq_enable(self->device, variant->irq_index, 0, count);
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(msi_eventfd, &value, 8));
ASSERT_EQ(1, value);
}
vfio_pci_irq_disable(self->device, variant->irq_index);
}
TEST_F(vfio_pci_device_test, reset)
{
if (!(self->device->info.flags & VFIO_DEVICE_FLAGS_RESET))
SKIP(return, "Device does not support reset\n");
vfio_pci_device_reset(self->device);
}
Annotation
- Immediate include surface: `fcntl.h`, `stdlib.h`, `sys/ioctl.h`, `sys/mman.h`, `linux/limits.h`, `linux/pci_regs.h`, `linux/sizes.h`, `linux/vfio.h`.
- Detected declarations: `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.