qemuxml2xmltest.c 3.4 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 15
#include "testutils.h"
#include "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 36
    if (!(vmdef = virDomainDefParseString(NULL, driver.caps, xmlData,
                                          VIR_DOMAIN_XML_INACTIVE)))
37 38
        goto fail;

39
    if (!(actual = virDomainDefFormat(NULL, 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 95 96 97
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
98
    DO_TEST("disk-xenvbd");
99
    DO_TEST("disk-usb");
100
    DO_TEST("disk-drive-fmt-qcow");
101 102 103
    DO_TEST("disk-drive-cache-v1-wt");
    DO_TEST("disk-drive-cache-v1-wb");
    DO_TEST("disk-drive-cache-v1-none");
104
    DO_TEST("graphics-vnc");
105 106
    DO_TEST("graphics-vnc-sasl");
    DO_TEST("graphics-vnc-tls");
107
    DO_TEST("graphics-sdl");
108
    DO_TEST("graphics-sdl-fullscreen");
109 110
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
111
    DO_TEST("input-xen");
112 113 114
    DO_TEST("misc-acpi");
    DO_TEST("misc-no-reboot");
    DO_TEST("net-user");
115
    DO_TEST("net-virtio");
116 117
    DO_TEST("net-eth");
    DO_TEST("net-eth-ifname");
118
    DO_TEST("sound");
119 120 121 122 123 124 125 126 127 128 129 130

    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");
131

132 133
    DO_TEST("hostdev-usb-product");
    DO_TEST("hostdev-usb-address");
134
    DO_TEST("hostdev-pci-address");
135

136
    virCapabilitiesFree(driver.caps);
137

138
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
139 140
}

141 142
VIRT_TEST_MAIN(mymain)

143 144 145 146 147
#else

int main (void) { exit (77); /* means 'test skipped' to automake */ }

#endif /* WITH_QEMU */