xml2sexprtest.c 12.0 KB
Newer Older
1

2
#include <config.h>
3

4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <string.h>
7 8 9
#include <sys/types.h>
#include <fcntl.h>

10 11
#if WITH_XEN

12
#include "internal.h"
13 14 15 16
#include "xml.h"
#include "testutils.h"

static char *progname;
17
static char *abs_top_srcdir;
18 19 20

#define MAX_FILE 4096

21 22
static int testCompareFiles(const char *xml_rel, const char *sexpr_rel,
                            const char *name, int xendConfigVersion) {
23 24 25 26 27 28
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotname = NULL;
  char *gotsexpr = NULL;
  char *xmlPtr = &(xmlData[0]);
  char *sexprPtr = &(sexprData[0]);
29
  int ret = -1;
30 31 32 33 34
  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);
35 36

  if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
37
    goto fail;
38 39

  if (virtTestLoadFile(sexpr, &sexprPtr, MAX_FILE) < 0)
40
    goto fail;
41

42
  if (!(gotsexpr = virDomainParseXMLDesc(NULL, xmlData, &gotname, xendConfigVersion)))
43
    goto fail;
44

45
  if (strcmp(sexprData, gotsexpr)) {
46
      if (getenv("DEBUG_TESTS")) {
47 48
        printf("Expect %d '%s'\n", (int)strlen(sexprData), sexprData);
        printf("Actual %d '%s'\n", (int)strlen(gotsexpr), gotsexpr);
49
      }
50 51
      goto fail;
  }
52

53 54 55 56
  if (strcmp(name, gotname)) {
      printf("Got wrong name: expected %s, got %s\n", name, gotname);
      goto fail;
  }
57

58 59 60 61 62 63 64 65
  ret = 0;

 fail:

  free(gotname);
  free(gotsexpr);

  return ret;
66 67
}

D
Daniel P. Berrange 已提交
68
static int testComparePVversion1(const void *data ATTRIBUTE_UNUSED) {
69
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
70 71 72
                          "xml2sexprdata/xml2sexpr-pv.sexpr",
                          "pvtest",
                          1);
73 74
}

D
Daniel P. Berrange 已提交
75
static int testCompareFVversion1(const void *data ATTRIBUTE_UNUSED) {
76
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
77 78 79
                          "xml2sexprdata/xml2sexpr-fv.sexpr",
                          "fvtest",
                          1);
80 81
}

D
Daniel P. Berrange 已提交
82
static int testComparePVversion2(const void *data ATTRIBUTE_UNUSED) {
83
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv.xml",
84 85 86
                          "xml2sexprdata/xml2sexpr-pv.sexpr",
                          "pvtest",
                          2);
87 88
}

D
Daniel P. Berrange 已提交
89
static int testCompareFVversion2(const void *data ATTRIBUTE_UNUSED) {
90
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv.xml",
91 92 93
                          "xml2sexprdata/xml2sexpr-fv-v2.sexpr",
                          "fvtest",
                          2);
94 95
}

D
Daniel P. Berrange 已提交
96
static int testCompareFVversion2VNC(const void *data ATTRIBUTE_UNUSED) {
97
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-vncunused.xml",
98 99 100
                          "xml2sexprdata/xml2sexpr-fv-vncunused.sexpr",
                          "fvtest",
                          2);
101 102
}

D
Daniel P. Berrange 已提交
103
static int testComparePVOrigVFB(const void *data ATTRIBUTE_UNUSED) {
104 105
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv-vfb-orig.xml",
                          "xml2sexprdata/xml2sexpr-pv-vfb-orig.sexpr",
106
                          "pvtest",
107 108 109 110
                          2);
}


D
Daniel P. Berrange 已提交
111
static int testComparePVNewVFB(const void *data ATTRIBUTE_UNUSED) {
112 113
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv-vfb-new.xml",
                          "xml2sexprdata/xml2sexpr-pv-vfb-new.sexpr",
114
                          "pvtest",
115 116 117
                          3);
}

D
Daniel P. Berrange 已提交
118
static int testComparePVBootloader(const void *data ATTRIBUTE_UNUSED) {
119
  return testCompareFiles("xml2sexprdata/xml2sexpr-pv-bootloader.xml",
120 121 122
                          "xml2sexprdata/xml2sexpr-pv-bootloader.sexpr",
                          "pvtest",
                          1);
123 124
}

