genericxml2xmltest.c 3.7 KB
Newer Older
C
Cole Robinson 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <sys/types.h>
#include <fcntl.h>

#include "testutils.h"
#include "internal.h"
#include "virstring.h"

#define VIR_FROM_THIS VIR_FROM_NONE

static virCapsPtr caps;
static virDomainXMLOptionPtr xmlopt;

struct testInfo {
    const char *name;
    int different;
    bool inactive_only;
24
    testCompareDomXML2XMLResult expectResult;
C
Cole Robinson 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
};

static int
testCompareXMLToXMLHelper(const void *data)
{
    const struct testInfo *info = data;
    char *xml_in = NULL;
    char *xml_out = NULL;
    int ret = -1;

    if (virAsprintf(&xml_in, "%s/genericxml2xmlindata/generic-%s.xml",
                    abs_srcdir, info->name) < 0 ||
        virAsprintf(&xml_out, "%s/genericxml2xmloutdata/generic-%s.xml",
                    abs_srcdir, info->name) < 0)
        goto cleanup;

    ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in,
                                     info->different ? xml_out : xml_in,
43
                                     !info->inactive_only, NULL, NULL, 0,
44
                                     info->expectResult);
C
Cole Robinson 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
 cleanup:
    VIR_FREE(xml_in);
    VIR_FREE(xml_out);
    return ret;
}


static int
mymain(void)
{
    int ret = 0;

    if (!(caps = virTestGenericCapsInit()))
        return EXIT_FAILURE;

    if (!(xmlopt = virTestGenericDomainXMLConfInit()))
        return EXIT_FAILURE;

63
#define DO_TEST_FULL(name, is_different, inactive, expectResult)        \
C
Cole Robinson 已提交
64
    do {                                                                \
65 66
        const struct testInfo info = {name, is_different, inactive,     \
                                      expectResult};                    \
67 68
        if (virTestRun("GENERIC XML-2-XML " name,                       \
                       testCompareXMLToXMLHelper, &info) < 0)           \
C
Cole Robinson 已提交
69 70 71 72
            ret = -1;                                                   \
    } while (0)

#define DO_TEST(name) \
73
    DO_TEST_FULL(name, 0, false, TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS)
C
Cole Robinson 已提交
74 75

#define DO_TEST_DIFFERENT(name) \
76
    DO_TEST_FULL(name, 1, false, TEST_COMPARE_DOM_XML2XML_RESULT_SUCCESS)
C
Cole Robinson 已提交
77 78 79

    DO_TEST_DIFFERENT("disk-virtio");

80 81 82 83
    DO_TEST_DIFFERENT("graphics-vnc-minimal");
    DO_TEST_DIFFERENT("graphics-vnc-manual-port");
    DO_TEST_DIFFERENT("graphics-vnc-socket");
    DO_TEST_DIFFERENT("graphics-vnc-socket-listen");
84 85 86
    DO_TEST_DIFFERENT("graphics-listen-back-compat");
    DO_TEST_FULL("graphics-listen-back-compat-mismatch", 0, false,
        TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
87 88 89
    DO_TEST_DIFFERENT("graphics-vnc-listen-attr-only");
    DO_TEST_DIFFERENT("graphics-vnc-listen-element-minimal");
    DO_TEST_DIFFERENT("graphics-vnc-listen-element-with-address");
90 91 92 93
    DO_TEST_DIFFERENT("graphics-vnc-socket-attr-listen-address");
    DO_TEST_DIFFERENT("graphics-vnc-socket-attr-listen-socket");
    DO_TEST_FULL("graphics-vnc-socket-attr-listen-socket-mismatch", 0, false,
        TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
94
    DO_TEST("graphics-vnc-autoport-no");
95

96
    DO_TEST_FULL("name-slash-fail", 0, false,
97 98
        TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);

P
Peter Krempa 已提交
99 100
    DO_TEST("perf");

101
    DO_TEST("vcpus-individual");
102
    DO_TEST("disk-network-http");
103

104 105 106 107
    DO_TEST("cpu-cache-emulate");
    DO_TEST("cpu-cache-passthrough");
    DO_TEST("cpu-cache-disable");

108 109 110 111 112 113
    DO_TEST_DIFFERENT("chardev-tcp");
    DO_TEST_FULL("chardev-tcp-missing-host", 0, false,
                 TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);
    DO_TEST_FULL("chardev-tcp-missing-service", 0, false,
                 TEST_COMPARE_DOM_XML2XML_RESULT_FAIL_PARSE);

C
Cole Robinson 已提交
114 115 116 117 118 119
    virObjectUnref(caps);
    virObjectUnref(xmlopt);

    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

120
VIR_TEST_MAIN(mymain)