qemuxml2xmltest.c 6.3 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
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(driver.caps, inXmlData,
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 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
struct testInfo {
    const char *name;
    int different;
E
Eric Blake 已提交
61
    bool inactive_only;
62 63
};

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

72 73 74 75 76
    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;
77 78

    if (info->different) {
E
Eric Blake 已提交
79
        ret = testCompareXMLToXMLFiles(xml_in, xml_out, false);
80
    } else {
E
Eric Blake 已提交
81 82 83 84 85 86 87 88
        ret = testCompareXMLToXMLFiles(xml_in, xml_in, false);
    }
    if (!info->inactive_only) {
        if (info->different) {
            ret = testCompareXMLToXMLFiles(xml_in, xml_out, true);
        } else {
            ret = testCompareXMLToXMLFiles(xml_in, xml_in, true);
        }
89 90
    }

91
cleanup:
92 93
    VIR_FREE(xml_in);
    VIR_FREE(xml_out);
94
    return ret;
95 96 97
}


98
static int
E
Eric Blake 已提交
99
mymain(void)
100 101
{
    int ret = 0;
102

103 104
    if ((driver.caps = testQemuCapsInit()) == NULL)
        return (EXIT_FAILURE);
105

E
Eric Blake 已提交
106
# define DO_TEST_FULL(name, is_different, inactive)                     \
107
    do {                                                                \
E
Eric Blake 已提交
108
        const struct testInfo info = {name, is_different, inactive};    \
109 110 111 112 113
        if (virtTestRun("QEMU XML-2-XML " name,                         \
                        1, testCompareXMLToXMLHelper, &info) < 0)       \
            ret = -1;                                                   \
    } while (0)

114
# define DO_TEST(name) \
E
Eric Blake 已提交
115
    DO_TEST_FULL(name, 0, false)
116 117

# define DO_TEST_DIFFERENT(name) \
E
Eric Blake 已提交
118
    DO_TEST_FULL(name, 1, false)
119 120 121 122 123

    /* 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);
124 125 126 127 128

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

    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");
188
    DO_TEST("console-virtio-many");
189
    DO_TEST("channel-guestfwd");
190
    DO_TEST("channel-virtio");
191

192
    DO_TEST("hostdev-usb-address");
193
    DO_TEST("hostdev-pci-address");
194
    DO_TEST("pci-rom");
195

196
    DO_TEST("encrypted-disk");
197
    DO_TEST("memtune");
198
    DO_TEST("blkiotune");
199
    DO_TEST("blkiotune-device");
O
Osier Yang 已提交
200
    DO_TEST("cputune");
201

202
    DO_TEST("smp");
203
    DO_TEST("lease");
204
    DO_TEST("event_idx");
205
    DO_TEST("virtio-lun");
206

207
    DO_TEST("usb-redir");
L
Lei Li 已提交
208
    DO_TEST("blkdeviotune");
209

E
Eric Blake 已提交
210 211
    DO_TEST_FULL("seclabel-dynamic-baselabel", false, true);
    DO_TEST_FULL("seclabel-dynamic-override", false, true);
212
    DO_TEST("seclabel-static");
E
Eric Blake 已提交
213
    DO_TEST("seclabel-none");
214

215 216 217 218 219
    /* 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 已提交
220
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
221
    DO_TEST_DIFFERENT("serial-target-port-auto");
222
    DO_TEST_DIFFERENT("graphics-listen-network2");
223
    DO_TEST_DIFFERENT("graphics-spice-timeout");
224

225 226
    DO_TEST_DIFFERENT("metadata");

227
    virCapabilitiesFree(driver.caps);
228

229
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
230 231
}

232 233
VIRT_TEST_MAIN(mymain)

234
#else
E
Eric Blake 已提交
235
# include "testutils.h"
236

237 238 239 240 241
int
main(void)
{
    return EXIT_AM_SKIP;
}
242 243

#endif /* WITH_QEMU */