D
Daniel P. Berrange 已提交
125
static int testCompareDiskFile(const void *data ATTRIBUTE_UNUSED) {
126
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-file.xml",
127 128 129
                          "xml2sexprdata/xml2sexpr-disk-file.sexpr",
                          "pvtest",
                          2);
130 131
}

D
Daniel P. Berrange 已提交
132
static int testCompareDiskBlock(const void *data ATTRIBUTE_UNUSED) {
133
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-block.xml",
134 135 136
                          "xml2sexprdata/xml2sexpr-disk-block.sexpr",
                          "pvtest",
                          2);
137 138
}

139 140
static int testCompareDiskShareable(const void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-block-shareable.xml",
141 142 143
                          "xml2sexprdata/xml2sexpr-disk-block-shareable.sexpr",
                          "pvtest",
                          2);
144 145
}

D
Daniel P. Berrange 已提交
146
static int testCompareDiskDrvLoop(const void *data ATTRIBUTE_UNUSED) {
147
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-loop.xml",
148 149 150
                          "xml2sexprdata/xml2sexpr-disk-drv-loop.sexpr",
                          "pvtest",
                          2);
151 152
}

D
Daniel P. Berrange 已提交
153
static int testCompareDiskDrvBlkback(const void *data ATTRIBUTE_UNUSED) {
154
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blkback.xml",
155 156 157
                          "xml2sexprdata/xml2sexpr-disk-drv-blkback.sexpr",
                          "pvtest",
                          2);
158 159
}

D
Daniel P. Berrange 已提交
160
static int testCompareDiskDrvBlktap(const void *data ATTRIBUTE_UNUSED) {
161
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blktap.xml",
162 163 164
                          "xml2sexprdata/xml2sexpr-disk-drv-blktap.sexpr",
                          "pvtest",
                          2);
165 166
}

D
Daniel P. Berrange 已提交
167
static int testCompareDiskDrvBlktapQcow(const void *data ATTRIBUTE_UNUSED) {
168
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blktap-qcow.xml",
169 170 171
                          "xml2sexprdata/xml2sexpr-disk-drv-blktap-qcow.sexpr",
                          "pvtest",
                          2);
172 173
}

D
Daniel P. Berrange 已提交
174
static int testCompareDiskDrvBlktapRaw(const void *data ATTRIBUTE_UNUSED) {
175
  return testCompareFiles("xml2sexprdata/xml2sexpr-disk-drv-blktap-raw.xml",
176 177 178
                          "xml2sexprdata/xml2sexpr-disk-drv-blktap-raw.sexpr",
                          "pvtest",
                          2);
179 180
}

D
Daniel P. Berrange 已提交
181
static int testCompareMemoryResize(const void *data ATTRIBUTE_UNUSED) {
182
  return testCompareFiles("xml2sexprdata/xml2sexpr-curmem.xml",
183 184 185
                          "xml2sexprdata/xml2sexpr-curmem.sexpr",
                          "rhel5",
                          2);
186 187
}

D
Daniel P. Berrange 已提交
188
static int testCompareNetRouted(const void *data ATTRIBUTE_UNUSED) {
189
  return testCompareFiles("xml2sexprdata/xml2sexpr-net-routed.xml",
190 191 192
                          "xml2sexprdata/xml2sexpr-net-routed.sexpr",
                          "pvtest",
                          2);
193 194
}

D
Daniel P. Berrange 已提交
195
static int testCompareNetBridged(const void *data ATTRIBUTE_UNUSED) {
196
  return testCompareFiles("xml2sexprdata/xml2sexpr-net-bridged.xml",
197 198 199
                          "xml2sexprdata/xml2sexpr-net-bridged.sexpr",
                          "pvtest",
                          2);
200 201
}

D
Daniel P. Berrange 已提交
202
static int testCompareNoSourceCDRom(const void *data ATTRIBUTE_UNUSED) {
203
  return testCompareFiles("xml2sexprdata/xml2sexpr-no-source-cdrom.xml",
204 205 206
                          "xml2sexprdata/xml2sexpr-no-source-cdrom.sexpr",
                          "test",
                          2);
207 208
}

D
Daniel P. Berrange 已提交
209
static int testCompareFVclockUTC(const void *data ATTRIBUTE_UNUSED) {
210
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-utc.xml",
211 212 213
                          "xml2sexprdata/xml2sexpr-fv-utc.sexpr",
                          "fvtest",
                          1);
214 215
}

