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

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

static char *progname;

#define MAX_FILE 4096

13
static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) {
14 15 16 17 18
  char xmlData[MAX_FILE];
  char sexprData[MAX_FILE];
  char *gotxml = 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 (!(gotxml = xend_parse_domain_sexp(NULL, sexprData, xendConfigVersion)))
28
    goto fail;
29 30

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

37 38 39 40 41 42
  ret = 0;

 fail:
  free(gotxml);

  return ret;
43 44
}

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

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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);
}

static int testCompareFVversion2(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-fv-v2.xml",
			  "sexpr2xmldata/sexpr2xml-fv-v2.sexpr",
			  2);
67 68
}

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
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);
}

93 94 95 96 97 98
static int testCompareResizedMemory(void *data ATTRIBUTE_UNUSED) {
  return testCompareFiles("sexpr2xmldata/sexpr2xml-curmem.xml",
			  "sexpr2xmldata/sexpr2xml-curmem.sexpr",
			  1);
}

99

100 101 102 103
int
main(int argc, char **argv)
{
    int ret = 0;
104

105
    progname = argv[0];
106

107
    if (argc > 1) {
108 109
	fprintf(stderr, "Usage: %s\n", progname);
	exit(EXIT_FAILURE);
110
    }
111 112

    if (virtTestRun("SEXPR-2-XML PV config (version 1)",
113
		    1, testComparePVversion1, NULL) != 0)
114
	ret = -1;
115

116
    if (virtTestRun("SEXPR-2-XML FV config (version 1)",
117
		    1, testCompareFVversion1, NULL) != 0)
118
	ret = -1;
119

120
    if (virtTestRun("SEXPR-2-XML PV config (version 2)",
121
		    1, testComparePVversion2, NULL) != 0)
122
	ret = -1;
123

124
    if (virtTestRun("SEXPR-2-XML FV config  (version 2)",
125
		    1, testCompareFVversion2, NULL) != 0)
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
	ret = -1;

    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;
143

144 145 146 147
    if (virtTestRun("SEXPR-2-XML Resized memory config",
		    1, testCompareResizedMemory, NULL) != 0)
	ret = -1;

148 149
    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}