qemuxml2xmltest.c 5.1 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 16
# include "internal.h"
# include "testutils.h"
# include "qemu/qemu_conf.h"
# include "testutilsqemu.h"
17

18
static struct qemud_driver driver;
19

20 21 22 23 24
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
    char *inXmlData = NULL;
    char *outXmlData = NULL;
25 26
    char *actual = NULL;
    int ret = -1;
27
    virDomainDefPtr def = NULL;
28

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

34
    if (!(def = virDomainDefParseString(driver.caps, inXmlData,
35
                                          VIR_DOMAIN_XML_INACTIVE)))
36 37
        goto fail;

38
    if (!(actual = virDomainDefFormat(def, 0)))
39 40
        goto fail;

41 42 43

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

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

56 57 58 59 60
struct testInfo {
    const char *name;
    int different;
};

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

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

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

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


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

93 94
    if ((driver.caps = testQemuCapsInit()) == NULL)
        return (EXIT_FAILURE);
95

96 97 98 99 100 101 102 103
# 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)

104
# define DO_TEST(name) \
105 106 107 108 109 110 111 112 113
    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);
114 115 116 117 118

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

    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");
171
    DO_TEST("channel-guestfwd");
172
    DO_TEST("channel-virtio");
173

174
    DO_TEST("hostdev-usb-address");
175
    DO_TEST("hostdev-pci-address");
176

177
    DO_TEST("encrypted-disk");
178
    DO_TEST("memtune");
179
    DO_TEST("blkiotune");
O
Osier Yang 已提交
180
    DO_TEST("cputune");
181

182 183
    DO_TEST("smp");

184 185 186 187 188
    /* 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 已提交
189
    DO_TEST_DIFFERENT("console-virtio");
M
Michal Novotny 已提交
190
    DO_TEST_DIFFERENT("serial-target-port-auto");
191

192
    virCapabilitiesFree(driver.caps);
193

194
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
195 196
}

197 198
VIRT_TEST_MAIN(mymain)

199 200
#else

201
int main (void) { exit (EXIT_AM_SKIP); }
202 203

#endif /* WITH_QEMU */