D
Daniel P. Berrange 已提交
216
static int testCompareFVclockLocaltime(const void *data ATTRIBUTE_UNUSED) {
217
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-localtime.xml",
218 219 220
                          "xml2sexprdata/xml2sexpr-fv-localtime.sexpr",
                          "fvtest",
                          1);
221 222
}

223

D
Daniel P. Berrange 已提交
224
static int testCompareFVInputUSBMouse(const void *data ATTRIBUTE_UNUSED) {
225
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-usbmouse.xml",
226 227 228
                          "xml2sexprdata/xml2sexpr-fv-usbmouse.sexpr",
                          "fvtest",
                          1);
229 230
}

D
Daniel P. Berrange 已提交
231
static int testCompareFVInputUSBTablet(const void *data ATTRIBUTE_UNUSED) {
232
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-usbtablet.xml",
233 234 235
                          "xml2sexprdata/xml2sexpr-fv-usbtablet.sexpr",
                          "fvtest",
                          1);
236 237
}

238 239
static int testCompareFVKernel(const void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("xml2sexprdata/xml2sexpr-fv-kernel.xml",
240 241 242
                          "xml2sexprdata/xml2sexpr-fv-kernel.sexpr",
                          "fvtest",
                          1);
243 244
}

245 246


247 248 249 250
int
main(int argc, char **argv)
{
    int ret = 0;
251

252
    progname = argv[0];
253

254
    abs_top_srcdir = getenv("abs_top_srcdir");
255 256
    if (!abs_top_srcdir) {
        fprintf(stderr, "missing enviroment variable abs_top_srcdir\n");
257
        exit(EXIT_FAILURE);
258
    }
259

260

261
    if (argc > 1) {
262 263
        fprintf(stderr, "Usage: %s\n", progname);
        exit(EXIT_FAILURE);
264
    }
265 266

    if (virtTestRun("XML-2-SEXPR PV config (format 1)",
267 268
                    1, testComparePVversion1, NULL) != 0)
        ret = -1;
269

270
    if (virtTestRun("XML-2-SEXPR FV config (format 1)",
271 272
                    1, testCompareFVversion1, NULL) != 0)
        ret = -1;
273 274

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

278
    if (virtTestRun("XML-2-SEXPR FV config (format 2)",
279 280
                    1, testCompareFVversion2, NULL) != 0)
        ret = -1;
281

282
    if (virtTestRun("XML-2-SEXPR FV config (format 2, VNC unused)",
283 284
                    1, testCompareFVversion2VNC, NULL) != 0)
        ret = -1;
285

286 287 288 289 290 291 292 293
    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;

294
    if (virtTestRun("XML-2-SEXPR PV config with bootloader",
295 296
                    1, testComparePVBootloader, NULL) != 0)
        ret = -1;
297

298
    if (virtTestRun("XML-2-SEXPR Disk File",
299 300
                    1, testCompareDiskFile, NULL) != 0)
        ret = -1;
301 302

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

306
    if (virtTestRun("XML-2-SEXPR Disk Shareable",
307 308
                    1, testCompareDiskShareable, NULL) != 0)
        ret = -1;
309

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

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

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

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

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

330
    if (virtTestRun("XML-2-SEXPR Memory Resize",
331 332
                    1, testCompareMemoryResize, NULL) != 0)
        ret = -1;
333

334
    if (virtTestRun("XML-2-SEXPR Net Routed",
335 336
                    1, testCompareNetRouted, NULL) != 0)
        ret = -1;
337 338

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

342
    if (virtTestRun("XML-2-SEXPR No Source CDRom",
343 344
                    1, testCompareNoSourceCDRom, NULL) != 0)
        ret = -1;
345

346
    if (virtTestRun("XML-2-SEXPR FV usb mouse)",
347 348
                    1, testCompareFVInputUSBMouse, NULL) != 0)
        ret = -1;
349
    if (virtTestRun("XML-2-SEXPR FV usb tablet)",
350 351
                    1, testCompareFVInputUSBTablet, NULL) != 0)
        ret = -1;
352

353
    if (virtTestRun("XML-2-SEXPR clock UTC",
354 355
                    1, testCompareFVclockUTC, NULL) != 0)
        ret = -1;
356 357

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

361
    if (virtTestRun("XML-2-SEXPR FV kernel",
362 363
                    1, testCompareFVKernel, NULL) != 0)
        ret = -1;
364

365 366
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
367 368 369 370 371 372

#else /* WITH_XEN */

int main (void) { exit (77); /* means 'test skipped' for automake */ }

#endif /* ! WITH_XEN */