2 * xmconfigtest.c: Test backend for xm_internal config file handling
4 * Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
20 * Author: Daniel P. Berrange <berrange@redhat.com>
31 #include "datatypes.h"
32 #include "xen/xen_driver.h"
33 #include "xen/xm_internal.h"
34 #include "xenxs/xen_xm.h"
35 #include "testutils.h"
36 #include "testutilsxen.h"
38 #include "virstring.h"
40 #define VIR_FROM_THIS VIR_FROM_NONE
42 static virCapsPtr caps;
43 static virDomainXMLOptionPtr xmlopt;
46 testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
49 char *xmcfgData = NULL;
50 char *gotxmcfgData = NULL;
51 virConfPtr conf = NULL;
53 virConnectPtr conn = NULL;
55 struct _xenUnifiedPrivate priv;
56 virDomainDefPtr def = NULL;
58 if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
61 conn = virGetConnect();
64 if (virtTestLoadFile(xml, &xmlData) < 0)
67 if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
70 /* Many puppies died to bring you this code. */
71 priv.xendConfigVersion = xendConfigVersion;
73 conn->privateData = &priv;
75 if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
76 1 << VIR_DOMAIN_VIRT_XEN,
77 VIR_DOMAIN_XML_INACTIVE)))
80 if (!virDomainDefCheckABIStability(def, def)) {
81 fprintf(stderr, "ABI stability check failed on %s", xml);
85 if (!(conf = xenFormatXM(conn, def, xendConfigVersion)))
88 if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
90 gotxmcfgData[wrote] = '\0';
92 if (STRNEQ(xmcfgData, gotxmcfgData)) {
93 virtTestDifference(stderr, xmcfgData, gotxmcfgData);
102 VIR_FREE(gotxmcfgData);
105 virDomainDefFree(def);
106 virObjectUnref(conn);
112 testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
114 char *xmlData = NULL;
115 char *xmcfgData = NULL;
117 virConfPtr conf = NULL;
120 struct _xenUnifiedPrivate priv;
121 virDomainDefPtr def = NULL;
123 conn = virGetConnect();
124 if (!conn) goto fail;
126 if (virtTestLoadFile(xml, &xmlData) < 0)
129 if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
132 /* Many puppies died to bring you this code. */
133 priv.xendConfigVersion = xendConfigVersion;
135 conn->privateData = &priv;
137 if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
140 if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps)))
143 if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
146 if (STRNEQ(xmlData, gotxml)) {
147 virtTestDifference(stderr, xmlData, gotxml);
159 virDomainDefFree(def);
160 virObjectUnref(conn);
173 testCompareHelper(const void *data)
176 const struct testInfo *info = data;
180 if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml",
181 abs_srcdir, info->name) < 0 ||
182 virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg",
183 abs_srcdir, info->name) < 0)
187 result = testCompareParseXML(cfg, xml, info->version);
189 result = testCompareFormatXML(cfg, xml, info->version);
204 if (!(caps = testXenCapsInit()))
207 if (!(xmlopt = xenDomainXMLConfInit()))
210 #define DO_TEST(name, version) \
212 struct testInfo info0 = { name, version, 0 }; \
213 struct testInfo info1 = { name, version, 1 }; \
214 if (virtTestRun("Xen XM-2-XML Parse " name, \
215 testCompareHelper, &info0) < 0) \
217 if (virtTestRun("Xen XM-2-XML Format " name, \
218 testCompareHelper, &info1) < 0) \
222 DO_TEST("paravirt-old-pvfb", 1);
223 DO_TEST("paravirt-old-pvfb-vncdisplay", 1);
224 DO_TEST("paravirt-new-pvfb", 3);
225 DO_TEST("paravirt-new-pvfb-vncdisplay", 3);
226 DO_TEST("paravirt-net-e1000", 3);
227 DO_TEST("paravirt-net-vifname", 3);
228 DO_TEST("paravirt-vcpu", 2);
229 DO_TEST("fullvirt-old-cdrom", 1);
230 DO_TEST("fullvirt-new-cdrom", 2);
231 DO_TEST("fullvirt-utc", 2);
232 DO_TEST("fullvirt-localtime", 2);
233 DO_TEST("fullvirt-usbtablet", 2);
234 DO_TEST("fullvirt-usbmouse", 2);
235 DO_TEST("fullvirt-serial-file", 2);
236 DO_TEST("fullvirt-serial-dev-2-ports", 2);
237 DO_TEST("fullvirt-serial-dev-2nd-port", 2);
238 DO_TEST("fullvirt-serial-null", 2);
239 DO_TEST("fullvirt-serial-pipe", 2);
240 DO_TEST("fullvirt-serial-pty", 2);
241 DO_TEST("fullvirt-serial-stdio", 2);
242 DO_TEST("fullvirt-serial-tcp", 2);
243 DO_TEST("fullvirt-serial-tcp-telnet", 2);
244 DO_TEST("fullvirt-serial-udp", 2);
245 DO_TEST("fullvirt-serial-unix", 2);
247 DO_TEST("fullvirt-force-hpet", 2);
248 DO_TEST("fullvirt-force-nohpet", 2);
250 DO_TEST("fullvirt-parallel-tcp", 2);
252 DO_TEST("fullvirt-sound", 2);
254 DO_TEST("fullvirt-net-ioemu", 2);
255 DO_TEST("fullvirt-net-netfront", 2);
257 DO_TEST("escape-paths", 2);
258 DO_TEST("no-source-cdrom", 2);
259 DO_TEST("pci-devs", 2);
261 virObjectUnref(caps);
262 virObjectUnref(xmlopt);
264 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
267 VIRT_TEST_MAIN(mymain)