sexpr2xmltest.c 4.6 KB
Newer Older
1
#include <config.h>
2

3 4
#include <stdio.h>
#include <string.h>
5
#include <unistd.h>
6

7
#include "internal.h"
8
#include "xml.h"
9 10
#include "datatypes.h"
#include "xen_unified.h"
11 12
#include "xend_internal.h"
#include "testutils.h"
13
#include "testutilsxen.h"
14 15

static char *progname;
16
static char *abs_srcdir;
17
static virCapsPtr caps;
18 19 20

#define MAX_FILE 4096

21
static int testCompareFiles(const char *xml, const char *sexpr,
22
                            int xendConfigVersion) {
23 24 25 26 27
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotxml = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);
28
  int ret = -1;
29
  virDomainDefPtr def = NULL;
30 31 32 33 34 35
  virConnectPtr conn;
  struct _xenUnifiedPrivate priv;


  conn = virGetConnect();
  if (!conn) goto fail;
36

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

40 41 42
  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
      goto fail;

43 44 45 46 47 48 49 50 51
  memset(&priv, 0, sizeof priv);
  /* Many puppies died to bring you this code. */
  priv.xendConfigVersion = xendConfigVersion;
  priv.caps = caps;
  conn->privateData = &priv;
  if (virMutexInit(&priv.lock) < 0)
      goto fail;

  if (!(def = xenDaemonParseSxprString(conn, sexprData, xendConfigVersion)))
52
      goto fail;
53

54 55
  if (!(gotxml = virDomainDefFormat(NULL, def, 0)))
      goto fail;
56

57 58 59
  if (STRNEQ(xmlData, gotxml)) {
      virtTestDifference(stderr, xmlData, gotxml);
      goto fail;
60
  }
61

62 63 64 65
  ret = 0;

 fail:
  free(gotxml);
66
  virDomainDefFree(def);
67
  virUnrefConnect(conn);
68 69

  return ret;
70 71
}

72 73 74 75 76
struct testInfo {
    const char *input;
    const char *output;
    int version;
};
77

78 79 80 81 82 83 84 85 86
static int testCompareHelper(const void *data) {
    const struct testInfo *info = data;
    char xml[PATH_MAX];
    char args[PATH_MAX];
    snprintf(xml, PATH_MAX, "%s/sexpr2xmldata/sexpr2xml-%s.xml",
             abs_srcdir, info->input);
    snprintf(args, PATH_MAX, "%s/sexpr2xmldata/sexpr2xml-%s.sexpr",
             abs_srcdir, info->output);
    return testCompareFiles(xml, args, info->version);
87 88
}

89

90 91
static int
mymain(int argc, char **argv)
92 93
{
    int ret = 0;
94
    char cwd[PATH_MAX];
95

96
    progname = argv[0];
97

98
    if (argc > 1) {
99
        fprintf(stderr, "Usage: %s\n", progname);
100
        return(EXIT_FAILURE);
101
    }
102

103 104 105 106 107 108
    abs_srcdir = getenv("abs_srcdir");
    if (!abs_srcdir)
        abs_srcdir = getcwd(cwd, sizeof(cwd));

    if (argc > 1) {
        fprintf(stderr, "Usage: %s\n", progname);
109
        return(EXIT_FAILURE);
110
    }
111

112 113 114
    if (!(caps = testXenCapsInit()))
        return(EXIT_FAILURE);

115 116 117 118 119 120 121 122 123 124 125 126 127 128
#define DO_TEST(in, out, version)                                      \
    do {                                                               \
        struct testInfo info = { in, out, version };                   \
        if (virtTestRun("Xen SEXPR-2-XML " in " -> " out,              \
                        1, testCompareHelper, &info) < 0)              \
            ret = -1;                                                  \
    } while (0)

    DO_TEST("pv", "pv", 1);
    DO_TEST("fv", "fv", 1);
    DO_TEST("pv", "pv", 2);
    DO_TEST("fv-v2", "fv-v2", 2);
    DO_TEST("pv-vfb-orig", "pv-vfb-orig", 2);
    DO_TEST("pv-vfb-new", "pv-vfb-new", 3);
129
    DO_TEST("pv-vfb-new-vncdisplay", "pv-vfb-new-vncdisplay", 3);
130 131 132 133 134 135 136 137
    DO_TEST("pv-bootloader", "pv-bootloader", 1);

    DO_TEST("disk-file", "disk-file", 2);
    DO_TEST("disk-block", "disk-block", 2);
    DO_TEST("disk-block-shareable", "disk-block-shareable", 2);
    DO_TEST("disk-drv-blktap-raw", "disk-drv-blktap-raw", 2);
    DO_TEST("disk-drv-blktap-qcow", "disk-drv-blktap-qcow", 2);

138
    DO_TEST("curmem", "curmem", 2);
139 140
    DO_TEST("net-routed", "net-routed", 2);
    DO_TEST("net-bridged", "net-bridged", 2);
141
    DO_TEST("net-e1000", "net-e1000", 2);
142
    DO_TEST("bridge-ipaddr", "bridge-ipaddr", 3);
143
    DO_TEST("no-source-cdrom", "no-source-cdrom", 2);
144 145 146 147

    DO_TEST("fv-utc", "fv-utc", 1);
    DO_TEST("fv-localtime", "fv-localtime", 1);
    DO_TEST("fv-usbmouse", "fv-usbmouse", 1);
148
    DO_TEST("fv-usbtablet", "fv-usbtablet", 1);
149 150 151 152 153 154 155 156 157 158 159 160
    DO_TEST("fv-kernel", "fv-kernel", 1);

    DO_TEST("fv-serial-null", "fv-serial-null", 1);
    DO_TEST("fv-serial-file", "fv-serial-file", 1);
    DO_TEST("fv-serial-stdio", "fv-serial-stdio", 1);
    DO_TEST("fv-serial-pty", "fv-serial-pty", 1);
    DO_TEST("fv-serial-pipe", "fv-serial-pipe", 1);
    DO_TEST("fv-serial-tcp", "fv-serial-tcp", 1);
    DO_TEST("fv-serial-udp", "fv-serial-udp", 1);
    DO_TEST("fv-serial-tcp-telnet", "fv-serial-tcp-telnet", 1);
    DO_TEST("fv-serial-unix", "fv-serial-unix", 1);
    DO_TEST("fv-parallel-tcp", "fv-parallel-tcp", 1);
161

D
Daniel Veillard 已提交
162 163 164
    DO_TEST("fv-sound", "fv-sound", 1);
    DO_TEST("fv-sound-all", "fv-sound-all", 1);

165
    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
166
}
167 168 169

VIRT_TEST_MAIN(mymain)