xml2sexprtest.c 7.1 KB
Newer Older
1 2 3
#include <stdio.h>
#include <string.h>

4 5 6
#include <sys/types.h>
#include <fcntl.h>

7 8 9 10 11 12 13 14
#include "xml.h"
#include "testutils.h"
#include "internal.h"

static char *progname;

#define MAX_FILE 4096

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

  if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
25
    goto fail;
26 27

  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
28
    goto fail;
29

30
  if (!(gotsexpr = virDomainParseXMLDesc(NULL, xmlData, &gotname, xendConfigVersion)))
31
    goto fail;
32 33

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

41 42 43 44
  if (strcmp(name, gotname)) {
      printf("Got wrong name: expected %s, got %s\n", name, gotname);
      goto fail;
  }
45

46 47 48 49 50 51 52 53
  ret = 0;

 fail:

  free(gotname);
  free(gotsexpr);

  return ret;
54 55
}

56 57 58 59 60
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
			  "xml2sexprdata/xml2sexpr-pv.sexpr",
			  "pvtest",
			  1);
61 62
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
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);
82 83
}

84 85
static int testCompareFVversion2VNC(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-vncunused.xml",
86 87 88 89 90
			  "xml2sexprdata/xml2sexpr-fv-vncunused.sexpr",
			  "fvtest",
			  2);
}

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
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);
}

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 147 148 149 150 151 152
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);
153 154
}

155 156 157 158 159 160 161
static int testCompareMemoryResize(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-curmem.xml",
			  "xml2sexprdata/xml2sexpr-curmem.sexpr",
			  "rhel5",
			  2);
}

162 163 164 165 166 167 168 169 170 171 172 173 174 175
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);
}

176 177 178 179 180 181 182
static int testCompareNoSourceCDRom(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-no-source-cdrom.xml",
			  "xml2sexprdata/xml2sexpr-no-source-cdrom.sexpr",
			  "test",
			  2);
}

183

184 185 186 187
int
main(int argc, char **argv)
{
    int ret = 0;
188

189
    progname = argv[0];
190

191
    if (argc > 1) {
192 193
	fprintf(stderr, "Usage: %s\n", progname);
	exit(EXIT_FAILURE);
194
    }
195 196

    if (virtTestRun("XML-2-SEXPR PV config (format 1)",
197
		    1, testComparePVversion1, NULL) != 0)
198
	ret = -1;
199

200
    if (virtTestRun("XML-2-SEXPR FV config (format 1)",
201
		    1, testCompareFVversion1, NULL) != 0)
202
	ret = -1;
203 204 205

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

208
    if (virtTestRun("XML-2-SEXPR FV config (format 2)",
209
		    1, testCompareFVversion2, NULL) != 0)
210
	ret = -1;
211

212
    if (virtTestRun("XML-2-SEXPR FV config (format 2, VNC unused)",
213 214 215
		    1, testCompareFVversion2VNC, NULL) != 0)
	ret = -1;

216 217 218 219 220 221 222 223
    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;

224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
    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;

252 253 254 255
    if (virtTestRun("XML-2-SEXPR Memory Resize",
		    1, testCompareMemoryResize, NULL) != 0)
	ret = -1;

256 257 258 259 260 261 262
    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;
263

264 265 266 267
    if (virtTestRun("XML-2-SEXPR No Source CDRom",
		    1, testCompareNoSourceCDRom, NULL) != 0)
	ret = -1;

268 269
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}