sexpr2xmltest.c 4.2 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
  virDomainDefPtr def = NULL;
28

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

32 33 34 35
  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
      goto fail;

  if (!(def = xenDaemonParseSxprString(NULL, sexprData, xendConfigVersion)))
36
      goto fail;
37

38 39
  if (!(gotxml = virDomainDefFormat(NULL, def, 0)))
      goto fail;
40

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

46 47 48 49
  ret = 0;

 fail:
  free(gotxml);
50
  virDomainDefFree(def);
51 52

  return ret;
53 54
}

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

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

72

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

79
    progname = argv[0];
80

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

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

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

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

117
    DO_TEST("curmem", "curmem", 2);
118 119
    DO_TEST("net-routed", "net-routed", 2);
    DO_TEST("net-bridged", "net-bridged", 2);
120
    DO_TEST("net-e1000", "net-e1000", 2);
121
    DO_TEST("no-source-cdrom", "no-source-cdrom", 2);
122 123 124 125

    DO_TEST("fv-utc", "fv-utc", 1);
    DO_TEST("fv-localtime", "fv-localtime", 1);
    DO_TEST("fv-usbmouse", "fv-usbmouse", 1);
126
    DO_TEST("fv-usbtablet", "fv-usbtablet", 1);
127 128 129 130 131 132 133 134 135 136 137 138
    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);
139

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

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

VIRT_TEST_MAIN(mymain)

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