xml2sexprtest.c 6.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#include <stdio.h>
#include <string.h>

#include "xml.h"
#include "testutils.h"
#include "internal.h"

static char *progname;

#define MAX_FILE 4096

12
static int testCompareFiles(const char *xml, const char *sexpr, const char *name, int xendConfigVersion) {
13 14 15 16 17 18
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotname = NULL;
  char *gotsexpr = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);
19
  int ret = -1;
20 21

  if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
22
    goto fail;
23 24

  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
25
    goto fail;
26

27
  if (!(gotsexpr = virDomainParseXMLDesc(NULL, xmlData, &gotname, xendConfigVersion)))
28
    goto fail;
29 30

  if (getenv("DEBUG_TESTS")) {
31 32
      printf("Expect %d '%s'\n", (int)strlen(sexprData), sexprData);
      printf("Actual %d '%s'\n", (int)strlen(gotsexpr), gotsexpr);
33 34
  }
  if (strcmp(sexprData, gotsexpr))
35
    goto fail;
36 37

  if (strcmp(name, gotname))
38
    goto fail;
39

40 41 42 43 44 45 46 47
  ret = 0;

 fail:

  free(gotname);
  free(gotsexpr);

  return ret;
48 49
}

50 51 52 53 54
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
			  "xml2sexprdata/xml2sexpr-pv.sexpr",
			  "pvtest",
			  1);
55 56
}

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
static int testCompareFVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
			  "xml2sexprdata/xml2sexpr-fv.sexpr",
			  "fvtest",
			  1);
}

static int testComparePVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
			  "xml2sexprdata/xml2sexpr-pv.sexpr",
			  "pvtest",
			  2);
}

static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
			  "xml2sexprdata/xml2sexpr-fv-v2.sexpr",
			  "fvtest",
			  2);
76 77
}

78 79
static int testCompareFVversion2VNC(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-vncunused.xml",
80 81 82 83 84
			  "xml2sexprdata/xml2sexpr-fv-vncunused.sexpr",
			  "fvtest",
			  2);
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
static int testComparePVOrigVFB(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv-vfb-orig.xml",
                          "xml2sexprdata/xml2sexpr-pv-vfb-orig.sexpr",
			  "pvtest",
                          2);
}


static int testComparePVNewVFB(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv-vfb-new.xml",
                          "xml2sexprdata/xml2sexpr-pv-vfb-new.sexpr",
			  "pvtest",
                          3);
}

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
static int testCompareDiskFile(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-file.xml",
			  "xml2sexprdata/xml2sexpr-disk-file.sexpr",
			  "pvtest",
			  2);
}

static int testCompareDiskBlock(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-block.xml",
			  "xml2sexprdata/xml2sexpr-disk-block.sexpr",
			  "pvtest",
			  2);
}

static int testCompareDiskDrvLoop(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-loop.xml",
			  "xml2sexprdata/xml2sexpr-disk-drv-loop.sexpr",
			  "pvtest",
			  2);
}

static int testCompareDiskDrvBlkback(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blkback.xml",
			  "xml2sexprdata/xml2sexpr-disk-drv-blkback.sexpr",
			  "pvtest",
			  2);
}

static int testCompareDiskDrvBlktap(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blktap.xml",
			  "xml2sexprdata/xml2sexpr-disk-drv-blktap.sexpr",
			  "pvtest",
			  2);
}

static int testCompareDiskDrvBlktapQcow(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blktap-qcow.xml",
			  "xml2sexprdata/xml2sexpr-disk-drv-blktap-qcow.sexpr",
			  "pvtest",
			  2);
}

static int testCompareDiskDrvBlktapRaw(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blktap-raw.xml",
			  "xml2sexprdata/xml2sexpr-disk-drv-blktap-raw.sexpr",
			  "pvtest",
			  2);
147 148
}

149 150 151 152 153 154 155
static int testCompareMemoryResize(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-curmem.xml",
			  "xml2sexprdata/xml2sexpr-curmem.sexpr",
			  "rhel5",
			  2);
}

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
static int testCompareNetRouted(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-net-routed.xml",
			  "xml2sexprdata/xml2sexpr-net-routed.sexpr",
			  "pvtest",
			  2);
}

static int testCompareNetBridged(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-net-bridged.xml",
			  "xml2sexprdata/xml2sexpr-net-bridged.sexpr",
			  "pvtest",
			  2);
}


171 172 173 174
int
main(int argc, char **argv)
{
    int ret = 0;
175

176
    progname = argv[0];
177

178
    if (argc > 1) {
179 180
	fprintf(stderr, "Usage: %s\n", progname);
	exit(EXIT_FAILURE);
181
    }
182 183

    if (virtTestRun("XML-2-SEXPR PV config (format 1)",
184
		    1, testComparePVversion1, NULL) != 0)
185
	ret = -1;
186

187
    if (virtTestRun("XML-2-SEXPR FV config (format 1)",
188
		    1, testCompareFVversion1, NULL) != 0)
189
	ret = -1;
190 191 192

    if (virtTestRun("XML-2-SEXPR PV config (format 2)",
		    1, testComparePVversion2, NULL) != 0)
193
	ret = -1;
194

195
    if (virtTestRun("XML-2-SEXPR FV config (format 2)",
196
		    1, testCompareFVversion2, NULL) != 0)
197
	ret = -1;
198

199
    if (virtTestRun("XML-2-SEXPR FV config (format 2, VNC unused)",
200 201 202
		    1, testCompareFVversion2VNC, NULL) != 0)
	ret = -1;

203 204 205 206 207 208 209 210
    if (virtTestRun("XML-2-SEXPR PV config (Orig VFB)",
                    1, testComparePVOrigVFB, NULL) != 0)
        ret = -1;

    if (virtTestRun("XML-2-SEXPR PV config (New VFB)",
                    1, testComparePVNewVFB, NULL) != 0)
        ret = -1;

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
    if (virtTestRun("XML-2-SEXPR Disk File",
		    1, testCompareDiskFile, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Disk Block",
		    1, testCompareDiskBlock, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Disk Drv Loop",
		    1, testCompareDiskDrvLoop, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Disk Drv Blkback",
		    1, testCompareDiskDrvBlkback, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Disk Drv Blktap",
		    1, testCompareDiskDrvBlktap, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Disk Drv Blktap QCow",
		    1, testCompareDiskDrvBlktapQcow, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Disk Drv Blktap Raw",
		    1, testCompareDiskDrvBlktapRaw, NULL) != 0)
	ret = -1;

239 240 241 242
    if (virtTestRun("XML-2-SEXPR Memory Resize",
		    1, testCompareMemoryResize, NULL) != 0)
	ret = -1;

243 244 245 246 247 248 249
    if (virtTestRun("XML-2-SEXPR Net Routed",
		    1, testCompareNetRouted, NULL) != 0)
	ret = -1;

    if (virtTestRun("XML-2-SEXPR Net Bridged",
		    1, testCompareNetBridged, NULL) != 0)
	ret = -1;
250

251 252
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}