From nobody Sun Feb 8 07:59:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554137273566720.5601490067729; Mon, 1 Apr 2019 09:47:53 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6CD5059449; Mon, 1 Apr 2019 16:47:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 408855C28C; Mon, 1 Apr 2019 16:47:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 04377180338B; Mon, 1 Apr 2019 16:47:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x31Glc30026712 for ; Mon, 1 Apr 2019 12:47:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7D1605C27C; Mon, 1 Apr 2019 16:47:38 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-124-128.rdu2.redhat.com [10.10.124.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13E995C25A; Mon, 1 Apr 2019 16:47:37 +0000 (UTC) From: Cole Robinson To: libvirt-list@redhat.com Date: Mon, 1 Apr 2019 12:47:23 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/12] tests: Move testQemuInfo* to testutilsqemu X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 01 Apr 2019 16:47:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" So it can eventually be shared with qemuxml2xml Signed-off-by: Cole Robinson --- tests/qemuxml2argvtest.c | 173 --------------------------------------- tests/testutilsqemu.c | 144 ++++++++++++++++++++++++++++++++ tests/testutilsqemu.h | 39 +++++++++ 3 files changed, 183 insertions(+), 173 deletions(-) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index b87d2e3fb9..a51bdb2453 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -288,25 +288,6 @@ static virNWFilterDriver fakeNWFilterDriver =3D { .nwfilterBindingDelete =3D fakeNWFilterBindingDelete, }; =20 -typedef enum { - FLAG_EXPECT_FAILURE =3D 1 << 0, - FLAG_EXPECT_PARSE_ERROR =3D 1 << 1, - FLAG_FIPS =3D 1 << 2, - FLAG_REAL_CAPS =3D 1 << 3, - FLAG_SKIP_LEGACY_CPUS =3D 1 << 4, -} testQemuInfoFlags; - -struct testQemuInfo { - const char *name; - char *infile; - char *outfile; - virQEMUCapsPtr qemuCaps; - const char *migrateFrom; - int migrateFd; - unsigned int flags; - unsigned int parseFlags; -}; - =20 static int testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy) @@ -593,160 +574,6 @@ testCompareXMLToArgv(const void *data) return ret; } =20 -# define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata" - -typedef enum { - ARG_QEMU_CAPS, - ARG_GIC, - ARG_MIGRATE_FROM, - ARG_MIGRATE_FD, - ARG_FLAGS, - ARG_PARSEFLAGS, - ARG_CAPS_ARCH, - ARG_CAPS_VER, - ARG_END, -} testQemuInfoArgName; - -static int -testQemuInfoSetArgs(struct testQemuInfo *info, - virHashTablePtr capslatest, ...) -{ - va_list argptr; - testQemuInfoArgName argname; - virQEMUCapsPtr qemuCaps =3D NULL; - int gic =3D GIC_NONE; - char *capsarch =3D NULL; - char *capsver =3D NULL; - VIR_AUTOFREE(char *) capsfile =3D NULL; - int flag; - int ret =3D -1; - - va_start(argptr, capslatest); - argname =3D va_arg(argptr, testQemuInfoArgName); - while (argname !=3D ARG_END) { - switch (argname) { - case ARG_QEMU_CAPS: - if (qemuCaps || !(qemuCaps =3D virQEMUCapsNew())) - goto cleanup; - - while ((flag =3D 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 =3D va_arg(argptr, int)) !=3D QEMU_CAPS_LAST) { - argname =3D flag; - continue; - } - - break; - - case ARG_GIC: - gic =3D va_arg(argptr, int); - break; - - case ARG_MIGRATE_FROM: - info->migrateFrom =3D va_arg(argptr, char *); - break; - - case ARG_MIGRATE_FD: - info->migrateFd =3D va_arg(argptr, int); - break; - - case ARG_FLAGS: - info->flags =3D va_arg(argptr, int); - break; - - case ARG_PARSEFLAGS: - info->parseFlags =3D va_arg(argptr, int); - break; - - case ARG_CAPS_ARCH: - capsarch =3D va_arg(argptr, char *); - break; - - case ARG_CAPS_VER: - capsver =3D va_arg(argptr, char *); - break; - - case ARG_END: - default: - fprintf(stderr, "Unexpected test info argument"); - goto cleanup; - } - - argname =3D va_arg(argptr, testQemuInfoArgName); - } - - if (!!capsarch ^ !!capsver) { - fprintf(stderr, "ARG_CAPS_ARCH and ARG_CAPS_VER " - "must be specified together.\n"); - goto cleanup; - } - - if (qemuCaps && (capsarch || capsver)) { - fprintf(stderr, "ARG_QEMU_CAPS can not be combined with ARG_CAPS_A= RCH " - "or ARG_CAPS_VER\n"); - goto cleanup; - } - - if (!qemuCaps && capsarch && capsver) { - bool stripmachinealiases =3D false; - - if (STREQ(capsver, "latest")) { - if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) = < 0) - goto cleanup; - stripmachinealiases =3D true; - } else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml", - TEST_CAPS_PATH, capsver, capsarch) < 0) { - goto cleanup; - } - - if (!(qemuCaps =3D qemuTestParseCapabilitiesArch(virArchFromString= (capsarch), - capsfile))) { - goto cleanup; - } - - if (stripmachinealiases) - virQEMUCapsStripMachineAliases(qemuCaps); - info->flags |=3D FLAG_REAL_CAPS; - } - - if (!qemuCaps) { - fprintf(stderr, "No qemuCaps generated\n"); - goto cleanup; - } - VIR_STEAL_PTR(info->qemuCaps, qemuCaps); - - if (gic !=3D GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, gic) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - virObjectUnref(qemuCaps); - va_end(argptr); - - return ret; -} - -static void -testQemuInfoClear(struct testQemuInfo *info) -{ - VIR_FREE(info->infile); - VIR_FREE(info->outfile); - virObjectUnref(info->qemuCaps); -} - static int testInfoSetPaths(struct testQemuInfo *info, const char *suffix) { diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index dffe473944..6286c7b3c7 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -918,3 +918,147 @@ testQemuCapsIterate(const char *dirname, =20 return ret; } + + +#define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata" + +int +testQemuInfoSetArgs(struct testQemuInfo *info, + virHashTablePtr capslatest, ...) +{ + va_list argptr; + testQemuInfoArgName argname; + virQEMUCapsPtr qemuCaps =3D NULL; + int gic =3D GIC_NONE; + char *capsarch =3D NULL; + char *capsver =3D NULL; + VIR_AUTOFREE(char *) capsfile =3D NULL; + int flag; + int ret =3D -1; + + va_start(argptr, capslatest); + argname =3D va_arg(argptr, testQemuInfoArgName); + while (argname !=3D ARG_END) { + switch (argname) { + case ARG_QEMU_CAPS: + if (qemuCaps || !(qemuCaps =3D virQEMUCapsNew())) + goto cleanup; + + while ((flag =3D 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 =3D va_arg(argptr, int)) !=3D QEMU_CAPS_LAST) { + argname =3D flag; + continue; + } + + break; + + case ARG_GIC: + gic =3D va_arg(argptr, int); + break; + + case ARG_MIGRATE_FROM: + info->migrateFrom =3D va_arg(argptr, char *); + break; + + case ARG_MIGRATE_FD: + info->migrateFd =3D va_arg(argptr, int); + break; + + case ARG_FLAGS: + info->flags =3D va_arg(argptr, int); + break; + + case ARG_PARSEFLAGS: + info->parseFlags =3D va_arg(argptr, int); + break; + + case ARG_CAPS_ARCH: + capsarch =3D va_arg(argptr, char *); + break; + + case ARG_CAPS_VER: + capsver =3D va_arg(argptr, char *); + break; + + case ARG_END: + default: + fprintf(stderr, "Unexpected test info argument"); + goto cleanup; + } + + argname =3D va_arg(argptr, testQemuInfoArgName); + } + + if (!!capsarch ^ !!capsver) { + fprintf(stderr, "ARG_CAPS_ARCH and ARG_CAPS_VER " + "must be specified together.\n"); + goto cleanup; + } + + if (qemuCaps && (capsarch || capsver)) { + fprintf(stderr, "ARG_QEMU_CAPS can not be combined with ARG_CAPS_A= RCH " + "or ARG_CAPS_VER\n"); + goto cleanup; + } + + if (!qemuCaps && capsarch && capsver) { + bool stripmachinealiases =3D false; + + if (STREQ(capsver, "latest")) { + if (VIR_STRDUP(capsfile, virHashLookup(capslatest, capsarch)) = < 0) + goto cleanup; + stripmachinealiases =3D true; + } else if (virAsprintf(&capsfile, "%s/caps_%s.%s.xml", + TEST_CAPS_PATH, capsver, capsarch) < 0) { + goto cleanup; + } + + if (!(qemuCaps =3D qemuTestParseCapabilitiesArch(virArchFromString= (capsarch), + capsfile))) { + goto cleanup; + } + + if (stripmachinealiases) + virQEMUCapsStripMachineAliases(qemuCaps); + info->flags |=3D FLAG_REAL_CAPS; + } + + if (!qemuCaps) { + fprintf(stderr, "No qemuCaps generated\n"); + goto cleanup; + } + VIR_STEAL_PTR(info->qemuCaps, qemuCaps); + + if (gic !=3D GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, gic) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virObjectUnref(qemuCaps); + va_end(argptr); + + return ret; +} + + +void +testQemuInfoClear(struct testQemuInfo *info) +{ + VIR_FREE(info->infile); + VIR_FREE(info->outfile); + virObjectUnref(info->qemuCaps); +} diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 183ce915f1..f6ae2a38d3 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -32,6 +32,41 @@ enum { GIC_BOTH, }; =20 + +typedef enum { + ARG_QEMU_CAPS, + ARG_GIC, + ARG_MIGRATE_FROM, + ARG_MIGRATE_FD, + ARG_FLAGS, + ARG_PARSEFLAGS, + ARG_CAPS_ARCH, + ARG_CAPS_VER, + ARG_END, +} testQemuInfoArgName; + + +typedef enum { + FLAG_EXPECT_FAILURE =3D 1 << 0, + FLAG_EXPECT_PARSE_ERROR =3D 1 << 1, + FLAG_FIPS =3D 1 << 2, + FLAG_REAL_CAPS =3D 1 << 3, + FLAG_SKIP_LEGACY_CPUS =3D 1 << 4, +} testQemuInfoFlags; + + +struct testQemuInfo { + const char *name; + char *infile; + char *outfile; + virQEMUCapsPtr qemuCaps; + const char *migrateFrom; + int migrateFd; + unsigned int flags; + unsigned int parseFlags; +}; + + virCapsPtr testQemuCapsInit(void); virDomainXMLOptionPtr testQemuXMLConfInit(void); =20 @@ -71,6 +106,10 @@ int testQemuCapsIterate(const char *dirname, testQemuCapsIterateCallback callback, void *opaque); =20 +int testQemuInfoSetArgs(struct testQemuInfo *info, + virHashTablePtr capslatest, ...); +void testQemuInfoClear(struct testQemuInfo *info); + # endif =20 #endif /* LIBVIRT_TESTUTILSQEMU_H */ --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list