qemuxml2argvtest: Drop dependency between testInfoArgName and virQEMUCapsFlags enums

Introduced in fdf6c89ee7, 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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Michal Privoznik 2019-03-27 17:30:44 +01:00
parent 087a74e160
commit 97b729effe

View File

@ -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) {