tests: Reuse qemucapabilities data for qemucaps2xml

While qemucaps2xml has a meager two test cases to its name, we
have plenty of data from qemucapabilities which is taken from
actual QEMU binaries, covers pretty much all supported QEMU
versions and architectures and is even in the right format already!

Rewrite qemucaps2xml so that it uses qemucapabilities data as
input. Right now we have a single test case, but we're going to
add a lot more next.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Andrea Bolognani 2018-09-13 18:06:20 +02:00
parent 11e1f11dd3
commit 562990849a
5 changed files with 23 additions and 311 deletions

View File

@ -1,129 +0,0 @@
<qemuCaps>
<flag name='mem-path'/>
<flag name='drive-serial'/>
<flag name='chardev'/>
<flag name='enable-kvm'/>
<flag name='monitor-json'/>
<flag name='balloon'/>
<flag name='device'/>
<flag name='sdl'/>
<flag name='smp-topology'/>
<flag name='netdev'/>
<flag name='rtc'/>
<flag name='vhost-net'/>
<flag name='no-hpet'/>
<flag name='no-kvm-pit'/>
<flag name='pci-configfd'/>
<flag name='nodefconfig'/>
<flag name='boot-menu'/>
<flag name='fsdev'/>
<flag name='name-process'/>
<flag name='drive-readonly'/>
<flag name='smbios-type'/>
<flag name='vga-qxl'/>
<flag name='spice'/>
<flag name='vga-none'/>
<flag name='boot-index'/>
<flag name='hda-duplex'/>
<flag name='drive-aio'/>
<flag name='pci-multibus'/>
<flag name='pci-bootindex'/>
<flag name='ccid-emulated'/>
<flag name='ccid-passthru'/>
<flag name='chardev-spicevmc'/>
<flag name='virtio-tx-alg'/>
<flag name='device-qxl-vga'/>
<flag name='pci-multifunction'/>
<flag name='virtio-blk-pci.ioeventfd'/>
<flag name='sga'/>
<flag name='virtio-blk-pci.event_idx'/>
<flag name='virtio-net-pci.event_idx'/>
<flag name='cache-directsync'/>
<flag name='piix3-usb-uhci'/>
<flag name='piix4-usb-uhci'/>
<flag name='usb-ehci'/>
<flag name='ich9-usb-ehci1'/>
<flag name='vt82c686b-usb-uhci'/>
<flag name='pci-ohci'/>
<flag name='usb-hub'/>
<flag name='no-shutdown'/>
<flag name='cache-unsafe'/>
<flag name='rombar'/>
<flag name='ich9-ahci'/>
<flag name='no-acpi'/>
<flag name='fsdev-readonly'/>
<flag name='virtio-blk-pci.scsi'/>
<flag name='blk-sg-io'/>
<flag name='drive-copy-on-read'/>
<flag name='cpu-host'/>
<flag name='fsdev-writeout'/>
<flag name='drive-iotune'/>
<flag name='system_wakeup'/>
<flag name='scsi-disk.channel'/>
<flag name='scsi-block'/>
<flag name='transaction'/>
<flag name='block-job-async'/>
<flag name='scsi-cd'/>
<flag name='ide-cd'/>
<flag name='no-user-config'/>
<flag name='hda-micro'/>
<flag name='dump-guest-memory'/>
<flag name='nec-usb-xhci'/>
<flag name='balloon-event'/>
<flag name='bridge'/>
<flag name='lsi'/>
<flag name='virtio-scsi-pci'/>
<flag name='blockio'/>
<flag name='disable-s3'/>
<flag name='disable-s4'/>
<flag name='ide-drive.wwn'/>
<flag name='scsi-disk.wwn'/>
<flag name='seccomp-sandbox'/>
<flag name='dump-guest-core'/>
<flag name='seamless-migration'/>
<flag name='block-commit'/>
<flag name='vnc'/>
<flag name='drive-mirror'/>
<flag name='usb-host.bootindex'/>
<flag name='blockdev-snapshot-sync'/>
<flag name='qxl'/>
<flag name='VGA'/>
<flag name='cirrus-vga'/>
<flag name='vmware-svga'/>
<flag name='device-video-primary'/>
<flag name='usb-serial'/>
<flag name='usb-net'/>
<flag name='add-fd'/>
<flag name='nbd-server'/>
<flag name='virtio-rng'/>
<flag name='rng-random'/>
<flag name='rng-egd'/>
<flag name='dtb'/>
<flag name='megasas'/>
<flag name='ipv6-migration'/>
<flag name='machine-opt'/>
<flag name='machine-usb-opt'/>
<flag name='pci-bridge'/>
<flag name='vfio-pci'/>
<flag name='vfio-pci.bootindex'/>
<flag name='scsi-generic'/>
<flag name='scsi-generic.bootindex'/>
<flag name='mem-merge'/>
<flag name='vnc-websocket'/>
<flag name='mlock'/>
<flag name='vnc-share-policy'/>
<flag name='device-del-event'/>
<flag name='dmi-to-pci-bridge'/>
<flag name='i440fx-pci-hole64-size'/>
<flag name='q35-pci-hole64-size'/>
<flag name='usb-storage'/>
<flag name='usb-storage.removable'/>
<flag name='virtio-mmio'/>
<flag name='ich9-intel-hda'/>
<flag name='kvm-pit-lost-tick-policy'/>
<flag name='boot-strict'/>
<flag name='pvpanic'/>
<flag name='reboot-timeout'/>
<flag name='enable-fips'/>
<flag name='name-guest'/>
</qemuCaps>

