xml2sexprtest.c 5.4 KB
Newer Older
1

2
#include <config.h>
3

4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <string.h>
7 8
#include <sys/types.h>
#include <fcntl.h>
9
#include <unistd.h>
10

11
#include "internal.h"
12
#include "xen/xend_internal.h"
13
#include "testutils.h"
14
#include "testutilsxen.h"
15 16

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

#define MAX_FILE 4096

22
static int testCompareFiles(const char *xml, const char *sexpr,
23
                            int xendConfigVersion) {
24 25 26 27 28
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotsexpr = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);
29
  int ret = -1;
30
  virDomainDefPtr def = NULL;
31 32

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

  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
36
      goto fail;
37

38
  if (!(def = virDomainDefParseString(caps, xmlData,
G
Guido Günther 已提交
39
                                      VIR_DOMAIN_XML_INACTIVE)))
40
      goto fail;
41

42
  if (!(gotsexpr = xenDaemonFormatSxpr(NULL, def, xendConfigVersion)))
43
      goto fail;
44

45 46
  if (STRNEQ(sexprData, gotsexpr)) {
      virtTestDifference(stderr, sexprData, gotsexpr);
47 48
      goto fail;
  }
49

50 51 52
  ret = 0;

 fail:
53
  virDomainDefFree(def);
54 55 56
  free(gotsexpr);

  return ret;
57 58
}

59 60 61 62 63 64
struct testInfo {
    const char *input;
    const char *output;
    const char *name;
    int version;
};
65

66 67 68 69 70 71 72 73
static int testCompareHelper(const void *data) {
    const struct testInfo *info = data;
    char xml[PATH_MAX];
    char args[PATH_MAX];
    snprintf(xml, PATH_MAX, "%s/xml2sexprdata/xml2sexpr-%s.xml",
             abs_srcdir, info->input);
    snprintf(args, PATH_MAX, "%s/xml2sexprdata/xml2sexpr-%s.sexpr",
             abs_srcdir, info->output);
74
    return testCompareFiles(xml, args, info->version);
75 76
}

77

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

84
    progname = argv[0];
85

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

90
    if (argc > 1) {
91
        fprintf(stderr, "Usage: %s\n", progname);
92
        return(EXIT_FAILURE);
93
    }
94

95 96 97
#define DO_TEST(in, out, name, version)                                \
    do {                                                               \
        struct testInfo info = { in, out, name, version };             \
98
        virResetLastError();                                           \
99 100 101 102 103
        if (virtTestRun("Xen XML-2-SEXPR " in " -> " out,              \
                        1, testCompareHelper, &info) < 0)     \
            ret = -1;                                                  \
    } while (0)

104 105 106
    if (!(caps = testXenCapsInit()))
        return(EXIT_FAILURE);

107 108 109 110 111
    DO_TEST("pv", "pv", "pvtest", 1);
    DO_TEST("fv", "fv", "fvtest", 1);
    DO_TEST("pv", "pv", "pvtest", 2);
    DO_TEST("fv", "fv-v2", "fvtest", 2);
    DO_TEST("fv-vncunused", "fv-vncunused", "fvtest", 2);
112 113 114 115
#ifdef WITH_RHEL5_API
    /* RHEL-5 Xen doesn't support the old style vnc configuration */
    DO_TEST("pv-vfb-orig", "pv-vfb-new", "pvtest", 2);
#else
116
    DO_TEST("pv-vfb-orig", "pv-vfb-orig", "pvtest", 2);
117
#endif
118
    DO_TEST("pv-vfb-new", "pv-vfb-new", "pvtest", 3);
119
    DO_TEST("pv-vfb-new-auto", "pv-vfb-new-auto", "pvtest", 3);
120 121 122 123 124 125 126 127 128 129
    DO_TEST("pv-bootloader", "pv-bootloader", "pvtest", 1);

    DO_TEST("disk-file", "disk-file", "pvtest", 2);
    DO_TEST("disk-block", "disk-block", "pvtest", 2);
    DO_TEST("disk-block-shareable", "disk-block-shareable", "pvtest", 2);
    DO_TEST("disk-drv-loop", "disk-drv-loop", "pvtest", 2);
    DO_TEST("disk-drv-blkback", "disk-drv-blkback", "pvtest", 2);
    DO_TEST("disk-drv-blktap", "disk-drv-blktap", "pvtest", 2);
    DO_TEST("disk-drv-blktap-raw", "disk-drv-blktap-raw", "pvtest", 2);
    DO_TEST("disk-drv-blktap-qcow", "disk-drv-blktap-qcow", "pvtest", 2);
130 131
    DO_TEST("disk-drv-blktap2", "disk-drv-blktap2", "pvtest", 2);
    DO_TEST("disk-drv-blktap2-raw", "disk-drv-blktap2-raw", "pvtest", 2);
132 133 134 135

    DO_TEST("curmem", "curmem", "rhel5", 2);
    DO_TEST("net-routed", "net-routed", "pvtest", 2);
    DO_TEST("net-bridged", "net-bridged", "pvtest", 2);
136
    DO_TEST("net-e1000", "net-e1000", "pvtest", 2);
137
    DO_TEST("bridge-ipaddr", "bridge-ipaddr", "pvtest", 2);
138
    DO_TEST("no-source-cdrom", "no-source-cdrom", "test", 2);
139
    DO_TEST("pv-localtime", "pv-localtime", "pvtest", 1);
140
    DO_TEST("pci-devs", "pci-devs", "pvtest", 2);
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157

    DO_TEST("fv-utc", "fv-utc", "fvtest", 1);
    DO_TEST("fv-localtime", "fv-localtime", "fvtest", 1);
    DO_TEST("fv-usbmouse", "fv-usbmouse", "fvtest", 1);
    DO_TEST("fv-usbmouse", "fv-usbmouse", "fvtest", 1);
    DO_TEST("fv-kernel", "fv-kernel", "fvtest", 1);

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

D
Daniel Veillard 已提交
159 160
    DO_TEST("fv-sound", "fv-sound", "fvtest", 1);

161 162 163
    DO_TEST("fv-net-ioemu", "fv-net-ioemu", "fvtest", 1);
    DO_TEST("fv-net-netfront", "fv-net-netfront", "fvtest", 1);

164 165
    virCapabilitiesFree(caps);

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

169
VIRT_TEST_MAIN(mymain)