qemuxml2xmltest.c 15.2 KB
Newer Older
1
#include <config.h>
2

3
#include <stdio.h>
4 5
#include <stdlib.h>
#include <unistd.h>
6 7 8 9 10
#include <string.h>

#include <sys/types.h>
#include <fcntl.h>

11 12
#include "testutils.h"

13 14
#ifdef WITH_QEMU

15 16
# include "internal.h"
# include "qemu/qemu_conf.h"
M
Matthias Bolte 已提交
17
# include "qemu/qemu_domain.h"
18
# include "testutilsqemu.h"
19
# include "virstring.h"
20

21 22
# define VIR_FROM_THIS VIR_FROM_NONE

23
static virQEMUDriver driver;
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
enum {
    WHEN_INACTIVE = 1,
    WHEN_ACTIVE = 2,
    WHEN_BOTH = 3,
};

struct testInfo {
    char *inName;
    char *inFile;

    char *outActiveName;
    char *outActiveFile;

    char *outInactiveName;
    char *outInactiveFile;
};

42
static int
43 44 45 46 47
testXML2XMLHelper(const char *inxml,
                  const char *inXmlData,
                  const char *outxml,
                  const char *outXmlData,
                  bool live)
48
{
49 50
    char *actual = NULL;
    int ret = -1;
51
    virDomainDefPtr def = NULL;
52 53 54 55
    unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE;
    unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
    if (!live)
        format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
56

57
    if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt,
58
                                        QEMU_EXPECTED_VIRT_TYPES, parse_flags)))
59 60
        goto fail;

61 62 63 64 65
    if (!virDomainDefCheckABIStability(def, def)) {
        fprintf(stderr, "ABI stability check failed on %s", inxml);
        goto fail;
    }

66
    if (!(actual = virDomainDefFormat(def, format_flags)))
67 68
        goto fail;

69
    if (STRNEQ(outXmlData, actual)) {
70
        virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml);
71 72 73 74
        goto fail;
    }

    ret = 0;
75

76
 fail:
77
    VIR_FREE(actual);
78
    virDomainDefFree(def);
79 80 81
    return ret;
}

82

83 84 85 86 87 88 89 90 91 92 93 94
static int
testXML2XMLActive(const void *opaque)
{
    const struct testInfo *info = opaque;

    return testXML2XMLHelper(info->inName,
                             info->inFile,
                             info->outActiveName,
                             info->outActiveFile,
                             true);
}

95

96
static int
97
testXML2XMLInactive(const void *opaque)
98
{
99 100 101 102 103 104 105 106
    const struct testInfo *info = opaque;

    return testXML2XMLHelper(info->inName,
                             info->inFile,
                             info->outInactiveName,
                             info->outInactiveFile,
                             false);
}
107

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157

static void
testInfoFree(struct testInfo *info)
{
    VIR_FREE(info->inName);
    VIR_FREE(info->inFile);

    VIR_FREE(info->outActiveName);
    VIR_FREE(info->outActiveFile);

    VIR_FREE(info->outInactiveName);
    VIR_FREE(info->outInactiveFile);
}


static int
testInfoSet(struct testInfo *info,
            const char *name,
            bool different,
            int when)
{
    if (virAsprintf(&info->inName, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
                    abs_srcdir, name) < 0)
        goto error;

    if (virtTestLoadFile(info->inName, &info->inFile) < 0)
        goto error;

    if (when & WHEN_INACTIVE) {
        if (different) {
            if (virAsprintf(&info->outInactiveName,
                           "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s-inactive.xml",
                           abs_srcdir, name) < 0)
                goto error;

            if (!virFileExists(info->outInactiveName)) {
                VIR_FREE(info->outInactiveName);

                if (virAsprintf(&info->outInactiveName,
                                "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
                                abs_srcdir, name) < 0)
                    goto error;
            }
        } else {
            if (VIR_STRDUP(info->outInactiveName, info->inName) < 0)
                goto error;
        }

        if (virtTestLoadFile(info->outInactiveName, &info->outInactiveFile) < 0)
            goto error;
158
    }
159

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
    if (when & WHEN_ACTIVE) {
        if (different) {
            if (virAsprintf(&info->outActiveName,
                           "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s-active.xml",
                           abs_srcdir, name) < 0)
                goto error;

            if (!virFileExists(info->outActiveName)) {
                VIR_FREE(info->outActiveName);

                if (virAsprintf(&info->outActiveName,
                                "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
                                abs_srcdir, name) < 0)
                    goto error;
            }
        } else {
            if (VIR_STRDUP(info->outActiveName, info->inName) < 0)
                goto error;
        }

        if (virtTestLoadFile(info->outActiveName, &info->outActiveFile) < 0)
            goto error;
182
    }
183

184
    return 0;
185

186 187 188
 error:
    testInfoFree(info);
    return -1;
189 190 191
}