View File

@ -1,128 +0,0 @@
<qemuCaps>
<flag name='mem-path'/>
<flag name='drive-serial'/>
<flag name='chardev'/>
<flag name='enable-kvm'/>
<flag name='monitor-json'/>
<flag name='balloon'/>
<flag name='device'/>
<flag name='sdl'/>
<flag name='smp-topology'/>
<flag name='netdev'/>
<flag name='rtc'/>
<flag name='vhost-net'/>
<flag name='no-hpet'/>
<flag name='no-kvm-pit'/>
<flag name='pci-configfd'/>
<flag name='nodefconfig'/>
<flag name='boot-menu'/>
<flag name='fsdev'/>
<flag name='name-process'/>
<flag name='drive-readonly'/>
<flag name='smbios-type'/>
<flag name='vga-qxl'/>
<flag name='spice'/>
<flag name='vga-none'/>
<flag name='boot-index'/>
<flag name='hda-duplex'/>
<flag name='drive-aio'/>
<flag name='pci-multibus'/>
<flag name='pci-bootindex'/>
<flag name='ccid-emulated'/>
<flag name='ccid-passthru'/>
<flag name='chardev-spicevmc'/>
<flag name='virtio-tx-alg'/>
<flag name='device-qxl-vga'/>
<flag name='pci-multifunction'/>
<flag name='virtio-blk-pci.ioeventfd'/>
<flag name='sga'/>
<flag name='virtio-blk-pci.event_idx'/>
<flag name='virtio-net-pci.event_idx'/>
<flag name='cache-directsync'/>
<flag name='piix3-usb-uhci'/>
<flag name='piix4-usb-uhci'/>
<flag name='usb-ehci'/>
<flag name='ich9-usb-ehci1'/>
<flag name='vt82c686b-usb-uhci'/>
<flag name='pci-ohci'/>
<flag name='usb-hub'/>
<flag name='no-shutdown'/>
<flag name='cache-unsafe'/>
<flag name='rombar'/>
<flag name='ich9-ahci'/>
<flag name='no-acpi'/>
<flag name='fsdev-readonly'/>
<flag name='virtio-blk-pci.scsi'/>
<flag name='blk-sg-io'/>
<flag name='drive-copy-on-read'/>
<flag name='cpu-host'/>
<flag name='fsdev-writeout'/>
<flag name='drive-iotune'/>
<flag name='system_wakeup'/>
<flag name='scsi-disk.channel'/>
<flag name='scsi-block'/>
<flag name='transaction'/>
<flag name='block-job-async'/>
<flag name='scsi-cd'/>
<flag name='ide-cd'/>
<flag name='no-user-config'/>
<flag name='hda-micro'/>
<flag name='dump-guest-memory'/>
<flag name='nec-usb-xhci'/>
<flag name='balloon-event'/>
<flag name='bridge'/>
<flag name='lsi'/>
<flag name='virtio-scsi-pci'/>
<flag name='blockio'/>
<flag name='disable-s3'/>
<flag name='disable-s4'/>
<flag name='ide-drive.wwn'/>
<flag name='scsi-disk.wwn'/>
<flag name='seccomp-sandbox'/>
<flag name='dump-guest-core'/>
<flag name='seamless-migration'/>
<flag name='block-commit'/>
<flag name='vnc'/>
<flag name='drive-mirror'/>
<flag name='usb-host.bootindex'/>
<flag name='qxl'/>
<flag name='VGA'/>
<flag name='cirrus-vga'/>
<flag name='vmware-svga'/>
<flag name='device-video-primary'/>
<flag name='usb-serial'/>
<flag name='usb-net'/>
<flag name='add-fd'/>
<flag name='nbd-server'/>
<flag name='virtio-rng'/>
<flag name='rng-random'/>
<flag name='rng-egd'/>
<flag name='dtb'/>
<flag name='megasas'/>
<flag name='ipv6-migration'/>
<flag name='machine-opt'/>
<flag name='machine-usb-opt'/>
<flag name='pci-bridge'/>
<flag name='vfio-pci'/>
<flag name='vfio-pci.bootindex'/>
<flag name='scsi-generic'/>
<flag name='scsi-generic.bootindex'/>
<flag name='mem-merge'/>
<flag name='vnc-websocket'/>
<flag name='mlock'/>
<flag name='vnc-share-policy'/>
<flag name='device-del-event'/>
<flag name='dmi-to-pci-bridge'/>
<flag name='i440fx-pci-hole64-size'/>
<flag name='q35-pci-hole64-size'/>
<flag name='usb-storage'/>
<flag name='usb-storage.removable'/>
<flag name='virtio-mmio'/>
<flag name='ich9-intel-hda'/>
<flag name='kvm-pit-lost-tick-policy'/>
<flag name='boot-strict'/>
<flag name='pvpanic'/>
<flag name='reboot-timeout'/>
<flag name='enable-fips'/>
<flag name='name-guest'/>
</qemuCaps>

