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

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

static char *progname;

#define MAX_FILE 4096

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

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

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

28
  if (!(gotxml = xend_parse_domain_sexp(NULL, sexprData, xendConfigVersion)))
29
    goto fail;
30

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

39 40 41 42 43 44
  ret = 0;

 fail:
  free(gotxml);

  return ret;
45 46
}

47 48 49 50
static int testComparePVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv.xml",
			  "sexpr2xmldata/sexpr2xml-pv.sexpr",
			  1);
51 52
}

53 54 55 56 57 58 59 60 61 62 63 64
static int testCompareFVversion1(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv.xml",
			  "sexpr2xmldata/sexpr2xml-fv.sexpr",
			  1);
}

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

65 66 67 68
static int testComparePVOrigVFB(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-vfb-orig.xml",
                          "sexpr2xmldata/sexpr2xml-pv-vfb-orig.sexpr",
                          2);
69
}
70 71 72 73 74 75


static int testComparePVNewVFB(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-vfb-new.xml",
                          "sexpr2xmldata/sexpr2xml-pv-vfb-new.sexpr",
                          3);
76
}
77 78


79 80 81 82
static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-v2.xml",
			  "sexpr2xmldata/sexpr2xml-fv-v2.sexpr",
			  2);
83 84
}

85 86 87 88 89 90
static int testComparePVBootloader(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-pv-bootloader.xml",
			  "sexpr2xmldata/sexpr2xml-pv-bootloader.sexpr",
			  2);
}

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
static int testCompareDiskFile(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-file.xml",
			  "sexpr2xmldata/sexpr2xml-disk-file.sexpr",
			  1);
}

static int testCompareDiskBlock(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-disk-block.xml",
			  "sexpr2xmldata/sexpr2xml-disk-block.sexpr",
			  1);
}

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

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

115 116 117 118 119 120
static int testCompareResizedMemory(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-curmem.xml",
			  "sexpr2xmldata/sexpr2xml-curmem.sexpr",
			  1);
}

121

122 123 124 125 126 127 128 129 130 131 132 133
static int testCompareNetRouted(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-net-routed.xml",
			  "sexpr2xmldata/sexpr2xml-net-routed.sexpr",
			  1);
}

static int testCompareNetBridged(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-net-bridged.xml",
			  "sexpr2xmldata/sexpr2xml-net-bridged.sexpr",
			  1);
}

134 135 136 137 138 139
static int testCompareNoSourceCDRom(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-no-source-cdrom.xml",
			  "sexpr2xmldata/sexpr2xml-no-source-cdrom.sexpr",
			  1);
}

140 141 142 143 144 145 146 147 148 149 150 151 152
static int testCompareFVclockUTC(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-utc.xml",
			  "sexpr2xmldata/sexpr2xml-fv-utc.sexpr",
			  1);
}

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


153

154 155 156 157
int
main(int argc, char **argv)
{
    int ret = 0;
158

159
    progname = argv[0];
160

161
    if (argc > 1) {
162 163
	fprintf(stderr, "Usage: %s\n", progname);
	exit(EXIT_FAILURE);
164
    }
165 166

    if (virtTestRun("SEXPR-2-XML PV config (version 1)",
167
		    1, testComparePVversion1, NULL) != 0)
168
	ret = -1;
169

170
    if (virtTestRun("SEXPR-2-XML FV config (version 1)",
171
		    1, testCompareFVversion1, NULL) != 0)
172
	ret = -1;
173

174
    if (virtTestRun("SEXPR-2-XML PV config (version 2)",
175
		    1, testComparePVversion2, NULL) != 0)
176
	ret = -1;
177

178 179 180 181 182 183 184
    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;
185

186
    if (virtTestRun("SEXPR-2-XML FV config (version 2)",
187
		    1, testCompareFVversion2, NULL) != 0)
188 189
	ret = -1;

190 191 192 193
    if (virtTestRun("SEXPR-2-XML PV config bootloader",
		    1, testComparePVBootloader, NULL) != 0)
	ret = -1;

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    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;
209

210 211 212 213
    if (virtTestRun("SEXPR-2-XML Resized memory config",
		    1, testCompareResizedMemory, NULL) != 0)
	ret = -1;

214 215 216 217 218 219 220 221
    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;

222 223 224 225
    if (virtTestRun("SEXPR-2-XML no source CDRom",
		    1, testCompareNoSourceCDRom, NULL) != 0)
	ret = -1;

226 227 228 229 230 231 232 233
    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;

234 235
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
236 237 238 239 240
#else /* WITHOUT_XEN */
int
main(void)
{
    fprintf(stderr, "libvirt compiled without Xen support\n");
241
    return(0);
242 243 244 245 246 247 248 249 250 251
}
#endif /* WITH_XEN */
/*
 * Local variables:
 *  indent-tabs-mode: nil
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 4
 * End:
 */