From nobody Wed Jan 15 09:29:05 2025 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1704730976183241.4550991345086; Mon, 8 Jan 2024 08:22:56 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1F50C1AA6; Mon, 8 Jan 2024 11:22:55 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 51CF91890; Mon, 8 Jan 2024 11:07:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id E70721A1F; Mon, 8 Jan 2024 11:06:12 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 51F7619AE for ; Mon, 8 Jan 2024 11:06:06 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-1OS_7fjUMROKonD0OPQP9A-1; Mon, 08 Jan 2024 11:06:04 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEC3E85A589 for ; Mon, 8 Jan 2024 16:06:03 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68816C15E6A for ; Mon, 8 Jan 2024 16:06:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 1OS_7fjUMROKonD0OPQP9A-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 08/23] qemu*xml2*test: Invoke tests from a function Date: Mon, 8 Jan 2024 17:05:38 +0100 Message-ID: <06fa7fa58fe2cd79f2201cbd356882f2ac9bb5b7.1704729291.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 5JJGEHDI6KWFYFDNZAEXCZUO3DUMZ36Y X-Message-ID-Hash: 5JJGEHDI6KWFYFDNZAEXCZUO3DUMZ36Y X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1704730976880100001 Refactor the code so that the test macros invoke a helper function with no additional steps. This change prevents regressions in compilation time when adding extra steps for the tests, which happen when the test macro gets too complicated. Signed-off-by: Peter Krempa --- tests/qemuxml2argvtest.c | 48 ++++++++++++++++++++++----------------- tests/qemuxml2xmltest.c | 47 +++++++++++++++++++++++++------------- tests/qemuxmlactivetest.c | 35 +++++++++++++++++----------- tests/testutilsqemu.c | 10 +++----- tests/testutilsqemu.h | 6 ++--- 5 files changed, 86 insertions(+), 60 deletions(-) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 09ba2647ae..e1a75cdd10 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -811,18 +811,6 @@ testCompareXMLToArgv(const void *data) return ret; } -static void -testInfoSetPaths(testQemuInfo *info, - const char *suffix) -{ - info->infile =3D g_strdup_printf("%s/qemuxml2argvdata/%s.xml", - abs_srcdir, info->name); - info->outfile =3D g_strdup_printf("%s/qemuxml2argvdata/%s%s.args", - abs_srcdir, info->name, suffix ? suffi= x : ""); - info->errfile =3D g_strdup_printf("%s/qemuxml2argvdata/%s%s.err", - abs_srcdir, info->name, suffix ? suf= fix : ""); -} - static int testConfXMLCheck(GHashTable *existingTestCases) @@ -870,6 +858,32 @@ testConfXMLEnumerate(GHashTable *existingTestCases) } +static void +testRun(const char *name, + const char *suffix, + int *ret, + struct testQemuConf *testConf, + ...) +{ + g_autofree char *testname =3D g_strdup_printf("QEMU XML-2-ARGV %s%s", = name, suffix); + g_autoptr(testQemuInfo) info =3D g_new0(testQemuInfo, 1); + va_list ap; + + info->name =3D name; + info->conf =3D testConf; + + va_start(ap, testConf); + testQemuInfoSetArgs(info, ap); + va_end(ap); + + info->infile =3D g_strdup_printf("%s/qemuxml2argvdata/%s.xml", abs_src= dir, info->name); + info->outfile =3D g_strdup_printf("%s/qemuxml2argvdata/%s%s.args", abs= _srcdir, info->name, suffix); + info->errfile =3D g_strdup_printf("%s/qemuxml2argvdata/%s%s.err", abs_= srcdir, info->name, suffix); + + virTestRunLog(ret, testname, testCompareXMLToArgv, info); +} + + static int mymain(void) { @@ -940,15 +954,7 @@ mymain(void) * version. */ # define DO_TEST_FULL(_name, _suffix, ...) \ - do { \ - static testQemuInfo info =3D { \ - .name =3D _name, \ - }; \ - testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__); \ - testInfoSetPaths(&info, _suffix); \ - virTestRunLog(&ret, "QEMU XML-2-ARGV " _name _suffix, testCompareX= MLToArgv, &info); \ - testQemuInfoClear(&info); \ - } while (0) + testRun(_name, _suffix, &ret, &testConf, __VA_ARGS__); # define DO_TEST_CAPS_INTERNAL(name, arch, ver, ...) \ DO_TEST_FULL(name, "." arch "-" ver, \ diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index b4fcd87df8..2e384e76aa 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -107,6 +107,34 @@ testInfoSetPaths(testQemuInfo *info, } +static void +testRun(const char *name, + const char *suffix, + struct testQemuConf *testConf, + int *ret, + ...) +{ + g_autofree char *name_active =3D g_strdup_printf("QEMU XML-2-XML-activ= e %s", name); + g_autofree char *name_inactive =3D g_strdup_printf("QEMU XML-2-XML-ina= ctive %s", name); + g_autoptr(testQemuInfo) info =3D g_new0(testQemuInfo, 1); + va_list ap; + + info->name =3D name; + info->conf =3D testConf; + + va_start(ap, ret); + testQemuInfoSetArgs(info, ap); + va_end(ap); + + + testInfoSetPaths(info, suffix, "inactive"); + virTestRunLog(ret, name_inactive, testXML2XMLInactive, info); + + testInfoSetPaths(info, suffix, "active"); + virTestRunLog(ret, name_active, testXML2XMLActive, info); +} + + static int mymain(void) { @@ -147,22 +175,9 @@ mymain(void) virSetConnectStorage(conn); #define DO_TEST_CAPS_INTERNAL(_name, arch, ver, ...) \ - do { \ - static testQemuInfo info =3D { \ - .name =3D _name, \ - }; \ - testQemuInfoSetArgs(&info, &testConf, \ - ARG_CAPS_ARCH, arch, \ - ARG_CAPS_VER, ver, \ - __VA_ARGS__, ARG_END); \ - \ - testInfoSetPaths(&info, "." arch "-" ver, "inactive"); \ - virTestRunLog(&ret, "QEMU XML-2-XML-inactive " _name, testXML2XMLI= nactive, &info); \ - \ - testInfoSetPaths(&info, "." arch "-" ver, "active"); \ - virTestRunLog(&ret, "QEMU XML-2-XML-active " _name, testXML2XMLAct= ive, &info); \ - testQemuInfoClear(&info); \ - } while (0) + testRun(_name, "." arch "-" ver, &testConf, &ret, \ + ARG_CAPS_ARCH, arch, ARG_CAPS_VER, ver, \ + __VA_ARGS__, ARG_END); #define DO_TEST_CAPS_ARCH_LATEST_FULL(name, arch, ...) \ DO_TEST_CAPS_INTERNAL(name, arch, "latest", __VA_ARGS__) diff --git a/tests/qemuxmlactivetest.c b/tests/qemuxmlactivetest.c index 9224bd5d05..65431863bd 100644 --- a/tests/qemuxmlactivetest.c +++ b/tests/qemuxmlactivetest.c @@ -60,11 +60,30 @@ testCompareStatusXMLToXMLFiles(const void *opaque) static const char *statusPath =3D abs_srcdir "/qemustatusxml2xmldata/"; -static void -testInfoSetStatusPaths(testQemuInfo *info) + +static int +testRunStatus(const char *name, + struct testQemuConf *testConf, + ...) { + const char *testname =3D g_strdup_printf("QEMU status XML-2-XML %s", n= ame); + g_autoptr(testQemuInfo) info =3D g_new0(testQemuInfo, 1); + va_list ap; + + info->name =3D name; + info->conf =3D testConf; + + va_start(ap, testConf); + testQemuInfoSetArgs(info, ap); + va_end(ap); + info->infile =3D g_strdup_printf("%s%s-in.xml", statusPath, info->name= ); info->outfile =3D g_strdup_printf("%s%s-out.xml", statusPath, info->na= me); + + if (virTestRun(testname, testCompareStatusXMLToXMLFiles, info) < 0) + return -1; + + return 0; } @@ -90,20 +109,10 @@ mymain(void) #define DO_TEST_STATUS(_name) \ do { \ - static testQemuInfo info =3D { \ - .name =3D _name, \ - }; \ - testQemuInfoSetArgs(&info, &testConf, ARG_END); \ - testInfoSetStatusPaths(&info); \ -\ - if (virTestRun("QEMU status XML-2-XML " _name, \ - testCompareStatusXMLToXMLFiles, &info) < 0) \ + if (testRunStatus(_name, &testConf, ARG_END) < 0) \ ret =3D -1; \ -\ - testQemuInfoClear(&info); \ } while (0) - DO_TEST_STATUS("blockjob-mirror"); DO_TEST_STATUS("vcpus-multi"); DO_TEST_STATUS("modern"); diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index cf4ef3a317..3799c2eb51 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -624,16 +624,13 @@ testQemuCapsIterate(const char *suffix, void testQemuInfoSetArgs(testQemuInfo *info, - struct testQemuConf *conf, ...) + va_list argptr) { - va_list argptr; testQemuInfoArgName argname; int flag; - info->conf =3D conf; info->args.newargs =3D true; - va_start(argptr, conf); while ((argname =3D va_arg(argptr, testQemuInfoArgName)) !=3D ARG_END)= { switch (argname) { case ARG_QEMU_CAPS: @@ -748,8 +745,6 @@ testQemuInfoSetArgs(testQemuInfo *info, if (info->args.invalidarg) break; } - - va_end(argptr); } @@ -959,7 +954,7 @@ testQemuInfoInitArgs(testQemuInfo *info) void -testQemuInfoClear(testQemuInfo *info) +testQemuInfoFree(testQemuInfo *info) { VIR_FREE(info->infile); VIR_FREE(info->outfile); @@ -970,6 +965,7 @@ testQemuInfoClear(testQemuInfo *info) g_clear_pointer(&info->args.fds, g_hash_table_unref); g_clear_object(&info->nbdkitCaps); g_clear_pointer(&info->args.fakeNbdkitCaps, virBitmapFree); + g_free(info); } diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index c9c36d24c6..9343457f59 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -115,6 +115,8 @@ struct _testQemuInfo { }; typedef struct _testQemuInfo testQemuInfo; +void testQemuInfoFree(testQemuInfo *info); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(testQemuInfo, testQemuInfoFree); virDomainXMLOption *testQemuXMLConfInit(void); @@ -153,10 +155,8 @@ int testQemuCapsIterate(const char *suffix, void *opaque); void testQemuInfoSetArgs(testQemuInfo *info, - struct testQemuConf *conf, - ...); + va_list argptr); int testQemuInfoInitArgs(testQemuInfo *info); -void testQemuInfoClear(testQemuInfo *info); int testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev, virDomainChrSourceDef *chardev, --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org