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
#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

20
static virQEMUDriver driver;
21

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

157 158
    DO_TEST("hyperv");

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

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

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

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

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

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

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

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

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

262 263
    DO_TEST("pseries-nvram");

264 265 266 267 268
    /* 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 已提交
269
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
270
    DO_TEST_DIFFERENT("serial-target-port-auto");
271
    DO_TEST_DIFFERENT("graphics-listen-network2");
272
    DO_TEST_DIFFERENT("graphics-spice-timeout");
273
    DO_TEST_DIFFERENT("numad-auto-vcpu-no-numatune");
274 275
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-no-cpuset-and-placement");
    DO_TEST_DIFFERENT("numad-auto-memory-vcpu-cpuset");
276
    DO_TEST_DIFFERENT("usb-ich9-ehci-addr");
277

278 279
    DO_TEST_DIFFERENT("metadata");

280 281
    DO_TEST("tpm-passthrough");

282
    virObjectUnref(driver.caps);
283
    virObjectUnref(driver.xmlopt);
284

285
    return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
286 287
}

288 289
VIRT_TEST_MAIN(mymain)

290 291
#else

292 293 294 295 296
int
main(void)
{
    return EXIT_AM_SKIP;
}
297 298

#endif /* WITH_QEMU */