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

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

7
#ifdef WITH_XEN
8 9

#include "internal.h"
10 11 12 13 14
#include "xml.h"
#include "xend_internal.h"
#include "testutils.h"

static char *progname;
15
static char *abs_srcdir;
16 17 18

#define MAX_FILE 4096

19
static int testCompareFiles(const char *xml, const char *sexpr,
20
                            int xendConfigVersion) {
21 22 23 24 25
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotxml = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);
26
  int ret = -1;
27

28 29 30 31
  if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) {
      printf("Missing %s\n", xml);
      goto fail;
  }
32

33 34 35 36
  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0) {
      printf("Missing %s\n", sexpr);
      goto fail;
  }
37

38
  if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData, xendConfigVersion)))
39
    goto fail;
40

41 42 43
  if (STRNEQ(xmlData, gotxml)) {
      virtTestDifference(stderr, xmlData, gotxml);
      goto fail;
44
  }
45

46 47 48 49 50 51
  ret = 0;

 fail:
  free(gotxml);

  return ret;
52 53
}

54 55 56 57 58
struct testInfo {
    const char *input;
    const char *output;
    int version;
};
59

60 61 62 63 64 65 66 67 68
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);
69 70
}

71

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

78
    progname = argv[0];
79

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

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

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

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#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);
    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);

116
    DO_TEST("curmem", "curmem", 2);
117 118
    DO_TEST("net-routed", "net-routed", 2);
    DO_TEST("net-bridged", "net-bridged", 2);
119
    DO_TEST("net-e1000", "net-e1000", 2);
120
    DO_TEST("no-source-cdrom", "no-source-cdrom", 2);
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

    DO_TEST("fv-utc", "fv-utc", 1);
    DO_TEST("fv-localtime", "fv-localtime", 1);
    DO_TEST("fv-usbmouse", "fv-usbmouse", 1);
    DO_TEST("fv-usbmouse", "fv-usbmouse", 1);
    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);
138

D
Daniel Veillard 已提交
139 140 141
    DO_TEST("fv-sound", "fv-sound", 1);
    DO_TEST("fv-sound-all", "fv-sound-all", 1);

142
    return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
143
}
144 145 146

VIRT_TEST_MAIN(mymain)

147 148 149 150 151
#else /* WITHOUT_XEN */
int
main(void)
{
    fprintf(stderr, "libvirt compiled without Xen support\n");
152
    return(0);
153 154
}
#endif /* WITH_XEN */