qemuxml2xmltest.c 8.0 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
#ifdef WITH_QEMU

13 14 15
# include "internal.h"
# include "testutils.h"
# include "qemu/qemu_conf.h"
M
Matthias Bolte 已提交
16
# include "qemu/qemu_domain.h"
17
# include "testutilsqemu.h"
18

19
static virQEMUDriver driver;
20

21
static int
E
Eric Blake 已提交
22
testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
23 24 25
{
    char *inXmlData = NULL;
    char *outXmlData = NULL;
26 27
    char *actual = NULL;
    int ret = -1;
28
    virDomainDefPtr def = NULL;
29

30
    if (virtTestLoadFile(inxml, &inXmlData) < 0)
31
        goto fail;
32
    if (virtTestLoadFile(outxml, &outXmlData) < 0)
33 34
        goto fail;

35
    if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt,
M
Matthias Bolte 已提交
36
                                        QEMU_EXPECTED_VIRT_TYPES,
E
Eric Blake 已提交
37
                                        live ? 0 : VIR_DOMAIN_XML_INACTIVE)))
38 39
        goto fail;

40
    if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
41 42
        goto fail;

43 44
    if (STRNEQ(outXmlData, actual)) {
        virtTestDifference(stderr, outXmlData, actual);
45 46 47 48 49
        goto fail;
    }

    ret = 0;
 fail:
50 51 52
    VIR_FREE(inXmlData);
    VIR_FREE(outXmlData);
    VIR_FREE(actual);
53
    virDomainDefFree(def);
54 55 56
    return ret;
}

57 58 59 60 61 62
enum {
    WHEN_INACTIVE = 1,
    WHEN_ACTIVE = 2,
    WHEN_EITHER = 3,
};

63 64
struct testInfo {
    const char *name;
65 66
    bool different;
    int when;
67 68
};

69 70 71
static int
testCompareXMLToXMLHelper(const void *data)
{
72
    const struct testInfo *info = data;
73 74 75
    char *xml_in = NULL;
    char *xml_out = NULL;
    int ret = -1;
76

77 78 79 80 81
    if (virAsprintf(&xml_in, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
                    abs_srcdir, info->name) < 0 ||
        virAsprintf(&xml_out, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
                    abs_srcdir, info->name) < 0)
        goto cleanup;
82

83 84 85 86
    if (info->when & WHEN_INACTIVE) {
        ret = testCompareXMLToXMLFiles(xml_in,
                                       info->different ? xml_out : xml_in,
                                       false);
E
Eric Blake 已提交
87
    }
88 89 90 91
    if (info->when & WHEN_ACTIVE) {
        ret = testCompareXMLToXMLFiles(xml_in,
                                       info->different ? xml_out : xml_in,
                                       true);
92 93
    }

94
cleanup:
95 96
    VIR_FREE(xml_in);
    VIR_FREE(xml_out);
97
    return ret;
98 99 100
}


