This RFC series shows how I'm using qtest to implement virtio device test cases. The main pieces are:
1. libpci is a thin PCI device wrapper that makes it possible to access configuration space and map BARs. There is stuff missing, I have not dealt with MMIO or interrupts yet. But this might already be useful for others who want to write qtests for PCI devices. 2. One advantage of qtest is that C tests can share headers, constants, and utility functions with QEMU. This reduces code duplication and I've done that for virtio where it makes sense. The same can probably be done for other devices so that the test code can reuse most of the constants. 3. virtio-test is the beginning of a virtio-pci test case. Right now it just probes the PCI device and gets the virtio device going. I still need to add the real meat of the test cases here. If you are writing qtests for devices, please take a look and feel free to use libpci to get started more quickly. Stefan Hajnoczi (3): tests: add libpci qtest library virtio: move virtio spec constants to separate headers qtest: add virtio-test test-case hw/9pfs/virtio-9p-device.c | 1 + hw/virtio-defs.h | 70 +++++++++++++++++++++++++++++ hw/virtio-pci-defs.h | 70 +++++++++++++++++++++++++++++ hw/virtio-pci.c | 45 +------------------ hw/virtio-pci.h | 3 -- hw/virtio.c | 4 -- hw/virtio.h | 45 +------------------ tests/Makefile | 3 +- tests/libpci.c | 106 ++++++++++++++++++++++++++++++++++++++++++++ tests/libpci.h | 41 +++++++++++++++++ tests/virtio-test.c | 88 ++++++++++++++++++++++++++++++++++++ 11 files changed, 380 insertions(+), 96 deletions(-) create mode 100644 hw/virtio-defs.h create mode 100644 hw/virtio-pci-defs.h create mode 100644 tests/libpci.c create mode 100644 tests/libpci.h create mode 100644 tests/virtio-test.c -- 1.7.9.5