192
static int
E
Eric Blake 已提交
193
mymain(void)
194 195
{
    int ret = 0;
196
    struct testInfo info;
197

198
    if ((driver.caps = testQemuCapsInit()) == NULL)
199
        return EXIT_FAILURE;
200

201
    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
202 203
        return EXIT_FAILURE;

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
# define DO_TEST_FULL(name, is_different, when)                                \
    do {                                                                       \
        if (testInfoSet(&info, name, is_different, when) < 0) {                \
            fprintf(stderr, "Failed to generate test data for '%s'", name);    \
            return -1;                                                         \
        }                                                                      \
                                                                               \
        if (info.outInactiveName) {                                            \
            if (virtTestRun("QEMU XML-2-XML-inactive " name,                   \
                            testXML2XMLInactive, &info) < 0)                   \
                ret = -1;                                                      \
        }                                                                      \
                                                                               \
        if (info.outActiveName) {                                              \
            if (virtTestRun("QEMU XML-2-XML-active " name,                     \
                            testXML2XMLActive, &info) < 0)                     \
                ret = -1;                                                      \
        }                                                                      \
        testInfoFree(&info);                                                   \
223 224
    } while (0)

225
# define DO_TEST(name) \
226
    DO_TEST_FULL(name, false, WHEN_BOTH)
227 228

# define DO_TEST_DIFFERENT(name) \
229
    DO_TEST_FULL(name, true, WHEN_BOTH)
230 231 232 233 234

    /* Unset or set all envvars here that are copied in qemudBuildCommandLine
     * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
     * values for these envvars */
    setenv("PATH", "/bin", 1);
235 236

    DO_TEST("minimal");
237 238
    DO_TEST("machine-core-on");
    DO_TEST("machine-core-off");
239 240 241
    DO_TEST("boot-cdrom");
    DO_TEST("boot-network");
    DO_TEST("boot-floppy");
242
    DO_TEST("boot-multi");
243
    DO_TEST("boot-menu-enable-with-timeout");
244
    DO_TEST("boot-menu-disable");
245
    DO_TEST_DIFFERENT("boot-menu-disable-with-timeout");
246
    DO_TEST("boot-order");
247 248 249 250

    DO_TEST("reboot-timeout-enabled");
    DO_TEST("reboot-timeout-disabled");

251 252
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
253 254
    DO_TEST("cpu-kvmclock");
    DO_TEST("cpu-host-kvmclock");
255
    DO_TEST("cpu-host-passthrough-features");
256
    DO_TEST("cpu-host-model-features");
257
    DO_TEST("clock-catchup");
258
    DO_TEST("kvmclock");
259
    DO_TEST("clock-timer-hyperv-rtc");
260 261 262 263 264

    DO_TEST("cpu-eoi-disabled");
    DO_TEST("cpu-eoi-enabled");
    DO_TEST("eoi-disabled");
    DO_TEST("eoi-enabled");
265 266
    DO_TEST("pv-spinlock-disabled");
    DO_TEST("pv-spinlock-enabled");
267

268
    DO_TEST("hyperv");
269
    DO_TEST("hyperv-off");
270

271 272 273
    DO_TEST("kvm-features");
    DO_TEST("kvm-features-off");

274 275 276
    DO_TEST_DIFFERENT("pmu-feature");
    DO_TEST("pmu-feature-off");

277
    DO_TEST("hugepages");
278
    DO_TEST("hugepages-pages");
279 280
    DO_TEST("hugepages-pages2");
    DO_TEST("hugepages-pages3");
281
    DO_TEST("hugepages-shared");
282
    DO_TEST("nosharepages");
E
Eric Blake 已提交
283
    DO_TEST("disk-aio");
284 285 286
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
287
    DO_TEST("disk-xenvbd");
288
    DO_TEST("disk-usb");
289
    DO_TEST("disk-virtio");
290 291
    DO_TEST("floppy-drive-fat");
    DO_TEST("disk-drive-fat");
292
    DO_TEST("disk-drive-fmt-qcow");
293 294 295
    DO_TEST("disk-drive-cache-v1-wt");
    DO_TEST("disk-drive-cache-v1-wb");
    DO_TEST("disk-drive-cache-v1-none");
296
    DO_TEST("disk-drive-copy-on-read");
297
    DO_TEST("disk-drive-network-nbd");
P
Paolo Bonzini 已提交
298
    DO_TEST("disk-drive-network-nbd-export");
P
Paolo Bonzini 已提交
299 300
    DO_TEST("disk-drive-network-nbd-ipv6");
    DO_TEST("disk-drive-network-nbd-ipv6-export");
301
    DO_TEST("disk-drive-network-nbd-unix");
302
    DO_TEST("disk-drive-network-iscsi");
303
    DO_TEST("disk-drive-network-iscsi-auth");
304
    DO_TEST("disk-scsi-device");
305 306
    DO_TEST("disk-scsi-vscsi");
    DO_TEST("disk-scsi-virtio-scsi");
307
    DO_TEST("disk-virtio-scsi-num_queues");
308 309
    DO_TEST("disk-virtio-scsi-cmd_per_lun");
    DO_TEST("disk-virtio-scsi-max_sectors");
310
    DO_TEST("disk-scsi-megasas");
E
Eric Blake 已提交
311
    DO_TEST_DIFFERENT("disk-mirror-old");
312 313
    DO_TEST_FULL("disk-mirror", false, WHEN_ACTIVE);
    DO_TEST_FULL("disk-mirror", true, WHEN_INACTIVE);
E
Eric Blake 已提交
314
    DO_TEST_FULL("disk-active-commit", false, WHEN_ACTIVE);
315
    DO_TEST("graphics-listen-network");
316
    DO_TEST("graphics-vnc");
317
    DO_TEST("graphics-vnc-websocket");
318 319
    DO_TEST("graphics-vnc-sasl");
    DO_TEST("graphics-vnc-tls");
320
    DO_TEST("graphics-sdl");
321
    DO_TEST("graphics-sdl-fullscreen");
322
    DO_TEST("graphics-spice");
323
    DO_TEST("graphics-spice-compression");
324
    DO_TEST("graphics-spice-qxl-vga");
325 326 327
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
    DO_TEST("misc-acpi");
328 329 330
    DO_TEST("misc-disable-s3");
    DO_TEST("misc-disable-suspends");
    DO_TEST("misc-enable-s4");
331
    DO_TEST("misc-no-reboot");
M
Michele Paolino 已提交
332
    DO_TEST("net-vhostuser");
333
    DO_TEST("net-user");
334
    DO_TEST("net-virtio");
335
    DO_TEST("net-virtio-device");
336
    DO_TEST("net-virtio-disable-offloads");
337 338
    DO_TEST("net-eth");
    DO_TEST("net-eth-ifname");
339
    DO_TEST("net-virtio-network-portgroup");
340
    DO_TEST("net-hostdev");
341
    DO_TEST("net-hostdev-vfio");
342
    DO_TEST("net-midonet");
343
    DO_TEST("net-openvswitch");
344
    DO_TEST("sound");
345
    DO_TEST("sound-device");
346
    DO_TEST("net-bandwidth");
347 348 349 350 351 352 353 354 355 356

    DO_TEST("serial-vc");
    DO_TEST("serial-pty");
    DO_TEST("serial-dev");
    DO_TEST("serial-file");
    DO_TEST("serial-unix");
    DO_TEST("serial-tcp");
    DO_TEST("serial-udp");
    DO_TEST("serial-tcp-telnet");
    DO_TEST("serial-many");
357 358
    DO_TEST("serial-spiceport");
    DO_TEST("serial-spiceport-nospice");
359 360
    DO_TEST("parallel-tcp");
    DO_TEST("console-compat");
361
    DO_TEST("console-virtio-many");
362
    DO_TEST("channel-guestfwd");
363
    DO_TEST("channel-virtio");
364
    DO_TEST_DIFFERENT("channel-virtio-state");
365

366
    DO_TEST("hostdev-usb-address");
367
    DO_TEST("hostdev-pci-address");
368
    DO_TEST("hostdev-vfio");
369
    DO_TEST("pci-rom");
370

371
    DO_TEST("encrypted-disk");
E
Eric Blake 已提交
372
    DO_TEST_DIFFERENT("memtune");
373
    DO_TEST_DIFFERENT("memtune-unlimited");
374
    DO_TEST("blkiotune");
375
    DO_TEST("blkiotune-device");
O
Osier Yang 已提交
376
    DO_TEST("cputune");
377
    DO_TEST("cputune-zero-shares");
378
    DO_TEST_DIFFERENT("cputune-iothreadsched");
379 380
    DO_TEST("cputune-numatune");
    DO_TEST("vcpu-placement-static");
381

382
    DO_TEST("smp");
J
John Ferlan 已提交
383
    DO_TEST("iothreads");
E
Eric Blake 已提交
384
    DO_TEST_DIFFERENT("cputune-iothreads");
385
    DO_TEST("iothreads-disk");
386
    DO_TEST("iothreads-disk-virtio-ccw");
387
    DO_TEST("lease");
388
    DO_TEST("event_idx");
389
    DO_TEST("vhost_queues");
390
    DO_TEST("interface-driver");
391
    DO_TEST("interface-server");
392
    DO_TEST("virtio-lun");
393

394
    DO_TEST("usb-redir");
L
Lei Li 已提交
395
    DO_TEST("blkdeviotune");
396

397 398
    DO_TEST_FULL("seclabel-dynamic-baselabel", false, WHEN_INACTIVE);
    DO_TEST_FULL("seclabel-dynamic-override", false, WHEN_INACTIVE);
399
    DO_TEST_FULL("seclabel-dynamic-labelskip", true, WHEN_INACTIVE);
400
    DO_TEST_FULL("seclabel-dynamic-relabel", true, WHEN_INACTIVE);
401
    DO_TEST("seclabel-static");
402
    DO_TEST_FULL("seclabel-static-labelskip", false, WHEN_ACTIVE);
403
    DO_TEST_DIFFERENT("seclabel-none");
404
    DO_TEST("seclabel-dac-none");
405
    DO_TEST("seclabel-dynamic-none");
406
    DO_TEST("seclabel-device-multiple");
407
    DO_TEST_FULL("seclabel-dynamic-none-relabel", true, WHEN_INACTIVE);
408
    DO_TEST("numad-static-vcpu-no-numatune");
O
Osier Yang 已提交
409
    DO_TEST("disk-scsi-lun-passthrough-sgio");
410

411
    DO_TEST("disk-scsi-disk-vpd");
412
    DO_TEST_DIFFERENT("disk-source-pool");
413
    DO_TEST("disk-source-pool-mode");
414

415
    DO_TEST_DIFFERENT("disk-drive-discard");
O
Osier Yang 已提交
416

417 418 419
    DO_TEST("virtio-rng-random");
    DO_TEST("virtio-rng-egd");

420 421
    DO_TEST("pseries-nvram");

422 423
    /* These tests generate different XML */
    DO_TEST_DIFFERENT("balloon-device-auto");
424
    DO_TEST_DIFFERENT("balloon-device-period");
425 426 427
    DO_TEST_DIFFERENT("channel-virtio-auto");
    DO_TEST_DIFFERENT("console-compat-auto");
    DO_TEST_DIFFERENT("disk-scsi-device-auto");
C
Cole Robinson 已提交
428
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
429
    DO_TEST_DIFFERENT("serial-target-port-auto");
430
    DO_TEST_DIFFERENT("graphics-listen-network2");
431
    DO_TEST_DIFFERENT("graphics-spice-timeout");
432
    DO_TEST_DIFFERENT("numad-auto-vcpu-no-numatune");
433 434
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-no-cpuset-and-placement");
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-cpuset");
435
    DO_TEST_DIFFERENT("usb-ich9-ehci-addr");
436

437
    DO_TEST_DIFFERENT("metadata");
438
    DO_TEST_DIFFERENT("metadata-duplicate");
439

440
    DO_TEST("tpm-passthrough");
441
    DO_TEST("pci-bridge");
442
    DO_TEST_DIFFERENT("pci-bridge-many-disks");
443 444
    DO_TEST_DIFFERENT("pci-autoadd-addr");
    DO_TEST_DIFFERENT("pci-autoadd-idx");
445
    DO_TEST_DIFFERENT("pcie-root");
446
    DO_TEST_DIFFERENT("q35");
447

448 449
    DO_TEST("hostdev-scsi-lsi");
    DO_TEST("hostdev-scsi-virtio-scsi");
O
Osier Yang 已提交
450
    DO_TEST("hostdev-scsi-readonly");
H
Han Cheng 已提交
451

452
    DO_TEST("disk-copy_on_read");
453
    DO_TEST("hostdev-scsi-shareable");
O
Osier Yang 已提交
454
    DO_TEST("hostdev-scsi-sgio");
455
    DO_TEST("hostdev-scsi-rawio");
456

457 458
    DO_TEST_DIFFERENT("hostdev-scsi-autogen-address");

J
John Ferlan 已提交
459 460 461 462 463
    DO_TEST("hostdev-scsi-lsi-iscsi");
    DO_TEST("hostdev-scsi-lsi-iscsi-auth");
    DO_TEST("hostdev-scsi-virtio-iscsi");
    DO_TEST("hostdev-scsi-virtio-iscsi-auth");

464 465
    DO_TEST_DIFFERENT("s390-defaultconsole");

466 467 468 469 470
    DO_TEST("pcihole64");
    DO_TEST_DIFFERENT("pcihole64-gib");
    DO_TEST("pcihole64-none");
    DO_TEST("pcihole64-q35");

H
Hu Tao 已提交
471
    DO_TEST("panic");
472
    DO_TEST("panic-no-address");
H
Hu Tao 已提交
473

474 475
    DO_TEST_DIFFERENT("disk-backing-chains");

J
Ján Tomko 已提交
476 477
    DO_TEST("chardev-label");

478 479
    DO_TEST_DIFFERENT("cpu-numa1");
    DO_TEST_DIFFERENT("cpu-numa2");
480
    DO_TEST_DIFFERENT("cpu-numa-no-memory-element");
481
    DO_TEST("cpu-numa-disjoint");
482
    DO_TEST("cpu-numa-memshared");
483

484
    DO_TEST_DIFFERENT("numatune-auto-prefer");
485 486
    DO_TEST_DIFFERENT("numatune-memnode");
    DO_TEST("numatune-memnode-no-memory");
487

488
    DO_TEST("bios-nvram");
489
    DO_TEST_DIFFERENT("bios-nvram-os-interleave");
490

491
    DO_TEST("tap-vhost");
492
    DO_TEST_DIFFERENT("tap-vhost-incorrect");
493
    DO_TEST("shmem");
494
    DO_TEST("smbios");
495
    DO_TEST("aarch64-aavmf-virtio-mmio");
496

497 498
    DO_TEST("memory-hotplug");
    DO_TEST("memory-hotplug-nonuma");
499
    DO_TEST("memory-hotplug-dimm");
500

501
    virObjectUnref(driver.caps);
502
    virObjectUnref(driver.xmlopt);
503

504
    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
505 506
}

507 508
VIRT_TEST_MAIN(mymain)

509 510
#else

511 512 513 514 515
int
main(void)
{
    return EXIT_AM_SKIP;
}
516 517

#endif /* WITH_QEMU */