backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / lxcconf2xmltest.c
blob2a277042ce313755f24d80b301cfd721e227d2cf
1 #include <config.h>
3 #include "testutils.h"
5 #ifdef WITH_LXC
7 # include "lxc/lxc_native.h"
8 # include "lxc/lxc_conf.h"
9 # include "testutilslxc.h"
11 # define VIR_FROM_THIS VIR_FROM_NONE
13 static virCapsPtr caps;
14 static virDomainXMLOptionPtr xmlopt;
16 static int testSanitizeDef(virDomainDefPtr vmdef)
18 /* Remove UUID randomness */
19 if (virUUIDParse("c7a5fdbd-edaf-9455-926a-d65c16db1809", vmdef->uuid) < 0)
20 return -1;
21 return 0;
24 static int
25 testCompareXMLToConfigFiles(const char *xmlfile,
26 const char *configfile,
27 bool expectError)
29 int ret = -1;
30 char *config = NULL;
31 char *actualxml = NULL;
32 virDomainDefPtr vmdef = NULL;
34 if (virTestLoadFile(configfile, &config) < 0)
35 goto fail;
37 vmdef = lxcParseConfigString(config, caps, xmlopt);
38 if ((vmdef && expectError) || (!vmdef && !expectError))
39 goto fail;
41 if (vmdef) {
42 if (testSanitizeDef(vmdef) < 0)
43 goto fail;
45 if (!(actualxml = virDomainDefFormat(vmdef, caps, 0)))
46 goto fail;
48 if (virTestCompareToFile(actualxml, xmlfile) < 0)
49 goto fail;
52 ret = 0;
54 fail:
55 VIR_FREE(actualxml);
56 VIR_FREE(config);
57 virDomainDefFree(vmdef);
58 return ret;
61 struct testInfo {
62 const char *name;
63 bool expectError;
66 static int
67 testCompareXMLToConfigHelperLegacy(const void *data)
69 int result = -1;
70 const struct testInfo *info = data;
71 char *xml = NULL;
72 char *config = NULL;
74 if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
75 abs_srcdir, info->name) < 0 ||
76 virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config",
77 abs_srcdir, info->name) < 0)
78 goto cleanup;
80 result = testCompareXMLToConfigFiles(xml, config, info->expectError);
82 cleanup:
83 VIR_FREE(xml);
84 VIR_FREE(config);
85 return result;
88 static int
89 testCompareXMLToConfigHelperV3(const void *data)
91 int result = -1;
92 const struct testInfo *info = data;
93 char *xml = NULL;
94 char *config = NULL;
96 if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
97 abs_srcdir, info->name) < 0 ||
98 virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s-v3.config",
99 abs_srcdir, info->name) < 0)
100 goto cleanup;
102 result = testCompareXMLToConfigFiles(xml, config, info->expectError);
104 cleanup:
105 VIR_FREE(xml);
106 VIR_FREE(config);
107 return result;
111 static int
112 mymain(void)
114 int ret = EXIT_SUCCESS;
116 if (!(caps = testLXCCapsInit()))
117 return EXIT_FAILURE;
119 if (!(xmlopt = lxcDomainXMLConfInit())) {
120 virObjectUnref(caps);
121 return EXIT_FAILURE;
124 # define DO_TEST(name, expectError) \
125 do { \
126 const struct testInfo info = { name, expectError }; \
127 if (virTestRun("LXC Native-2-XML " name, \
128 testCompareXMLToConfigHelperLegacy, \
129 &info) < 0) \
130 ret = EXIT_FAILURE; \
131 } while (0)
133 DO_TEST("simple", false);
134 DO_TEST("fstab", true);
135 DO_TEST("nonetwork", false);
136 DO_TEST("nonenetwork", false);
137 DO_TEST("physnetwork", false);
138 DO_TEST("macvlannetwork", false);
139 DO_TEST("vlannetwork", false);
140 DO_TEST("miscnetwork", false);
141 DO_TEST("idmap", false);
142 DO_TEST("memtune", false);
143 DO_TEST("cputune", false);
144 DO_TEST("cpusettune", false);
145 DO_TEST("blkiotune", false);
146 DO_TEST("ethernet", false);
148 /* Tests for LXC 3.0 and higher */
149 # define DO_TEST3(name, expectError) \
150 do { \
151 const struct testInfo info = { name, expectError }; \
152 if (virTestRun("LXC Native-3-XML " name, \
153 testCompareXMLToConfigHelperV3, \
154 &info) < 0) \
155 ret = EXIT_FAILURE; \
156 } while (0)
158 DO_TEST3("simple", false);
159 DO_TEST3("fstab", true);
160 DO_TEST3("nonetwork", false);
161 DO_TEST3("nonenetwork", false);
162 DO_TEST3("physnetwork", false);
163 DO_TEST3("macvlannetwork", false);
164 DO_TEST3("vlannetwork", false);
165 DO_TEST3("miscnetwork", false);
166 DO_TEST3("idmap", false);
167 DO_TEST3("memtune", false);
168 DO_TEST3("cputune", false);
169 DO_TEST3("cpusettune", false);
170 DO_TEST3("blkiotune", false);
171 DO_TEST3("ethernet", false);
173 virObjectUnref(xmlopt);
174 virObjectUnref(caps);
176 return ret;
179 VIR_TEST_MAIN(mymain)
181 #else
184 main(void)
186 return EXIT_AM_SKIP;
189 #endif /* WITH_LXC */