qemuxml2xmltest.c 5.9 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 struct qemud_driver driver;
20

21 22 23 24 25
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
    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(driver.caps, inXmlData,
M
Matthias Bolte 已提交
36 37
                                        QEMU_EXPECTED_VIRT_TYPES,
                                        VIR_DOMAIN_XML_INACTIVE)))
38 39
        goto fail;

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

43 44 45

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

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

58 59 60 61 62
struct testInfo {
    const char *name;
    int different;
};

63 64 65
static int
testCompareXMLToXMLHelper(const void *data)
{
66
    const struct testInfo *info = data;
67 68 69
    char *xml_in = NULL;
    char *xml_out = NULL;
    int ret = -1;
70

71 72 73 74 75
    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;
76 77 78 79 80 81 82

    if (info->different) {
        ret = testCompareXMLToXMLFiles(xml_in, xml_out);
    } else {
        ret = testCompareXMLToXMLFiles(xml_in, xml_in);
    }

83 84 85
cleanup:
    free(xml_in);
    free(xml_out);
86
    return ret;
87 88 89
}


90
static int
E
Eric Blake 已提交
91
mymain(void)
92 93
{
    int ret = 0;
94

95 96
    if ((driver.caps = testQemuCapsInit()) == NULL)
        return (EXIT_FAILURE);
97

98 99 100 101 102 103 104 105
# define DO_TEST_FULL(name, is_different)                               \
    do {                                                                \
        const struct testInfo info = {name, is_different};              \
        if (virtTestRun("QEMU XML-2-XML " name,                         \
                        1, testCompareXMLToXMLHelper, &info) < 0)       \
            ret = -1;                                                   \
    } while (0)

106
# define DO_TEST(name) \
107 108 109 110 111 112 113 114 115
    DO_TEST_FULL(name, 0)

# define DO_TEST_DIFFERENT(name) \
    DO_TEST_FULL(name, 1)

    /* 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);
116 117 118 119 120

    DO_TEST("minimal");
    DO_TEST("boot-cdrom");
    DO_TEST("boot-network");
    DO_TEST("boot-floppy");
121 122
    DO_TEST("boot-multi");
    DO_TEST("boot-menu-disable");
123
    DO_TEST("boot-order");
D
Daniel P. Berrange 已提交
124
    DO_TEST("bootloader");
125 126
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
127 128 129
    DO_TEST("cpu-kvmclock");
    DO_TEST("cpu-host-kvmclock");
    DO_TEST("kvmclock");
130
    DO_TEST("hugepages");
E
Eric Blake 已提交
131
    DO_TEST("disk-aio");
132 133 134
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
135
    DO_TEST("disk-xenvbd");
136
    DO_TEST("disk-usb");
137
    DO_TEST("disk-virtio");
138 139
    DO_TEST("floppy-drive-fat");
    DO_TEST("disk-drive-fat");
140
    DO_TEST("disk-drive-fmt-qcow");
141 142 143
    DO_TEST("disk-drive-cache-v1-wt");
    DO_TEST("disk-drive-cache-v1-wb");
    DO_TEST("disk-drive-cache-v1-none");
144
    DO_TEST("disk-scsi-device");
145
    DO_TEST("disk-scsi-vscsi");
146
    DO_TEST("disk-scsi-virtio-scsi");
147
    DO_TEST("graphics-listen-network");
148
    DO_TEST("graphics-vnc");
149 150
    DO_TEST("graphics-vnc-sasl");
    DO_TEST("graphics-vnc-tls");
151
    DO_TEST("graphics-sdl");
152
    DO_TEST("graphics-sdl-fullscreen");
153
    DO_TEST("graphics-spice");
154
    DO_TEST("graphics-spice-compression");
155
    DO_TEST("graphics-spice-qxl-vga");
156 157
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
158
    DO_TEST("input-xen");
159 160 161
    DO_TEST("misc-acpi");
    DO_TEST("misc-no-reboot");
    DO_TEST("net-user");
162
    DO_TEST("net-virtio");
163
    DO_TEST("net-virtio-device");
164 165
    DO_TEST("net-eth");
    DO_TEST("net-eth-ifname");
166
    DO_TEST("net-virtio-network-portgroup");
167
    DO_TEST("sound");
168
    DO_TEST("net-bandwidth");
169 170 171 172 173 174 175 176 177 178 179 180

    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");
181
    DO_TEST("console-virtio-many");
182
    DO_TEST("channel-guestfwd");
183
    DO_TEST("channel-virtio");
184

185
    DO_TEST("hostdev-usb-address");
186
    DO_TEST("hostdev-pci-address");
187
    DO_TEST("pci-rom");
188

189
    DO_TEST("encrypted-disk");
190
    DO_TEST("memtune");
191
    DO_TEST("blkiotune");
192
    DO_TEST("blkiotune-device");
O
Osier Yang 已提交
193
    DO_TEST("cputune");
194

195
    DO_TEST("smp");
196
    DO_TEST("lease");
197
    DO_TEST("event_idx");
198
    DO_TEST("virtio-lun");
199

200
    DO_TEST("usb-redir");
L
Lei Li 已提交
201
    DO_TEST("blkdeviotune");
202

203
    DO_TEST("seclabel-dynamic-baselabel");
204
    DO_TEST("seclabel-dynamic-override");
205 206
    DO_TEST("seclabel-static");

207 208 209 210 211
    /* 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 已提交
212
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
213
    DO_TEST_DIFFERENT("serial-target-port-auto");
214
    DO_TEST_DIFFERENT("graphics-listen-network2");
215
    DO_TEST_DIFFERENT("graphics-spice-timeout");
216

217 218
    DO_TEST_DIFFERENT("metadata");

219
    virCapabilitiesFree(driver.caps);
220

221
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
222 223
}

224 225
VIRT_TEST_MAIN(mymain)

226
#else
E
Eric Blake 已提交
227
# include "testutils.h"
228

229 230 231 232 233
int
main(void)
{
    return EXIT_AM_SKIP;
}
234 235

#endif /* WITH_QEMU */