View File

@ -1,32 +0,0 @@
<capabilities>
<host>
<cpu>
<arch>i686</arch>
</cpu>
<power_management/>
<iommu support='no'/>
</host>
<guest>
<os_type>hvm</os_type>
<arch name='i686'>
<wordsize>32</wordsize>
<emulator>/usr/bin/qemu-system-i386</emulator>
<domain type='qemu'/>
<domain type='kvm'>
<emulator>/usr/bin/qemu-system-i386</emulator>
</domain>
</arch>
<features>
<cpuselection/>
<deviceboot/>
<disksnapshot default='off' toggle='no'/>
<acpi default='on' toggle='yes'/>
<apic default='on' toggle='no'/>
<pae/>
<nonpae/>
</features>
</guest>
</capabilities>

View File

@ -2,7 +2,7 @@
<host> <host>
<cpu> <cpu>
<arch>i686</arch> <arch>x86_64</arch>
</cpu> </cpu>
<power_management/> <power_management/>
<iommu support='no'/> <iommu support='no'/>
@ -10,12 +10,12 @@
<guest> <guest>
<os_type>hvm</os_type> <os_type>hvm</os_type>
<arch name='i686'> <arch name='x86_64'>
<wordsize>32</wordsize> <wordsize>64</wordsize>
<emulator>/usr/bin/qemu-system-i386</emulator> <emulator>/usr/bin/qemu-system-x86_64</emulator>
<domain type='qemu'/> <domain type='qemu'/>
<domain type='kvm'> <domain type='kvm'>
<emulator>/usr/bin/qemu-system-i386</emulator> <emulator>/usr/bin/qemu-system-x86_64</emulator>
</domain> </domain>
</arch> </arch>
<features> <features>
@ -24,8 +24,6 @@
<disksnapshot default='on' toggle='no'/> <disksnapshot default='on' toggle='no'/>
<acpi default='on' toggle='yes'/> <acpi default='on' toggle='yes'/>
<apic default='on' toggle='no'/> <apic default='on' toggle='no'/>
<pae/>
<nonpae/>
</features> </features>
</guest> </guest>

