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

static char *progname;
19
static char *abs_srcdir;
20
static struct qemud_driver driver;
21 22 23 24 25 26 27 28 29

#define MAX_FILE 4096


static int testCompareXMLToXMLFiles(const char *xml) {
    char xmlData[MAX_FILE];
    char *xmlPtr = &(xmlData[0]);
    char *actual = NULL;
    int ret = -1;
30
    virDomainDefPtr vmdef = NULL;
31 32 33 34

    if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
        goto fail;

35
    if (!(vmdef = virDomainDefParseString(driver.caps, xmlData,
36
                                          VIR_DOMAIN_XML_INACTIVE)))
37 38
        goto fail;

39
    if (!(actual = virDomainDefFormat(vmdef, 0)))
40 41
        goto fail;

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

    ret = 0;

 fail:
    free(actual);
51
    virDomainDefFree(vmdef);
52 53 54 55 56
    return ret;
}

static int testCompareXMLToXMLHelper(const void *data) {
    char xml[PATH_MAX];
57 58
    snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
             abs_srcdir, (const char*)data);
59 60 61 62
    return testCompareXMLToXMLFiles(xml);
}


63 64
static int
mymain(int argc, char **argv)
65 66
{
    int ret = 0;
67
    char cwd[PATH_MAX];
68 69 70 71 72

    progname = argv[0];

    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname);
73
        return (EXIT_FAILURE);
74 75
    }

76 77 78
    abs_srcdir = getenv("abs_srcdir");
    if (!abs_srcdir)
        abs_srcdir = getcwd(cwd, sizeof(cwd));
79

80 81
    if ((driver.caps = testQemuCapsInit()) == NULL)
        return (EXIT_FAILURE);
82

83 84 85 86 87 88 89 90 91
#define DO_TEST(name) \
    if (virtTestRun("QEMU XML-2-XML " name, \
                    1, testCompareXMLToXMLHelper, (name)) < 0) \
        ret = -1

    DO_TEST("minimal");
    DO_TEST("boot-cdrom");
    DO_TEST("boot-network");
    DO_TEST("boot-floppy");
D
Daniel P. Berrange 已提交
92
    DO_TEST("bootloader");
93 94
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
95
    DO_TEST("hugepages");
96 97 98
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
99
    DO_TEST("disk-xenvbd");
100
    DO_TEST("disk-usb");
101
    DO_TEST("disk-virtio");
102 103
    DO_TEST("floppy-drive-fat");
    DO_TEST("disk-drive-fat");
104
    DO_TEST("disk-drive-fmt-qcow");
105 106 107
    DO_TEST("disk-drive-cache-v1-wt");
    DO_TEST("disk-drive-cache-v1-wb");
    DO_TEST("disk-drive-cache-v1-none");
108
    DO_TEST("graphics-vnc");
109 110
    DO_TEST("graphics-vnc-sasl");
    DO_TEST("graphics-vnc-tls");
111
    DO_TEST("graphics-sdl");
112
    DO_TEST("graphics-sdl-fullscreen");
113 114
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
115
    DO_TEST("input-xen");
116 117 118
    DO_TEST("misc-acpi");
    DO_TEST("misc-no-reboot");
    DO_TEST("net-user");
119
    DO_TEST("net-virtio");
120 121
    DO_TEST("net-eth");
    DO_TEST("net-eth-ifname");
122
    DO_TEST("sound");
123 124 125 126 127 128 129 130 131 132 133 134

    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");
135
    DO_TEST("channel-guestfwd");
136
    DO_TEST("channel-virtio");
137

138
    DO_TEST("hostdev-usb-address");
139
    DO_TEST("hostdev-pci-address");
140

141
    virCapabilitiesFree(driver.caps);
142

143
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
144 145
}

146 147
VIRT_TEST_MAIN(mymain)

148 149
#else

150
int main (void) { exit (EXIT_AM_SKIP); }
151 152

#endif /* WITH_QEMU */