mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
tests: Move qemu caps XML parsing into shared unit
Later on, we the qemu capabilities XML parsing code may come handy so instead of duplicating the code make the already existing one shared. By the same time, make the function accept file name instead of XML document stored already in memory. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
e9f2929f41
commit
3ecb9e7631
@ -85,55 +85,6 @@ testQemuFeedMonitor(char *replies,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (n > 0) {
|
|
||||||
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 int
|
static int
|
||||||
testQemuCapsCompare(virQEMUCapsPtr capsProvided,
|
testQemuCapsCompare(virQEMUCapsPtr capsProvided,
|
||||||
virQEMUCapsPtr capsComputed)
|
virQEMUCapsPtr capsComputed)
|
||||||
@ -166,7 +117,7 @@ testQemuCaps(const void *opaque)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
const testQemuData *data = opaque;
|
const testQemuData *data = opaque;
|
||||||
char *repliesFile = NULL, *capsFile = NULL;
|
char *repliesFile = NULL, *capsFile = NULL;
|
||||||
char *replies = NULL, *caps = NULL;
|
char *replies = NULL;
|
||||||
qemuMonitorTestPtr mon = NULL;
|
qemuMonitorTestPtr mon = NULL;
|
||||||
virQEMUCapsPtr capsProvided = NULL, capsComputed = NULL;
|
virQEMUCapsPtr capsProvided = NULL, capsComputed = NULL;
|
||||||
|
|
||||||
@ -176,14 +127,13 @@ testQemuCaps(const void *opaque)
|
|||||||
abs_srcdir, data->base) < 0)
|
abs_srcdir, data->base) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virtTestLoadFile(repliesFile, &replies) < 0 ||
|
if (virtTestLoadFile(repliesFile, &replies) < 0)
|
||||||
virtTestLoadFile(capsFile, &caps) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(mon = testQemuFeedMonitor(replies, data->xmlopt)))
|
if (!(mon = testQemuFeedMonitor(replies, data->xmlopt)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(capsProvided = testQemuGetCaps(caps)))
|
if (!(capsProvided = qemuTestParseCapabilities(capsFile)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(capsComputed = virQEMUCapsNew()))
|
if (!(capsComputed = virQEMUCapsNew()))
|
||||||
@ -207,7 +157,6 @@ testQemuCaps(const void *opaque)
|
|||||||
VIR_FREE(repliesFile);
|
VIR_FREE(repliesFile);
|
||||||
VIR_FREE(capsFile);
|
VIR_FREE(capsFile);
|
||||||
VIR_FREE(replies);
|
VIR_FREE(replies);
|
||||||
VIR_FREE(caps);
|
|
||||||
qemuMonitorTestFree(mon);
|
qemuMonitorTestFree(mon);
|
||||||
virObjectUnref(capsProvided);
|
virObjectUnref(capsProvided);
|
||||||
virObjectUnref(capsComputed);
|
virObjectUnref(capsComputed);
|
||||||
|
@ -373,4 +373,53 @@ testSCSIDeviceGetSgName(const char *sysfs_prefix ATTRIBUTE_UNUSED,
|
|||||||
qemuBuildCommandLineCallbacks testCallbacks = {
|
qemuBuildCommandLineCallbacks testCallbacks = {
|
||||||
.qemuGetSCSIDeviceSgName = testSCSIDeviceGetSgName,
|
.qemuGetSCSIDeviceSgName = testSCSIDeviceGetSgName,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virQEMUCapsPtr
|
||||||
|
qemuTestParseCapabilities(const char *capsFile)
|
||||||
|
{
|
||||||
|
virQEMUCapsPtr qemuCaps = NULL;
|
||||||
|
xmlDocPtr xml;
|
||||||
|
xmlXPathContextPtr ctxt = NULL;
|
||||||
|
ssize_t i, n;
|
||||||
|
xmlNodePtr *nodes = NULL;
|
||||||
|
|
||||||
|
if (!(xml = virXMLParseFileCtxt(capsFile, &ctxt)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) {
|
||||||
|
fprintf(stderr, "failed to parse qemu capabilities flags");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n > 0) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,8 +3,11 @@
|
|||||||
# include "capabilities.h"
|
# include "capabilities.h"
|
||||||
# include "domain_conf.h"
|
# include "domain_conf.h"
|
||||||
# include "qemu/qemu_command.h"
|
# include "qemu/qemu_command.h"
|
||||||
|
# include "qemu/qemu_capabilities.h"
|
||||||
|
|
||||||
virCapsPtr testQemuCapsInit(void);
|
virCapsPtr testQemuCapsInit(void);
|
||||||
virDomainXMLOptionPtr testQemuXMLConfInit(void);
|
virDomainXMLOptionPtr testQemuXMLConfInit(void);
|
||||||
extern qemuBuildCommandLineCallbacks testCallbacks;
|
extern qemuBuildCommandLineCallbacks testCallbacks;
|
||||||
|
|
||||||
|
virQEMUCapsPtr qemuTestParseCapabilities(const char *capsFile);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user