sexpr2xmltest.c 7.7 KB
Newer Older
1 2 3
#include <stdio.h>
#include <string.h>

4
#ifdef WITH_XEN
5 6 7 8 9 10
#include "xml.h"
#include "xend_internal.h"
#include "testutils.h"
#include "internal.h"

static char *progname;
11
static char *abs_top_srcdir;
12 13 14

#define MAX_FILE 4096

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

  snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
  snprintf(sexpr, sizeof sexpr - 1, "%s/tests/%s", abs_top_srcdir, sexpr_rel);
28 29

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

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

35
  if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData, xendConfigVersion)))
36
    goto fail;
37

38 39
  if (strcmp(xmlData, gotxml)) {
    if (getenv("DEBUG_TESTS")) {
40
        printf("In test file %s -> %s:\n", sexpr, xml);
41 42 43
        printf("Expect %d '%s'\n", (int)strlen(xmlData), xmlData);
        printf("Actual %d '%s'\n", (int)strlen(gotxml), gotxml);
    }
44
    goto fail;
45
  }
46

47 48 49 50 51 52
  ret = 0;

 fail:
  free(gotxml);

  return ret;
53 54
}

55
static int testComparePVversion1(const void *data ATTRIBUTE_UNUSED) {
56 57 58
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv.xml",
			  "sexpr2xmldata/sexpr2xml-pv.sexpr",
			  1);
59 60
}

61
static int testCompareFVversion1(const void *data ATTRIBUTE_UNUSED) {
62 63 64 65 66
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv.xml",
			  "sexpr2xmldata/sexpr2xml-fv.sexpr",
			  1);
}

67
static int testComparePVversion2(const void *data ATTRIBUTE_UNUSED) {
68 69 70 71 72
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv.xml",
			  "sexpr2xmldata/sexpr2xml-pv.sexpr",
			  2);
}

73
static int testComparePVOrigVFB(const void *data ATTRIBUTE_UNUSED) {
74 75 76
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-vfb-orig.xml",
                          "sexpr2xmldata/sexpr2xml-pv-vfb-orig.sexpr",
                          2);
77
}
78 79


80
static int testComparePVNewVFB(const void *data ATTRIBUTE_UNUSED) {
81 82 83
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-vfb-new.xml",
                          "sexpr2xmldata/sexpr2xml-pv-vfb-new.sexpr",
                          3);
84
}
85 86


87
static int testCompareFVversion2(const void *data ATTRIBUTE_UNUSED) {
88 89 90
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-v2.xml",
			  "sexpr2xmldata/sexpr2xml-fv-v2.sexpr",
			  2);
91 92
}

93
static int testComparePVBootloader(const void *data ATTRIBUTE_UNUSED) {
94 95 96 97 98
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-bootloader.xml",
			  "sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr",
			  2);
}

99
static int testCompareDiskFile(const void *data ATTRIBUTE_UNUSED) {
100 101 102 103 104
  return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-file.xml",
			  "sexpr2xmldata/sexpr2xml-disk-file.sexpr",
			  1);
}

105
static int testCompareDiskBlock(const void *data ATTRIBUTE_UNUSED) {
106 107 108 109 110
  return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-block.xml",
			  "sexpr2xmldata/sexpr2xml-disk-block.sexpr",
			  1);
}

111
static int testCompareDiskDrvBlktapQcow(const void *data ATTRIBUTE_UNUSED) {
112 113 114 115 116
  return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-drv-blktap-qcow.xml",
			  "sexpr2xmldata/sexpr2xml-disk-drv-blktap-qcow.sexpr",
			  1);
}

117
static int testCompareDiskDrvBlktapRaw(const void *data ATTRIBUTE_UNUSED) {
118 119 120 121 122
  return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-drv-blktap-raw.xml",
			  "sexpr2xmldata/sexpr2xml-disk-drv-blktap-raw.sexpr",
			  1);
}

123
static int testCompareResizedMemory(const void *data ATTRIBUTE_UNUSED) {
124 125 126 127 128
  return testCompareFiles("sexpr2xmldata/sexpr2xml-curmem.xml",
			  "sexpr2xmldata/sexpr2xml-curmem.sexpr",
			  1);
}

129

130
static int testCompareNetRouted(const void *data ATTRIBUTE_UNUSED) {
131 132 133 134 135
  return testCompareFiles("sexpr2xmldata/sexpr2xml-net-routed.xml",
			  "sexpr2xmldata/sexpr2xml-net-routed.sexpr",
			  1);
}

