2014-03-17 15:19:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Francesco Romani <fromani@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "qemu/qemu_capabilities.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _testQemuData testQemuData;
|
|
|
|
typedef testQemuData *testQemuDataPtr;
|
|
|
|
struct _testQemuData {
|
|
|
|
const char *base;
|
|
|
|
virArch guestarch;
|
|
|
|
};
|
|
|
|
|
|
|
|
static virQEMUCapsPtr
|
|
|
|
testQemuGetCaps(char *caps)
|
|
|
|
{
|
|
|
|
virQEMUCapsPtr qemuCaps = NULL;
|
|
|
|
xmlDocPtr xml;
|
|
|
|
xmlXPathContextPtr ctxt = NULL;
|
|
|
|
ssize_t i, n;
|
|
|
|
xmlNodePtr *nodes = NULL;
|
|
|
|
|
|
|
|
if (!(xml = virXMLParseStringCtxt(caps, "(test caps)", &ctxt)))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) {
|
|
|
|
fprintf(stderr, "failed to parse qemu capabilities flags");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(qemuCaps = virQEMUCapsNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
char *str = virXMLPropString(nodes[i], "name");
|
|
|
|
if (str) {
|
|
|
|
int flag = virQEMUCapsTypeFromString(str);
|
|
|
|
if (flag < 0) {
|
|
|
|
fprintf(stderr, "Unknown qemu capabilities flag %s", str);
|
|
|
|
VIR_FREE(str);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
VIR_FREE(str);
|
|
|
|
virQEMUCapsSet(qemuCaps, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return qemuCaps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
VIR_FREE(nodes);
|
|
|
|
virObjectUnref(qemuCaps);
|
|
|
|
xmlFreeDoc(xml);
|
|
|
|
xmlXPathFreeContext(ctxt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static virCapsPtr
|
|
|
|
testGetCaps(char *capsData, const testQemuData *data)
|
|
|
|
{
|
|
|
|
virQEMUCapsPtr qemuCaps = NULL;
|
|
|
|
virCapsPtr caps = NULL;
|
|
|
|
|
|
|
|
if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) {
|
|
|
|
fprintf(stderr, "failed to parse qemu capabilities flags");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-07-14 12:56:13 +00:00
|
|
|
if ((caps = virCapabilitiesNew(data->guestarch, false, false)) == NULL) {
|
2014-03-17 15:19:46 +00:00
|
|
|
fprintf(stderr, "failed to create the fake capabilities");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virQEMUCapsInitGuestFromBinary(caps,
|
|
|
|
"/usr/bin/qemu-system-i386",
|
|
|
|
qemuCaps,
|
2015-03-25 14:17:13 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-03-17 15:19:46 +00:00
|
|
|
data->guestarch) < 0) {
|
|
|
|
fprintf(stderr, "failed to create the capabilities from qemu");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2014-03-26 22:37:54 +00:00
|
|
|
virObjectUnref(qemuCaps);
|
2014-03-17 15:19:46 +00:00
|
|
|
return caps;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virObjectUnref(qemuCaps);
|
2015-09-08 11:12:52 +00:00
|
|
|
virObjectUnref(caps);
|
2014-03-17 15:19:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testQemuCapsXML(const void *opaque)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
const testQemuData *data = opaque;
|
|
|
|
char *capsFile = NULL, *xmlFile = NULL;
|
2015-04-23 15:14:26 +00:00
|
|
|
char *capsData = NULL;
|
2014-03-17 15:19:46 +00:00
|
|
|
char *capsXml = NULL;
|
|
|
|
virCapsPtr capsProvided = NULL;
|
|
|
|
|
2015-03-24 14:22:16 +00:00
|
|
|
if (virAsprintf(&xmlFile, "%s/qemucaps2xmldata/%s.xml",
|
2014-03-17 15:19:46 +00:00
|
|
|
abs_srcdir, data->base) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&capsFile, "%s/qemucaps2xmldata/%s.caps",
|
|
|
|
abs_srcdir, data->base) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(capsFile, &capsData) < 0)
|
2014-03-17 15:19:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(capsProvided = testGetCaps(capsData, data)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
capsXml = virCapabilitiesFormatXML(capsProvided);
|
|
|
|
if (!capsXml)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(capsXml, xmlFile) < 0)
|
2015-04-23 15:14:26 +00:00
|
|
|
goto cleanup;
|
2014-03-17 15:19:46 +00:00
|
|
|
|
2015-04-23 15:14:26 +00:00
|
|
|
ret = 0;
|
2014-03-17 15:19:46 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xmlFile);
|
|
|
|
VIR_FREE(capsFile);
|
|
|
|
VIR_FREE(capsXml);
|
|
|
|
VIR_FREE(capsData);
|
|
|
|
virObjectUnref(capsProvided);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
testQemuData data;
|
|
|
|
|
|
|
|
#if !WITH_YAJL
|
|
|
|
fputs("libvirt not compiled with yajl, skipping this test\n", stderr);
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (virThreadInitialize() < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
virEventRegisterDefaultImpl();
|
|
|
|
|
|
|
|
#define DO_TEST_FULL(name, guest) \
|
|
|
|
data.base = name; \
|
|
|
|
data.guestarch = guest; \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun(name, testQemuCapsXML, &data) < 0) \
|
2014-03-17 15:19:46 +00:00
|
|
|
ret = -1
|
|
|
|
|
|
|
|
#define DO_TEST(name) DO_TEST_FULL(name, VIR_ARCH_I686)
|
|
|
|
|
|
|
|
DO_TEST("all_1.6.0-1");
|
|
|
|
DO_TEST("nodisksnapshot_1.6.0-1");
|
|
|
|
|
|
|
|
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/qemucaps2xmlmock.so")
|