qemuxml2xmltest.c 3.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
#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;
D
Daniel P. Berrange 已提交
30
    struct qemud_vm_def *vmdef = NULL;
31 32 33 34 35 36 37 38 39 40 41
    struct qemud_vm vm;

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

    if (!(vmdef = qemudParseVMDef(NULL, &driver, xmlData, "test")))
        goto fail;

    vm.def = vmdef;
    vm.pid = -1;
    vm.id = -1;
42 43 44 45
    vm.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1;
    vm.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON |
        QEMUD_CMD_FLAG_NO_REBOOT;

46 47 48 49 50
    vmdef->vncActivePort = vmdef->vncPort;

    if (!(actual = qemudGenerateXML(NULL, &driver, &vm, vmdef, 0)))
        goto fail;

51 52
    if (STRNEQ(xmlData, actual)) {
        virtTestDifference(stderr, xmlData, actual);
53 54 55 56 57 58 59
        goto fail;
    }

    ret = 0;

 fail:
    free(actual);
60 61
    if (vmdef)
        qemudFreeVMDef(vmdef);
62 63 64 65 66
    return ret;
}

static int testCompareXMLToXMLHelper(const void *data) {
    char xml[PATH_MAX];
67 68
    snprintf(xml, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
             abs_srcdir, (const char*)data);
69 70 71 72
    return testCompareXMLToXMLFiles(xml);
}


73 74
static int
mymain(int argc, char **argv)
75 76
{
    int ret = 0;
77
    char cwd[PATH_MAX];
78 79 80 81 82

    progname = argv[0];

    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname);
83
        return (EXIT_FAILURE);
84 85
    }

86 87 88
    abs_srcdir = getenv("abs_srcdir");
    if (!abs_srcdir)
        abs_srcdir = getcwd(cwd, sizeof(cwd));
89

90 91
    if ((driver.caps = testQemuCapsInit()) == NULL)
        return (EXIT_FAILURE);
92

93 94 95 96 97 98 99 100 101
#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 已提交
102
    DO_TEST("bootloader");
103 104 105 106 107
    DO_TEST("clock-utc");
    DO_TEST("clock-localtime");
    DO_TEST("disk-cdrom");
    DO_TEST("disk-floppy");
    DO_TEST("disk-many");
108
    DO_TEST("disk-xenvbd");
109 110 111 112
    DO_TEST("graphics-vnc");
    DO_TEST("graphics-sdl");
    DO_TEST("input-usbmouse");
    DO_TEST("input-usbtablet");
113
    DO_TEST("input-xen");
114 115 116
    DO_TEST("misc-acpi");
    DO_TEST("misc-no-reboot");
    DO_TEST("net-user");
117
    DO_TEST("net-virtio");
118 119 120 121 122 123 124 125 126 127 128 129

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

131
    virCapabilitiesFree(driver.caps);
132

133
    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
134 135
}

136 137
VIRT_TEST_MAIN(mymain)

138 139 140 141 142
#else

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

#endif /* WITH_QEMU */