[libvirt PATCH 4/5] tests: introduce testVirNetDevBandwidthParse

Ján Tomko jtomko at redhat.com
Fri Aug 20 13:15:31 UTC 2021


The 'PARSE' macro does not use '#' or '##' directives,
or anything from outside of the macro other than the
cleanup label.

Turn it into a function.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 tests/virnetdevbandwidthtest.c   | 44 ++++++++++++++++----------------
 tests/virnetdevopenvswitchtest.c | 44 ++++++++++++++++----------------
 2 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c
index 197d936479..a17737ec40 100644
--- a/tests/virnetdevbandwidthtest.c
+++ b/tests/virnetdevbandwidthtest.c
@@ -39,27 +39,26 @@ struct testSetStruct {
     const bool hierarchical_class;
 };
 
-#define PARSE(xml, var) \
-    do { \
-        int rc; \
-        g_autoptr(xmlDoc) doc = NULL; \
-        g_autoptr(xmlXPathContext) ctxt = NULL; \
- \
-        if (!xml) \
-            break; \
- \
-        if (!(doc = virXMLParseStringCtxt((xml), \
-                                          "bandwidth definition", \
-                                          &ctxt))) \
-            goto cleanup; \
- \
-        rc = virNetDevBandwidthParse(&(var), \
-                                     NULL, \
-                                     ctxt->node, \
-                                     true); \
-        if (rc < 0) \
-            goto cleanup; \
-    } while (0)
+static int
+testVirNetDevBandwidthParse(virNetDevBandwidth **var,
+                            const char *xml)
+{
+    g_autoptr(xmlDoc) doc = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
+
+    if (!xml)
+        return 0;
+
+    if (!(doc = virXMLParseStringCtxt((xml),
+                                      "bandwidth definition",
+                                      &ctxt)))
+        return -1;
+
+    return virNetDevBandwidthParse(var,
+                                   NULL,
+                                   ctxt->node,
+                                   true);
+}
 
 static int
 testVirNetDevBandwidthSet(const void *data)
@@ -72,7 +71,8 @@ testVirNetDevBandwidthSet(const void *data)
     g_autofree char *actual_cmd = NULL;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
-    PARSE(info->band, band);
+    if (testVirNetDevBandwidthParse(&band, info->band) < 0)
+        return -1;
 
     if (!iface)
         iface = "eth0";
diff --git a/tests/virnetdevopenvswitchtest.c b/tests/virnetdevopenvswitchtest.c
index 89ffc1e4b5..1026c890cd 100644
--- a/tests/virnetdevopenvswitchtest.c
+++ b/tests/virnetdevopenvswitchtest.c
@@ -45,27 +45,26 @@ struct testClearQosStruct {
     const unsigned char *vmid;
 };
 
-#define PARSE(xml, var) \
-    do { \
-        int rc; \
-        g_autoptr(xmlDoc) doc = NULL; \
-        g_autoptr(xmlXPathContext) ctxt = NULL; \
- \
-        if (!xml) \
-            break; \
- \
-        if (!(doc = virXMLParseStringCtxt((xml), \
-                                          "bandwidth definition", \
-                                          &ctxt))) \
-            goto cleanup; \
- \
-        rc = virNetDevBandwidthParse(&(var), \
-                                     NULL, \
-                                     ctxt->node, \
-                                     true); \
-        if (rc < 0) \
-            goto cleanup; \
-    } while (0)
+static int
+testVirNetDevBandwidthParse(virNetDevBandwidth **var,
+                            const char *xml)
+{
+    g_autoptr(xmlDoc) doc = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
+
+    if (!xml)
+        return 0;
+
+    if (!(doc = virXMLParseStringCtxt((xml),
+                                      "bandwidth definition",
+                                      &ctxt)))
+        return -1;
+
+    return virNetDevBandwidthParse(var,
+                                   NULL,
+                                   ctxt->node,
+                                   true);
+}
 
 static const unsigned char vm_id[VIR_UUID_BUFLEN] = "fakeuuid";
 
@@ -161,7 +160,8 @@ testVirNetDevOpenvswitchInterfaceSetQos(const void *data)
     g_autofree char *actual_cmd = NULL;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
-    PARSE(info->band, band);
+    if (testVirNetDevBandwidthParse(&band, info->band) < 0)
+        return -1;
 
     if (!iface)
         iface = "tap-fake";
-- 
2.31.1




More information about the libvir-list mailing list