]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
tests: Move qemu caps XML parsing into shared unit
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 27 Jun 2014 14:39:27 +0000 (16:39 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Jul 2014 10:22:37 +0000 (12:22 +0200)
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>
tests/qemucapabilitiestest.c
tests/testutilsqemu.c
tests/testutilsqemu.h

index a2914606f7a8810cfefb65a6181fea99c8b6fd5f..4e5f9e5296b0f404fd86ba688e6e5c344e78dcc6 100644 (file)
@@ -85,55 +85,6 @@ testQemuFeedMonitor(char *replies,
     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
 testQemuCapsCompare(virQEMUCapsPtr capsProvided,
                     virQEMUCapsPtr capsComputed)
@@ -166,7 +117,7 @@ testQemuCaps(const void *opaque)
     int ret = -1;
     const testQemuData *data = opaque;
     char *repliesFile = NULL, *capsFile = NULL;
-    char *replies = NULL, *caps = NULL;
+    char *replies = NULL;
     qemuMonitorTestPtr mon = NULL;
     virQEMUCapsPtr capsProvided = NULL, capsComputed = NULL;
 
@@ -176,14 +127,13 @@ testQemuCaps(const void *opaque)
                     abs_srcdir, data->base) < 0)
         goto cleanup;
 
-    if (virtTestLoadFile(repliesFile, &replies) < 0 ||
-        virtTestLoadFile(capsFile, &caps) < 0)
+    if (virtTestLoadFile(repliesFile, &replies) < 0)
         goto cleanup;
 
     if (!(mon = testQemuFeedMonitor(replies, data->xmlopt)))
         goto cleanup;
 
-    if (!(capsProvided = testQemuGetCaps(caps)))
+    if (!(capsProvided = qemuTestParseCapabilities(capsFile)))
         goto cleanup;
 
     if (!(capsComputed = virQEMUCapsNew()))
@@ -207,7 +157,6 @@ testQemuCaps(const void *opaque)
     VIR_FREE(repliesFile);
     VIR_FREE(capsFile);
     VIR_FREE(replies);
-    VIR_FREE(caps);
     qemuMonitorTestFree(mon);
     virObjectUnref(capsProvided);
     virObjectUnref(capsComputed);
index 7e24909beefd5caa936e51eeab22518398fbbf25..85f03560a9305939c4bc213cbb4f25f504ee5fe4 100644 (file)
@@ -373,4 +373,53 @@ testSCSIDeviceGetSgName(const char *sysfs_prefix ATTRIBUTE_UNUSED,
 qemuBuildCommandLineCallbacks testCallbacks = {
     .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
index f01b722d7cfaddd6a4fad6a9c126264f64aa46f8..79ee1434c2c37c1fa5b267eeb5ce5dd0ef662571 100644 (file)
@@ -3,8 +3,11 @@
 # include "capabilities.h"
 # include "domain_conf.h"
 # include "qemu/qemu_command.h"
+# include "qemu/qemu_capabilities.h"
 
 virCapsPtr testQemuCapsInit(void);
 virDomainXMLOptionPtr testQemuXMLConfInit(void);
 extern qemuBuildCommandLineCallbacks testCallbacks;
+
+virQEMUCapsPtr qemuTestParseCapabilities(const char *capsFile);
 #endif