136
static int testCompareNetBridged(const void *data ATTRIBUTE_UNUSED) {
137 138 139 140 141
  return testCompareFiles("sexpr2xmldata/sexpr2xml-net-bridged.xml",
			  "sexpr2xmldata/sexpr2xml-net-bridged.sexpr",
			  1);
}

142
static int testCompareNoSourceCDRom(const void *data ATTRIBUTE_UNUSED) {
143 144 145 146 147
  return testCompareFiles("sexpr2xmldata/sexpr2xml-no-source-cdrom.xml",
			  "sexpr2xmldata/sexpr2xml-no-source-cdrom.sexpr",
			  1);
}

148 149 150 151 152 153 154 155 156 157 158 159 160
static int testCompareFVInputUSBMouse(const void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-usbmouse.xml",
			  "sexpr2xmldata/sexpr2xml-fv-usbmouse.sexpr",
			  1);
}

static int testCompareFVInputUSBTablet(const void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-usbtablet.xml",
			  "sexpr2xmldata/sexpr2xml-fv-usbtablet.sexpr",
			  1);
}

static int testCompareFVclockUTC(const void *data ATTRIBUTE_UNUSED) {
161 162 163 164 165
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-utc.xml",
			  "sexpr2xmldata/sexpr2xml-fv-utc.sexpr",
			  1);
}

166
static int testCompareFVclockLocaltime(const void *data ATTRIBUTE_UNUSED) {
167 168 169 170 171 172
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-localtime.xml",
			  "sexpr2xmldata/sexpr2xml-fv-localtime.sexpr",
			  1);
}


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

178
    progname = argv[0];
179

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

185 186 187 188
    abs_top_srcdir = getenv("abs_top_srcdir");
    if (!abs_top_srcdir)
      return 1;

189
    if (virtTestRun("SEXPR-2-XML PV config (version 1)",
190
		    1, testComparePVversion1, NULL) != 0)
191
	ret = -1;
192

193
    if (virtTestRun("SEXPR-2-XML FV config (version 1)",
194
		    1, testCompareFVversion1, NULL) != 0)
195
	ret = -1;
196

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

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

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

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

213 214 215 216
    if (virtTestRun("SEXPR-2-XML PV config bootloader",
		    1, testComparePVBootloader, NULL) != 0)
	ret = -1;

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    if (virtTestRun("SEXPR-2-XML Disk File config",
		    1, testCompareDiskFile, NULL) != 0)
	ret = -1;

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

    if (virtTestRun("SEXPR-2-XML Disk Driver blktap qcow config",
		    1, testCompareDiskDrvBlktapQcow, NULL) != 0)
	ret = -1;

    if (virtTestRun("SEXPR-2-XML Disk Driver blktap raw config",
		    1, testCompareDiskDrvBlktapRaw, NULL) != 0)
	ret = -1;
232

233 234 235 236
    if (virtTestRun("SEXPR-2-XML Resized memory config",
		    1, testCompareResizedMemory, NULL) != 0)
	ret = -1;

237 238 239 240 241 242 243 244
    if (virtTestRun("SEXPR-2-XML net routed",
		    1, testCompareNetRouted, NULL) != 0)
	ret = -1;

    if (virtTestRun("SEXPR-2-XML net bridged",
		    1, testCompareNetBridged, NULL) != 0)
	ret = -1;

245 246 247 248
    if (virtTestRun("SEXPR-2-XML no source CDRom",
		    1, testCompareNoSourceCDRom, NULL) != 0)
	ret = -1;

249 250 251 252 253 254 255
    if (virtTestRun("SEXPR-2-XML USB Mouse",
		    1, testCompareFVInputUSBMouse, NULL) != 0)
	ret = -1;
    if (virtTestRun("SEXPR-2-XML USB Tablet",
		    1, testCompareFVInputUSBTablet, NULL) != 0)
	ret = -1;

256 257 258 259 260 261 262 263
    if (virtTestRun("SEXPR-2-XML clock UTC",
		    1, testCompareFVclockUTC, NULL) != 0)
	ret = -1;

    if (virtTestRun("SEXPR-2-XML clock Localtime",
		    1, testCompareFVclockLocaltime, NULL) != 0)
	ret = -1;

264 265
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
266 267 268 269 270
#else /* WITHOUT_XEN */
int
main(void)
{
    fprintf(stderr, "libvirt compiled without Xen support\n");
271
    return(0);
272 273 274 275 276 277 278 279 280 281
}
#endif /* WITH_XEN */
/*
 * Local variables:
 *  indent-tabs-mode: nil
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 * End:
 */