qemuxml2xmltest.c 8.6 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
static virQEMUDriver driver;
22

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

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

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

42
    if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
43 44
        goto fail;

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

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

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

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

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

79 80 81 82 83
    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;
84

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

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


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

108
    if ((driver.caps = testQemuCapsInit()) == NULL)
109
        return EXIT_FAILURE;
110

111
    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
112 113
        return EXIT_FAILURE;

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

122
# define DO_TEST(name) \
123
    DO_TEST_FULL(name, false, WHEN_EITHER)
124 125

# define DO_TEST_DIFFERENT(name) \
126
    DO_TEST_FULL(name, true, WHEN_EITHER)
127 128 129 130 131

    /* 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);
132 133

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

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

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

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

158 159
    DO_TEST("hyperv");

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

    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");
231
    DO_TEST("console-virtio-many");
232
    DO_TEST("channel-guestfwd");
233
    DO_TEST("channel-virtio");
234

235
    DO_TEST("hostdev-usb-address");
236
    DO_TEST("hostdev-pci-address");
237
    DO_TEST("hostdev-vfio");
238
    DO_TEST("pci-rom");
239

240
    DO_TEST("encrypted-disk");
E
Eric Blake 已提交
241
    DO_TEST_DIFFERENT("memtune");
242
    DO_TEST("blkiotune");
243
    DO_TEST("blkiotune-device");
O
Osier Yang 已提交
244
    DO_TEST("cputune");
245

246
    DO_TEST("smp");
247
    DO_TEST("lease");
248
    DO_TEST("event_idx");
249
    DO_TEST("vhost_queues");
250
    DO_TEST("virtio-lun");
251

252
    DO_TEST("usb-redir");
L
Lei Li 已提交
253
    DO_TEST("blkdeviotune");
254

255 256
    DO_TEST_FULL("seclabel-dynamic-baselabel", false, WHEN_INACTIVE);
    DO_TEST_FULL("seclabel-dynamic-override", false, WHEN_INACTIVE);
257
    DO_TEST("seclabel-static");
E
Eric Blake 已提交
258
    DO_TEST("seclabel-none");
259
    DO_TEST("numad-static-vcpu-no-numatune");
O
Osier Yang 已提交
260
    DO_TEST("disk-scsi-lun-passthrough-sgio");
261

262
    DO_TEST("disk-scsi-disk-vpd");
263
    DO_TEST("disk-source-pool");
264

O
Osier Yang 已提交
265 266
    DO_TEST("disk-drive-discard");

267 268 269
    DO_TEST("virtio-rng-random");
    DO_TEST("virtio-rng-egd");

270 271
    DO_TEST("pseries-nvram");

272 273 274 275 276
    /* 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 已提交
277
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
278
    DO_TEST_DIFFERENT("serial-target-port-auto");
279
    DO_TEST_DIFFERENT("graphics-listen-network2");
280
    DO_TEST_DIFFERENT("graphics-spice-timeout");
281
    DO_TEST_DIFFERENT("numad-auto-vcpu-no-numatune");
282 283
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-no-cpuset-and-placement");
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-cpuset");
284
    DO_TEST_DIFFERENT("usb-ich9-ehci-addr");
285

286 287
    DO_TEST_DIFFERENT("metadata");

288
    DO_TEST("tpm-passthrough");
289 290 291
    DO_TEST("pci-bridge");
    DO_TEST_DIFFERENT("pci-autoadd-addr");
    DO_TEST_DIFFERENT("pci-autoadd-idx");
292

293 294
    DO_TEST("hostdev-scsi-lsi");
    DO_TEST("hostdev-scsi-virtio-scsi");
O
Osier Yang 已提交
295
    DO_TEST("hostdev-scsi-readonly");
H
Han Cheng 已提交
296

297
    DO_TEST("disk-copy_on_read");
298
    DO_TEST("hostdev-scsi-shareable");
O
Osier Yang 已提交
299
    DO_TEST("hostdev-scsi-sgio");
300

301 302
    DO_TEST_DIFFERENT("hostdev-scsi-autogen-address");

303
    virObjectUnref(driver.caps);
304
    virObjectUnref(driver.xmlopt);
305

306
    return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
307 308
}

309 310
VIRT_TEST_MAIN(mymain)

311 312
#else

313 314 315 316 317
int
main(void)
{
    return EXIT_AM_SKIP;
}
318 319

#endif /* WITH_QEMU */