qemuxml2xmltest.c 2.9 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
    if (!(vmdef = virDomainDefParseString(NULL, driver.caps, xmlData)))
36 37
        goto fail;

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

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

    ret = 0;

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

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


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

    progname = argv[0];

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

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

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

82 83 84 85 86 87 88 89 90
#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 已提交
91
    DO_TEST("bootloader");
92 93 94 95 96
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
97
    DO_TEST("disk-xenvbd");
98 99 100 101
    DO_TEST("graphics-vnc");
    DO_TEST("graphics-sdl");
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
102
    DO_TEST("input-xen");
103 104 105
    DO_TEST("misc-acpi");
    DO_TEST("misc-no-reboot");
    DO_TEST("net-user");
106
    DO_TEST("net-virtio");
107
    DO_TEST("sound");
108 109 110 111 112 113 114 115 116 117 118 119

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

121
    virCapabilitiesFree(driver.caps);
122

123
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
124 125
}

126 127
VIRT_TEST_MAIN(mymain)

128 129 130 131 132
#else

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

#endif /* WITH_QEMU */