diff mbox series

[v2,2/4] tests: qemuxml2argv: move DO_CAPS_TEST* qemuCaps init

Message ID 3591f921f167335d5d3cfe3fd9d97c246af9d515.1553197802.git.crobinso@redhat.com
State Accepted
Commit bb66ff2677ee4fbc1f0d5885d667b0f0adc23b2c
Headers show
Series tests: qemuxml2argv: support optional arguments | expand

Commit Message

Cole Robinson March 21, 2019, 7:55 p.m. UTC
Move DO_CAPS_TEST* qemuCaps init and all the associated setup
into testInfoSetArgs, adding ARG_CAPS_ARCH and ARG_CAPS_VER
options and using those to build the capsfile path locally

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

---
 tests/qemuxml2argvtest.c | 69 +++++++++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 22 deletions(-)

-- 
2.21.0

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

Comments

Andrea Bolognani March 22, 2019, 9:13 a.m. UTC | #1
On Thu, 2019-03-21 at 15:55 -0400, Cole Robinson wrote:
[...]
> +        if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(capsarch),

> +                                                       capsfile)))

> +            goto cleanup;


I'd put curly brackets around the body here.

[...]
> +        if (testInfoSetArgs(&info, capslatest, \

> +                            ARG_CAPS_ARCH, arch, \

> +                            ARG_CAPS_VER, ver, \

> +                            __VA_ARGS__, ARG_END) < 0) \


I'd put ARG_END on its own line both here...

[...]
> +        if (testInfoSetArgs(&info, capslatest, \

> +                            __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \


... and here.


Regardless of whether or not you decide to make those tweaks,

  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 d982a497a9..191a43726d 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -605,6 +605,8 @@  testCompareXMLToArgv(const void *data)
     return ret;
 }
 
+# define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata"
+
 typedef enum {
     ARG_QEMU_CAPS,
     ARG_GIC,
@@ -612,6 +614,8 @@  typedef enum {
     ARG_MIGRATE_FD,
     ARG_FLAGS,
     ARG_PARSEFLAGS,
+    ARG_CAPS_ARCH,
+    ARG_CAPS_VER,
 
     /* ARG_END is our va_args sentinel. The value QEMU_CAPS_LATEST is
      * necessary to handle the DO_TEST(..., NONE) case, which through macro
@@ -628,15 +632,19 @@  typedef enum {
 } testInfoArgName;
 
 static int
-testInfoSetArgs(struct testInfo *info, ...)
+testInfoSetArgs(struct testInfo *info,
+                virHashTablePtr capslatest, ...)
 {
     va_list argptr;
     testInfoArgName argname;
     virQEMUCapsPtr qemuCaps = NULL;
     int gic = GIC_NONE;
+    char *capsarch = NULL;
+    char *capsver = NULL;
+    VIR_AUTOFREE(char *) capsfile = NULL;
     int ret = -1;
 
-    va_start(argptr, info);
+    va_start(argptr, capslatest);
     while ((argname = va_arg(argptr, testInfoArgName)) < ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
@@ -665,6 +673,14 @@  testInfoSetArgs(struct testInfo *info, ...)
             info->parseFlags = va_arg(argptr, int);
             break;
 
+        case ARG_CAPS_ARCH:
+            capsarch = va_arg(argptr, char *);
+            break;
+
+        case ARG_CAPS_VER:
+            capsver = va_arg(argptr, char *);
+            break;
+
         case ARG_END:
         default:
             fprintf(stderr, "Unexpected test info argument");
@@ -672,13 +688,32 @@  testInfoSetArgs(struct testInfo *info, ...)
         }
     }
 
-    if (!info->qemuCaps) {
-        if (!qemuCaps) {
-            fprintf(stderr, "No qemuCaps generated\n");
+    if (!qemuCaps && capsarch && capsver) {
+        bool stripmachinealiases = false;
+
+        if (STREQ(capsver, "latest")) {
+            if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) < 0)
+                goto cleanup;
+            stripmachinealiases = true;
+        } else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml",
+                               TEST_CAPS_PATH, capsver, capsarch) < 0) {
             goto cleanup;
         }
-        VIR_STEAL_PTR(info->qemuCaps, qemuCaps);
+
+        if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(capsarch),
+                                                       capsfile)))
+            goto cleanup;
+
+        if (stripmachinealiases)
+            virQEMUCapsStripMachineAliases(qemuCaps);
+        info->flags |= FLAG_REAL_CAPS;
+    }
+
+    if (!qemuCaps) {
+        fprintf(stderr, "No qemuCaps generated\n");
+        goto cleanup;
     }
+    VIR_STEAL_PTR(info->qemuCaps, qemuCaps);
 
     if (gic != GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
         goto cleanup;
@@ -819,28 +854,17 @@  mymain(void)
  * the test cases should be forked using DO_TEST_CAPS_VER with the appropriate
  * version.
  */
-# define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata"
-
 # define DO_TEST_CAPS_INTERNAL(_name, arch, ver, ...) \
     do { \
         static struct testInfo info = { \
             .name = _name, \
             .suffix = "." arch "-" ver, \
         }; \
-        static const char *capsfile = TEST_CAPS_PATH "/caps_" ver "." arch ".xml"; \
-        static bool stripmachinealiases; \
-        if (STREQ(ver, "latest")) { \
-            capsfile = virHashLookup(capslatest, arch); \
-            stripmachinealiases = true; \
-        } \
-        if (!(info.qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(arch), \
-                                                            capsfile))) \
-            return EXIT_FAILURE; \
-        if (stripmachinealiases) \
-            virQEMUCapsStripMachineAliases(info.qemuCaps); \
-        if (testInfoSetArgs(&info, __VA_ARGS__, ARG_END) < 0) \
+        if (testInfoSetArgs(&info, capslatest, \
+                            ARG_CAPS_ARCH, arch, \
+                            ARG_CAPS_VER, ver, \
+                            __VA_ARGS__, ARG_END) < 0) \
             return EXIT_FAILURE; \
-        info.flags |= FLAG_REAL_CAPS; \
         if (virTestRun("QEMU XML-2-ARGV " _name "." arch "-" ver, \
                        testCompareXMLToArgv, &info) < 0) \
             ret = -1; \
@@ -876,7 +900,8 @@  mymain(void)
         static struct testInfo info = { \
             .name = _name, \
         }; \
-        if (testInfoSetArgs(&info, __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \
+        if (testInfoSetArgs(&info, capslatest, \
+                            __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \
             return EXIT_FAILURE; \
         if (virTestRun("QEMU XML-2-ARGV " _name, \
                        testCompareXMLToArgv, &info) < 0) \