]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: qemuxml2argv: add va_arg enum handling
authorCole Robinson <crobinso@redhat.com>
Wed, 13 Mar 2019 22:25:21 +0000 (18:25 -0400)
committerCole Robinson <crobinso@redhat.com>
Thu, 21 Mar 2019 16:43:01 +0000 (12:43 -0400)
This establishes a pattern that will allow us to make test macros
more general purpose, by taking optional arguments. The general
format will be:

DO_TEST_FULL(...
             ARG_FOO, <value1>,
             ARG_BAR, <value2>)

ARG_X are just enum values that we look for in the va_args and know
how to interpret.

Implement this for the existing implicit qemuCaps va_args

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
tests/qemuxml2argvtest.c

index a540e762fac9a90c037cd5754926c51b79466f55..4cb967595bbca6ffd1010cc3847d22bb135e6b52 100644 (file)
@@ -624,14 +624,47 @@ testCompareXMLToArgv(const void *data)
     return ret;
 }
 
+typedef enum {
+    ARG_QEMU_CAPS,
+
+    /* 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,
+} testInfoArgName;
+
 static int
 testInfoSetArgs(struct testInfo *info, ...)
 {
     va_list argptr;
-    int ret = 0;
+    testInfoArgName argname;
+    int ret = -1;
 
     va_start(argptr, info);
-    virQEMUCapsSetVAList(info->qemuCaps, argptr);
+    while ((argname = va_arg(argptr, testInfoArgName)) < ARG_END) {
+        switch (argname) {
+        case ARG_QEMU_CAPS:
+            virQEMUCapsSetVAList(info->qemuCaps, argptr);
+            break;
+
+        case ARG_END:
+        default:
+            fprintf(stderr, "Unexpected test info argument");
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
     va_end(argptr);
 
     return ret;
@@ -822,7 +855,8 @@ mymain(void)
         }; \
         if (testInitQEMUCaps(&info, gic) < 0) \
             return EXIT_FAILURE; \
-        if (testInfoSetArgs(&info, __VA_ARGS__, QEMU_CAPS_LAST) < 0) \
+        if (testInfoSetArgs(&info, ARG_QEMU_CAPS, \
+                            __VA_ARGS__, QEMU_CAPS_LAST, ARG_END) < 0) \
             return EXIT_FAILURE; \
         if (virTestRun("QEMU XML-2-ARGV " name, \
                        testCompareXMLToArgv, &info) < 0) \