tests: qemuxml2argv: move DO_CAPS_TEST* qemuCaps init

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

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2019-03-14 08:47:32 -04:00
parent 710990ec41
commit bb66ff2677

View File

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