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

static char *progname;
19
static char *abs_srcdir;
20
static struct qemud_driver driver;
21

22
# define MAX_FILE 4096
23 24


25 26 27 28 29
static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) {
    char inXmlData[MAX_FILE];
    char *inXmlPtr = &(inXmlData[0]);
    char outXmlData[MAX_FILE];
    char *outXmlPtr = &(outXmlData[0]);
30 31
    char *actual = NULL;
    int ret = -1;
32
    virDomainDefPtr def = NULL;
33

34 35 36
    if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0)
        goto fail;
    if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0)
37 38
        goto fail;

39
    if (!(def = virDomainDefParseString(driver.caps, inXmlData,
40
                                          VIR_DOMAIN_XML_INACTIVE)))
41 42
        goto fail;

43
    if (!(actual = virDomainDefFormat(def, 0)))
44 45
        goto fail;

46 47 48

    if (STRNEQ(outXmlData, actual)) {
        virtTestDifference(stderr, outXmlData, actual);
49 50 51 52 53 54
        goto fail;
    }

    ret = 0;
 fail:
    free(actual);
55
    virDomainDefFree(def);
56 57 58
    return ret;
}

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

64
static int testCompareXMLToXMLHelper(const void *data) {
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    const struct testInfo *info = data;
    char xml_in[PATH_MAX];
    char xml_out[PATH_MAX];
    int ret;

    snprintf(xml_in, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
             abs_srcdir, info->name);
    snprintf(xml_out, PATH_MAX, "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
             abs_srcdir, info->name);

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

    return ret;
82 83 84
}


85 86
static int
mymain(int argc, char **argv)
87 88
{
    int ret = 0;
89
    char cwd[PATH_MAX];
90 91 92 93 94

    progname = argv[0];

    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname);
95
        return (EXIT_FAILURE);
96 97
    }

98 99 100
    abs_srcdir = getenv("abs_srcdir");
    if (!abs_srcdir)
        abs_srcdir = getcwd(cwd, sizeof(cwd));
101

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

105 106 107 108 109 110 111 112
# 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)

113
# define DO_TEST(name) \
114 115 116 117 118 119 120 121 122
    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);
123 124 125 126 127

    DO_TEST("minimal");
    DO_TEST("boot-cdrom");
    DO_TEST("boot-network");
    DO_TEST("boot-floppy");
128 129
    DO_TEST("boot-multi");
    DO_TEST("boot-menu-disable");
130
    DO_TEST("boot-order");
D
Daniel P. Berrange 已提交
131
    DO_TEST("bootloader");
132 133
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
134
    DO_TEST("hugepages");
E
Eric Blake 已提交
135
    DO_TEST("disk-aio");
136 137 138
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
139
    DO_TEST("disk-xenvbd");
140
    DO_TEST("disk-usb");
141
    DO_TEST("disk-virtio");
142 143
    DO_TEST("floppy-drive-fat");
    DO_TEST("disk-drive-fat");
144
    DO_TEST("disk-drive-fmt-qcow");
145 146 147
    DO_TEST("disk-drive-cache-v1-wt");
    DO_TEST("disk-drive-cache-v1-wb");
    DO_TEST("disk-drive-cache-v1-none");
148
    DO_TEST("disk-scsi-device");
149
    DO_TEST("graphics-vnc");
150 151
    DO_TEST("graphics-vnc-sasl");
    DO_TEST("graphics-vnc-tls");
152
    DO_TEST("graphics-sdl");
153
    DO_TEST("graphics-sdl-fullscreen");
154
    DO_TEST("graphics-spice");
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("sound");
167 168 169 170 171 172 173 174 175 176 177 178

    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");
179
    DO_TEST("channel-guestfwd");
180
    DO_TEST("channel-virtio");
181

182
    DO_TEST("hostdev-usb-address");
183
    DO_TEST("hostdev-pci-address");
184

185
    DO_TEST("encrypted-disk");
186
    DO_TEST("memtune");
187
    DO_TEST("blkiotune");
O
Osier Yang 已提交
188
    DO_TEST("cputune");
189

190 191
    DO_TEST("smp");

192 193 194 195 196
    /* 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 已提交
197
    DO_TEST_DIFFERENT("console-virtio");
198

199
    virCapabilitiesFree(driver.caps);
200

201
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
202 203
}

204 205
VIRT_TEST_MAIN(mymain)

206 207
#else

208
int main (void) { exit (EXIT_AM_SKIP); }
209 210

#endif /* WITH_QEMU */