[PATCH v2 2/2] qemuxml2argvtest: Drop dependency between testInfoArgName and virQEMUCapsFlags enums

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Introduced in fdf6c89ee7b, this dependency looks weird. It was
needed because of the way that while() loop was written - it
fetches next argument in every iteration. Therefore, our only
option was for ARG_END to have the same value as QEMU_CAPS_LAST.
This also meant that QEMU_CAPS_* could have been only at the end
of the __VA_ARGS__.

This commit reworks the while() loop and removes the dependency.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/qemuxml2argvtest.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 4d6e4b0d39..0c0dcae197 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -616,19 +616,7 @@ typedef enum {
     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
-     * magic will give the va_args list:
-     *
-     *   ARG_QEMU_CAPS, NONE, QEMU_CAPS_LAST, ARG_END
-     *
-     * SetArgs consumes the first item, hands off control to virQEMUCapsX
-     * virQEMUCapsX sees NONE aka QEMU_CAPS_LAST, returns to SetArgs.
-     * SetArgs sees QEMU_CAPS_LAST aka ARG_END, and exits the parse loop.
-     * If ARG_END != QEMU_CAPS_LAST, this last step would generate an error.
-     */
-    ARG_END = QEMU_CAPS_LAST,
+    ARG_END,
 } testInfoArgName;
 
 static int
@@ -646,7 +634,8 @@ testInfoSetArgs(struct testInfo *info,
     int ret = -1;
 
     va_start(argptr, capslatest);
-    while ((argname = va_arg(argptr, testInfoArgName)) < ARG_END) {
+    argname = va_arg(argptr, testInfoArgName);
+    while (argname != ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
             if (qemuCaps || !(qemuCaps = virQEMUCapsNew()))
@@ -655,6 +644,22 @@ testInfoSetArgs(struct testInfo *info,
             while ((flag = va_arg(argptr, int)) < QEMU_CAPS_LAST)
                 virQEMUCapsSet(qemuCaps, flag);
 
+            /* Some tests are run with NONE capabilities, which is just
+             * another name for QEMU_CAPS_LAST. If that is the case the
+             * arguments look like this :
+             *
+             *   ARG_QEMU_CAPS, NONE, QEMU_CAPS_LAST, ARG_END
+             *
+             * Fetch one argument more and if it is QEMU_CAPS_LAST then
+             * break from the switch() to force getting next argument
+             * in the line. If it is not QEMU_CAPS_LAST then we've
+             * fetched real ARG_* and we must process it.
+             */
+            if ((flag = va_arg(argptr, int)) != QEMU_CAPS_LAST) {
+                argname = flag;
+                continue;
+            }
+
             break;
 
         case ARG_GIC:
@@ -690,6 +695,8 @@ testInfoSetArgs(struct testInfo *info,
             fprintf(stderr, "Unexpected test info argument");
             goto cleanup;
         }
+
+        argname = va_arg(argptr, testInfoArgName);
     }
 
     if (!!capsarch ^ !!capsver) {
-- 
2.19.2

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux