diff mbox series

[19/21] tests: qemuxml2argv: move DO_TEST qemuCaps init

Message ID e620ded0d73a7e452e047474840d52ee4d9a5a8d.1552574299.git.crobinso@redhat.com
State Accepted
Commit 320a1480d0dbe77ae9da08b6ce6c3ad5e2706b63
Headers show
Series tests: qemuxml2argv: support optional arguments | expand

Commit Message

Cole Robinson March 14, 2019, 2:44 p.m. UTC
Move DO_TEST* qemuCaps init into testInfoSetArgs. This is a step
towards unifying the different test macro implementations

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 tests/qemuxml2argvtest.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Andrea Bolognani March 19, 2019, 2:55 p.m. UTC | #1
On Thu, 2019-03-14 at 10:44 -0400, Cole Robinson wrote:
[...]
> +    if (gic && testQemuCapsSetGIC(info->qemuCaps, gic) < 0)

> +        goto cleanup;


Please change the first part of the condition to 'gic != GIC_NONE'
so that it doesn't implicitly rely on the actual value.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>


-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 813871d6b8..ff74892944 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -621,19 +621,21 @@  testInfoSetArgs(struct testInfo *info, ...)
 {
     va_list argptr;
     testInfoArgNames argname;
+    virQEMUCapsPtr qemuCaps = NULL;
+    int gic = GIC_NONE;
     int ret = -1;
 
     va_start(argptr, info);
     while ((argname = va_arg(argptr, int)) < ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
-            virQEMUCapsSetVList(info->qemuCaps, argptr);
+            if (qemuCaps || !(qemuCaps = virQEMUCapsNew()))
+                goto cleanup;
+            virQEMUCapsSetVList(qemuCaps, argptr);
             break;
 
         case ARG_GIC:
-            if (testQemuCapsSetGIC(info->qemuCaps,
-                                   va_arg(argptr, int)) < 0)
-                goto cleanup;
+            gic = va_arg(argptr, int);
             break;
 
         case ARG_MIGRATE_FROM:
@@ -659,8 +661,20 @@  testInfoSetArgs(struct testInfo *info, ...)
         }
     }
 
+    if (!info->qemuCaps) {
+        if (!qemuCaps) {
+            fprintf(stderr, "No qemuCaps generated\n");
+            goto cleanup;
+        }
+        VIR_STEAL_PTR(info->qemuCaps, qemuCaps);
+    }
+
+    if (gic && testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
+        goto cleanup;
+
     ret = 0;
  cleanup:
+    virObjectUnref(qemuCaps);
     va_end(argptr);
     return ret;
 }
@@ -851,8 +865,6 @@  mymain(void)
         static struct testInfo info = { \
             .name = _name, \
         }; \
-        if (!(info.qemuCaps = virQEMUCapsNew())) \
-            return EXIT_FAILURE; \
         if (testInfoSetArgs(&info, __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \
             return EXIT_FAILURE; \
         if (virTestRun("QEMU XML-2-ARGV " _name, \