]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests/domaincaps: Move most of DO_TEST_QEMU() into a function
authorAndrea Bolognani <abologna@redhat.com>
Tue, 22 Oct 2019 14:27:21 +0000 (16:27 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Thu, 24 Oct 2019 15:21:22 +0000 (17:21 +0200)
Macros become less and less appealing the more work you perform
inside them: DO_TEST_QEMU() has arguably already crossed that
threshold, and we're going to add even more code later on.

While factoring the code out of the macro, convert it to use the
GLib string manipulation functions and take advantage of autofree.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
tests/domaincapstest.c

index f38f5fb0477a7d9dbba1bd1669fdc4a64675a270..e35eddc659755d04d9b33d6fd0b604ae38909433 100644 (file)
@@ -266,6 +266,36 @@ test_virDomainCapsFormat(const void *opaque)
     return ret;
 }
 
+static int
+doTestQemu(const char *partialName,
+           const char *capsName,
+           const char *emulator,
+           const char *machine,
+           const char *arch,
+           virDomainVirtType type,
+           void *opaque)
+{
+    g_autofree char *name = NULL;
+
+    name = g_strdup_printf("qemu_%s.%s", partialName, arch);
+
+    struct testData data = {
+        .name = name,
+        .emulator = emulator,
+        .machine = machine,
+        .arch = arch,
+        .type = type,
+        .capsType = CAPS_QEMU,
+        .capsName = capsName,
+        .capsOpaque = opaque,
+    };
+
+    if (virTestRun(name, test_virDomainCapsFormat, &data) < 0)
+        return -1;
+
+    return 0;
+}
+
 static int
 mymain(void)
 {
@@ -298,26 +328,8 @@ mymain(void)
 
 #define DO_TEST_QEMU(Name, CapsName, Emulator, Machine, Arch, Type) \
     do { \
-        char *name = NULL; \
-        if (virAsprintf(&name, "qemu_%s.%s", \
-                        Name, \
-                        Arch) < 0) { \
+        if (doTestQemu(Name, CapsName, Emulator, Machine, Arch, Type, cfg) < 0) \
             ret = -1; \
-            break; \
-        } \
-        struct testData data = { \
-            .name = name, \
-            .emulator = Emulator, \
-            .machine = Machine, \
-            .arch = Arch, \
-            .type = Type, \
-            .capsType = CAPS_QEMU, \
-            .capsName = CapsName, \
-            .capsOpaque = cfg, \
-        }; \
-        if (virTestRun(name, test_virDomainCapsFormat, &data) < 0) \
-            ret = -1; \
-        VIR_FREE(name); \
     } while (0)
 
 #define DO_TEST_LIBXL(Name, Emulator, Machine, Arch, Type) \