101
static int
E
Eric Blake 已提交
102
mymain(void)
103 104
{
    int ret = 0;
105

106
    if ((driver.caps = testQemuCapsInit()) == NULL)
107
        return EXIT_FAILURE;
108

109
    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
110 111
        return EXIT_FAILURE;

112
# define DO_TEST_FULL(name, is_different, when)                         \
113
    do {                                                                \
114
        const struct testInfo info = {name, is_different, when};        \
115 116 117 118 119
        if (virtTestRun("QEMU XML-2-XML " name,                         \
                        1, testCompareXMLToXMLHelper, &info) < 0)       \
            ret = -1;                                                   \
    } while (0)

120
# define DO_TEST(name) \
121
    DO_TEST_FULL(name, false, WHEN_EITHER)
122 123

# define DO_TEST_DIFFERENT(name) \
124
    DO_TEST_FULL(name, true, WHEN_EITHER)
125 126 127 128 129

    /* 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);
130 131

    DO_TEST("minimal");
132 133
    DO_TEST("machine-core-on");
    DO_TEST("machine-core-off");
134 135 136
    DO_TEST("boot-cdrom");
    DO_TEST("boot-network");
    DO_TEST("boot-floppy");
137 138
    DO_TEST("boot-multi");
    DO_TEST("boot-menu-disable");
139
    DO_TEST("boot-order");
D
Daniel P. Berrange 已提交
140
    DO_TEST("bootloader");
141 142 143 144

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

145 146
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
147 148 149
    DO_TEST("cpu-kvmclock");
    DO_TEST("cpu-host-kvmclock");
    DO_TEST("kvmclock");
150 151 152 153 154 155

    DO_TEST("cpu-eoi-disabled");
    DO_TEST("cpu-eoi-enabled");
    DO_TEST("eoi-disabled");
    DO_TEST("eoi-enabled");

156 157
    DO_TEST("hyperv");

158
    DO_TEST("hugepages");
E
Eric Blake 已提交
159
    DO_TEST("disk-aio");
160 161 162
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
163
    DO_TEST("disk-xenvbd");
164
    DO_TEST("disk-usb");
165
    DO_TEST("disk-virtio");
166 167
    DO_TEST("floppy-drive-fat");
    DO_TEST("disk-drive-fat");
168
    DO_TEST("disk-drive-fmt-qcow");
169 170 171
    DO_TEST("disk-drive-cache-v1-wt");
    DO_TEST("disk-drive-cache-v1-wb");
    DO_TEST("disk-drive-cache-v1-none");
172
    DO_TEST("disk-drive-network-nbd");
P
Paolo Bonzini 已提交
173
    DO_TEST("disk-drive-network-nbd-export");
P
Paolo Bonzini 已提交
174 175
    DO_TEST("disk-drive-network-nbd-ipv6");
    DO_TEST("disk-drive-network-nbd-ipv6-export");
176
    DO_TEST("disk-drive-network-nbd-unix");
177
    DO_TEST("disk-drive-network-iscsi");
178
    DO_TEST("disk-drive-network-iscsi-auth");
179
    DO_TEST("disk-scsi-device");
180 181
    DO_TEST("disk-scsi-vscsi");
    DO_TEST("disk-scsi-virtio-scsi");
182
    DO_TEST("disk-virtio-scsi-num_queues");
183
    DO_TEST("disk-scsi-megasas");
184 185
    DO_TEST_FULL("disk-mirror", false, WHEN_ACTIVE);
    DO_TEST_FULL("disk-mirror", true, WHEN_INACTIVE);
186
    DO_TEST("graphics-listen-network");
187
    DO_TEST("graphics-vnc");
188 189
    DO_TEST("graphics-vnc-sasl");
    DO_TEST("graphics-vnc-tls");
190
    DO_TEST("graphics-sdl");
191
    DO_TEST("graphics-sdl-fullscreen");
192
    DO_TEST("graphics-spice");
193
    DO_TEST("graphics-spice-compression");
194
    DO_TEST("graphics-spice-qxl-vga");
195 196
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
197
    DO_TEST("input-xen");
198
    DO_TEST("misc-acpi");
199 200 201
    DO_TEST("misc-disable-s3");
    DO_TEST("misc-disable-suspends");
    DO_TEST("misc-enable-s4");
202 203
    DO_TEST("misc-no-reboot");
    DO_TEST("net-user");
204
    DO_TEST("net-virtio");
205
    DO_TEST("net-virtio-device");
206 207
    DO_TEST("net-eth");
    DO_TEST("net-eth-ifname");
208
    DO_TEST("net-virtio-network-portgroup");
209
    DO_TEST("net-hostdev");
210
    DO_TEST("net-openvswitch");
211
    DO_TEST("sound");
212
    DO_TEST("sound-device");
213
    DO_TEST("net-bandwidth");
214 215 216 217 218 219 220 221 222 223 224 225

    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");
    DO_TEST("parallel-tcp");
    DO_TEST("console-compat");
226
    DO_TEST("console-virtio-many");
227
    DO_TEST("channel-guestfwd");
228
    DO_TEST("channel-virtio");
229

230
    DO_TEST("hostdev-usb-address");
231
    DO_TEST("hostdev-pci-address");
232
    DO_TEST("pci-rom");
233

234
    DO_TEST("encrypted-disk");
E
Eric Blake 已提交
235
    DO_TEST_DIFFERENT("memtune");
236
    DO_TEST("blkiotune");
237
    DO_TEST("blkiotune-device");
O
Osier Yang 已提交
238
    DO_TEST("cputune");
239

240
    DO_TEST("smp");
241
    DO_TEST("lease");
242
    DO_TEST("event_idx");
243
    DO_TEST("virtio-lun");
244

245
    DO_TEST("usb-redir");
L
Lei Li 已提交
246
    DO_TEST("blkdeviotune");
247

248 249
    DO_TEST_FULL("seclabel-dynamic-baselabel", false, WHEN_INACTIVE);
    DO_TEST_FULL("seclabel-dynamic-override", false, WHEN_INACTIVE);
250
    DO_TEST("seclabel-static");
E
Eric Blake 已提交
251
    DO_TEST("seclabel-none");
252
    DO_TEST("numad-static-vcpu-no-numatune");
O
Osier Yang 已提交
253
    DO_TEST("disk-scsi-lun-passthrough-sgio");
254

255
    DO_TEST("disk-scsi-disk-vpd");
256
    DO_TEST("disk-source-pool");
257

258 259 260
    DO_TEST("virtio-rng-random");
    DO_TEST("virtio-rng-egd");

261 262 263 264 265
    /* These tests generate different XML */
    DO_TEST_DIFFERENT("balloon-device-auto");
    DO_TEST_DIFFERENT("channel-virtio-auto");
    DO_TEST_DIFFERENT("console-compat-auto");
    DO_TEST_DIFFERENT("disk-scsi-device-auto");
C
Cole Robinson 已提交
266
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
267
    DO_TEST_DIFFERENT("serial-target-port-auto");
268
    DO_TEST_DIFFERENT("graphics-listen-network2");
269
    DO_TEST_DIFFERENT("graphics-spice-timeout");
270
    DO_TEST_DIFFERENT("numad-auto-vcpu-no-numatune");
271 272
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-no-cpuset-and-placement");
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-cpuset");
273
    DO_TEST_DIFFERENT("usb-ich9-ehci-addr");
274

275 276
    DO_TEST_DIFFERENT("metadata");

277 278
    DO_TEST("tpm-passthrough");

279
    virObjectUnref(driver.caps);
280
    virObjectUnref(driver.xmlopt);
281

282
    return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
283 284
}

285 286
VIRT_TEST_MAIN(mymain)

287
#else
E
Eric Blake 已提交
288
# include "testutils.h"
289

290 291 292 293 294
int
main(void)
{
    return EXIT_AM_SKIP;
}
295 296

#endif /* WITH_QEMU */