View File

@ -32,7 +32,7 @@ typedef struct _testQemuData testQemuData;
typedef testQemuData *testQemuDataPtr; typedef testQemuData *testQemuDataPtr;
struct _testQemuData { struct _testQemuData {
const char *base; const char *base;
virArch guestarch; const char *archName;
}; };
static virQEMUCapsPtr static virQEMUCapsPtr
@ -87,23 +87,28 @@ testGetCaps(char *capsData, const testQemuData *data)
{ {
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
virArch arch = virArchFromString(data->archName);
char *binary = NULL;
if (virAsprintf(&binary, "/usr/bin/qemu-system-%s", data->archName) < 0)
goto error;
if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) { if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
fprintf(stderr, "failed to parse qemu capabilities flags"); fprintf(stderr, "failed to parse qemu capabilities flags");
goto error; goto error;
} }
if ((caps = virCapabilitiesNew(data->guestarch, false, false)) == NULL) { if ((caps = virCapabilitiesNew(arch, false, false)) == NULL) {
fprintf(stderr, "failed to create the fake capabilities"); fprintf(stderr, "failed to create the fake capabilities");
goto error; goto error;
} }
if (virQEMUCapsInitGuestFromBinary(caps, if (virQEMUCapsInitGuestFromBinary(caps,
"/usr/bin/qemu-system-i386", binary,
qemuCaps, qemuCaps,
NULL, NULL,
NULL, NULL,
data->guestarch) < 0) { arch) < 0) {
fprintf(stderr, "failed to create the capabilities from qemu"); fprintf(stderr, "failed to create the capabilities from qemu");
goto error; goto error;
} }
@ -114,6 +119,7 @@ testGetCaps(char *capsData, const testQemuData *data)
error: error:
virObjectUnref(qemuCaps); virObjectUnref(qemuCaps);
virObjectUnref(caps); virObjectUnref(caps);
VIR_FREE(binary);
return NULL; return NULL;
} }
@ -127,12 +133,12 @@ testQemuCapsXML(const void *opaque)
char *capsXml = NULL; char *capsXml = NULL;
virCapsPtr capsProvided = NULL; virCapsPtr capsProvided = NULL;
if (virAsprintf(&xmlFile, "%s/qemucaps2xmldata/%s.xml", if (virAsprintf(&xmlFile, "%s/qemucaps2xmloutdata/%s.%s.xml",
abs_srcdir, data->base) < 0) abs_srcdir, data->base, data->archName) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&capsFile, "%s/qemucaps2xmldata/%s.caps", if (virAsprintf(&capsFile, "%s/qemucapabilitiesdata/%s.%s.xml",
abs_srcdir, data->base) < 0) abs_srcdir, data->base, data->archName) < 0)
goto cleanup; goto cleanup;
if (virTestLoadFile(capsFile, &capsData) < 0) if (virTestLoadFile(capsFile, &capsData) < 0)
@ -175,16 +181,13 @@ mymain(void)
virEventRegisterDefaultImpl(); virEventRegisterDefaultImpl();
#define DO_TEST_FULL(name, guest) \ #define DO_TEST(arch, name) \
data.archName = arch; \
data.base = name; \ data.base = name; \
data.guestarch = guest; \ if (virTestRun(name "(" arch ")", testQemuCapsXML, &data) < 0) \
if (virTestRun(name, testQemuCapsXML, &data) < 0) \
ret = -1 ret = -1
#define DO_TEST(name) DO_TEST_FULL(name, VIR_ARCH_I686) DO_TEST("x86_64", "caps_1.6.0");
DO_TEST("all_1.6.0-1");
DO_TEST("nodisksnapshot_1.6.0-1");
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
} }