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)
25 testCompareXMLToConfigFiles(const char *xmlfile
,
26 const char *configfile
,
31 char *actualxml
= NULL
;
32 virDomainDefPtr vmdef
= NULL
;
34 if (virTestLoadFile(configfile
, &config
) < 0)
37 vmdef
= lxcParseConfigString(config
, caps
, xmlopt
);
38 if ((vmdef
&& expectError
) || (!vmdef
&& !expectError
))
42 if (testSanitizeDef(vmdef
) < 0)
45 if (!(actualxml
= virDomainDefFormat(vmdef
, caps
, 0)))
48 if (virTestCompareToFile(actualxml
, xmlfile
) < 0)
57 virDomainDefFree(vmdef
);
67 testCompareXMLToConfigHelperLegacy(const void *data
)
70 const struct testInfo
*info
= data
;
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)
80 result
= testCompareXMLToConfigFiles(xml
, config
, info
->expectError
);
89 testCompareXMLToConfigHelperV3(const void *data
)
92 const struct testInfo
*info
= data
;
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)
102 result
= testCompareXMLToConfigFiles(xml
, config
, info
->expectError
);
114 int ret
= EXIT_SUCCESS
;
116 if (!(caps
= testLXCCapsInit()))
119 if (!(xmlopt
= lxcDomainXMLConfInit())) {
120 virObjectUnref(caps
);
124 # define DO_TEST(name, expectError) \
126 const struct testInfo info = { name, expectError }; \
127 if (virTestRun("LXC Native-2-XML " name, \
128 testCompareXMLToConfigHelperLegacy, \
130 ret = EXIT_FAILURE; \
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) \
151 const struct testInfo info = { name, expectError }; \
152 if (virTestRun("LXC Native-3-XML " name, \
153 testCompareXMLToConfigHelperV3, \
155 ret = EXIT_FAILURE; \
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
);
179 VIR_TEST_MAIN(mymain
)
189 #endif /* WITH_LXC */