From 9d253e5e4b691af1deaa5022fd2ec01af0054a3e Mon Sep 17 00:00:00 2001 Message-Id: <9d253e5e4b691af1deaa5022fd2ec01af0054a3e@dist-git> From: Andrea Bolognani Date: Mon, 17 Sep 2018 18:00:48 +0200 Subject: [PATCH] tests: Reuse qemucapabilities data for qemucaps2xml While qemucaps2xml has a meager two test cases to its name, we have plenty of data from qemucapabilities which is taken from actual QEMU binaries, covers pretty much all supported QEMU versions and architectures and is even in the right format already! Rewrite qemucaps2xml so that it uses qemucapabilities data as input. Right now we have a single test case, but we're going to add a lot more next. Signed-off-by: Andrea Bolognani Reviewed-by: Jiri Denemark (cherry picked from commit 562990849a9de255b5fefa39be3f301b1bddfa6e) https://bugzilla.redhat.com/show_bug.cgi?id=1629862 Signed-off-by: Andrea Bolognani Reviewed-by: Jiri Denemark --- tests/qemucaps2xmldata/all_1.6.0-1.caps | 129 ------------------ .../nodisksnapshot_1.6.0-1.caps | 128 ----------------- .../nodisksnapshot_1.6.0-1.xml | 32 ----- .../caps_1.6.0.x86_64.xml} | 12 +- tests/qemucaps2xmltest.c | 33 +++-- 5 files changed, 23 insertions(+), 311 deletions(-) delete mode 100644 tests/qemucaps2xmldata/all_1.6.0-1.caps delete mode 100644 tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.caps delete mode 100644 tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.xml rename tests/{qemucaps2xmldata/all_1.6.0-1.xml => qemucaps2xmloutdata/caps_1.6.0.x86_64.xml} (67%) diff --git a/tests/qemucaps2xmldata/all_1.6.0-1.caps b/tests/qemucaps2xmldata/all_1.6.0-1.caps deleted file mode 100644 index d39d0bebbf..0000000000 --- a/tests/qemucaps2xmldata/all_1.6.0-1.caps +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.caps b/tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.caps deleted file mode 100644 index 5a0372c917..0000000000 --- a/tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.caps +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.xml b/tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.xml deleted file mode 100644 index 981344e6fd..0000000000 --- a/tests/qemucaps2xmldata/nodisksnapshot_1.6.0-1.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - i686 - - - - - - - hvm - - 32 - /usr/bin/qemu-system-i386 - - - /usr/bin/qemu-system-i386 - - - - - - - - - - - - - - diff --git a/tests/qemucaps2xmldata/all_1.6.0-1.xml b/tests/qemucaps2xmloutdata/caps_1.6.0.x86_64.xml similarity index 67% rename from tests/qemucaps2xmldata/all_1.6.0-1.xml rename to tests/qemucaps2xmloutdata/caps_1.6.0.x86_64.xml index efe86b9a12..b58f54fefd 100644 --- a/tests/qemucaps2xmldata/all_1.6.0-1.xml +++ b/tests/qemucaps2xmloutdata/caps_1.6.0.x86_64.xml @@ -2,7 +2,7 @@ - i686 + x86_64 @@ -10,12 +10,12 @@ hvm - - 32 - /usr/bin/qemu-system-i386 + + 64 + /usr/bin/qemu-system-x86_64 - /usr/bin/qemu-system-i386 + /usr/bin/qemu-system-x86_64 @@ -24,8 +24,6 @@ - - diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c index 5b9152b04d..65dd97c0a4 100644 --- a/tests/qemucaps2xmltest.c +++ b/tests/qemucaps2xmltest.c @@ -32,7 +32,7 @@ typedef struct _testQemuData testQemuData; typedef testQemuData *testQemuDataPtr; struct _testQemuData { const char *base; - virArch guestarch; + const char *archName; }; static virQEMUCapsPtr @@ -87,23 +87,28 @@ testGetCaps(char *capsData, const testQemuData *data) { virQEMUCapsPtr qemuCaps = NULL; virCapsPtr caps = NULL; + virArch arch = virArchFromString(data->archName); + char *binary = NULL; + + if (virAsprintf(&binary, "/usr/bin/qemu-system-%s", data->archName) < 0) + goto error; if ((qemuCaps = testQemuGetCaps(capsData)) == NULL) { fprintf(stderr, "failed to parse qemu capabilities flags"); goto error; } - if ((caps = virCapabilitiesNew(data->guestarch, false, false)) == NULL) { + if ((caps = virCapabilitiesNew(arch, false, false)) == NULL) { fprintf(stderr, "failed to create the fake capabilities"); goto error; } if (virQEMUCapsInitGuestFromBinary(caps, - "/usr/bin/qemu-system-i386", + binary, qemuCaps, NULL, NULL, - data->guestarch) < 0) { + arch) < 0) { fprintf(stderr, "failed to create the capabilities from qemu"); goto error; } @@ -114,6 +119,7 @@ testGetCaps(char *capsData, const testQemuData *data) error: virObjectUnref(qemuCaps); virObjectUnref(caps); + VIR_FREE(binary); return NULL; } @@ -127,12 +133,12 @@ testQemuCapsXML(const void *opaque) char *capsXml = NULL; virCapsPtr capsProvided = NULL; - if (virAsprintf(&xmlFile, "%s/qemucaps2xmldata/%s.xml", - abs_srcdir, data->base) < 0) + if (virAsprintf(&xmlFile, "%s/qemucaps2xmloutdata/%s.%s.xml", + abs_srcdir, data->base, data->archName) < 0) goto cleanup; - if (virAsprintf(&capsFile, "%s/qemucaps2xmldata/%s.caps", - abs_srcdir, data->base) < 0) + if (virAsprintf(&capsFile, "%s/qemucapabilitiesdata/%s.%s.xml", + abs_srcdir, data->base, data->archName) < 0) goto cleanup; if (virTestLoadFile(capsFile, &capsData) < 0) @@ -175,16 +181,13 @@ mymain(void) virEventRegisterDefaultImpl(); -#define DO_TEST_FULL(name, guest) \ +#define DO_TEST(arch, name) \ + data.archName = arch; \ data.base = name; \ - data.guestarch = guest; \ - if (virTestRun(name, testQemuCapsXML, &data) < 0) \ + if (virTestRun(name "(" arch ")", testQemuCapsXML, &data) < 0) \ ret = -1 -#define DO_TEST(name) DO_TEST_FULL(name, VIR_ARCH_I686) - - DO_TEST("all_1.6.0-1"); - DO_TEST("nodisksnapshot_1.6.0-1"); + DO_TEST("x86_64", "caps_1.6.0"); return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.19.1