Doing a load, copy, format cycle on all QEMU capabilities XML files should make sure we don't forget to update virQEMUCapsNewCopy when adding new elements to QEMU capabilities. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 8 ++++++-- src/qemu/qemu_capabilities.h | 1 - src/qemu/qemu_capspriv.h | 2 ++ tests/qemucapabilitiestest.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6c80d59..43e3ea7 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2864,8 +2864,12 @@ virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename, goto cleanup; } - /* Don't check for NULL, since it is optional and thus may be missing */ - qemuCaps->package = virXPathString("string(./package)", ctxt); + if (virXPathBoolean("boolean(./package)", ctxt) > 0) { + qemuCaps->package = virXPathString("string(./package)", ctxt); + if (!qemuCaps->package && + VIR_STRDUP(qemuCaps->package, "") < 0) + goto cleanup; + } if (!(str = virXPathString("string(./arch)", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index e083d61..d249e2e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -384,7 +384,6 @@ typedef struct _virQEMUCapsCache virQEMUCapsCache; typedef virQEMUCapsCache *virQEMUCapsCachePtr; virQEMUCapsPtr virQEMUCapsNew(void); -virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps); int virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, qemuMonitorPtr mon); diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 647aafa..aeb1293 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -37,6 +37,8 @@ struct _virQEMUCapsCache { gid_t runGid; }; +virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps); + virQEMUCapsPtr virQEMUCapsNewForBinaryInternal(const char *binary, const char *libDir, diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index b98f775..4f1e5a5 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -77,6 +77,50 @@ testQemuCaps(const void *opaque) return ret; } + +static int +testQemuCapsCopy(const void *opaque) +{ + int ret = -1; + const testQemuData *data = opaque; + char *capsFile = NULL; + virCapsPtr caps = NULL; + virQEMUCapsPtr orig = NULL; + virQEMUCapsPtr copy = NULL; + char *actual = NULL; + + if (virAsprintf(&capsFile, "%s/qemucapabilitiesdata/%s.%s.xml", + abs_srcdir, data->base, data->archName) < 0) + goto cleanup; + + if (!(caps = virCapabilitiesNew(virArchFromString(data->archName), + false, false))) + goto cleanup; + + if (!(orig = qemuTestParseCapabilities(capsFile))) + goto cleanup; + + if (!(copy = virQEMUCapsNewCopy(orig))) + goto cleanup; + + if (!(actual = virQEMUCapsFormatCache(copy, 0, 0))) + goto cleanup; + + if (virTestCompareToFile(actual, capsFile) < 0) + goto cleanup; + + ret = 0; + + cleanup: + VIR_FREE(capsFile); + virObjectUnref(caps); + virObjectUnref(orig); + virObjectUnref(copy); + VIR_FREE(actual); + return ret; +} + + static int mymain(void) { @@ -103,6 +147,9 @@ mymain(void) data.base = name; \ if (virTestRun(name "(" arch ")", testQemuCaps, &data) < 0) \ ret = -1; \ + if (virTestRun("copy " name "(" arch ")", \ + testQemuCapsCopy, &data) < 0) \ + ret = -1; \ } while (0) DO_TEST("x86_64", "caps_1.2.2"); -- 2.9.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list