From nobody Mon Feb 9 09:08:30 2026 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 1702646139031360.5202209574629; Fri, 15 Dec 2023 05:15:39 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id EEE411A3F; Fri, 15 Dec 2023 08:15:37 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BFE031A7E; Fri, 15 Dec 2023 07:36:34 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DAC7119C1; Fri, 15 Dec 2023 07:34:54 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 51CE61A93 for ; Fri, 15 Dec 2023 07:33:48 -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-604-l4DEOo-SMwO6o_YCT_Urow-1; Fri, 15 Dec 2023 07:33:46 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 6AD7E101326C for ; Fri, 15 Dec 2023 12:33:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id E662D1C060B1 for ; Fri, 15 Dec 2023 12:33:45 +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_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: l4DEOo-SMwO6o_YCT_Urow-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 19/19] qemuxml2argvtest: Add checker that all input files are used Date: Fri, 15 Dec 2023 13:33:29 +0100 Message-ID: <406ff40a9416860e4ca069dc856b9ae288706f13.1702643447.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: CJDQ6TNQXWO3EDHF7JG4NQWXSTR3OUFK X-Message-ID-Hash: CJDQ6TNQXWO3EDHF7JG4NQWXSTR3OUFK 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: 1702646141413100001 To prevent regressions when refactoring tests and accidentally forgotten input files make sure that qemuxml2argvtest is invoked for all input files in tests/qemuxml2argvdata Signed-off-by: Peter Krempa --- tests/qemustatusxml2xmltest.c | 2 +- tests/qemuxml2argvtest.c | 63 ++++++++++++++++++++++++++++++++++- tests/testutils.c | 14 ++++++++ tests/testutils.h | 2 ++ tests/testutilsqemu.h | 1 + 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/tests/qemustatusxml2xmltest.c b/tests/qemustatusxml2xmltest.c index 4796b62853..f60378c691 100644 --- a/tests/qemustatusxml2xmltest.c +++ b/tests/qemustatusxml2xmltest.c @@ -73,7 +73,7 @@ mymain(void) { int ret =3D 0; g_autoptr(virConnect) conn =3D NULL; - struct testQemuConf testConf =3D { NULL, NULL, NULL, NULL }; + struct testQemuConf testConf =3D { NULL, NULL, NULL, NULL, NULL }; if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 48ee433495..0ae6700d95 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -621,6 +621,9 @@ testCompareXMLToArgv(const void *data) virArch arch =3D VIR_ARCH_NONE; g_autoptr(virIdentity) sysident =3D virIdentityGetSystem(); + /* mark test case as used */ + ignore_value(g_hash_table_remove(info->conf->existingTestCases, info->= infile)); + if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0) goto cleanup; @@ -809,22 +812,76 @@ testInfoSetPaths(struct testQemuInfo *info, abs_srcdir, info->name, suffix ? suf= fix : ""); } + +static int +testConfXMLCheck(GHashTable *existingTestCases) +{ + g_autofree virHashKeyValuePair *items =3D virHashGetItems(existingTest= Cases, NULL, true); + size_t i; + int ret =3D 0; + + for (i =3D 0; items[i].key; i++) { + if (ret =3D=3D 0) + fprintf(stderr, "\n"); + + fprintf(stderr, "unused input file: %s\n", (const char *) items[i]= .key); + ret =3D -1; + } + + return ret; +} + + +static int +testConfXMLEnumerate(GHashTable *existingTestCases) +{ + struct dirent *ent; + g_autoptr(DIR) dir =3D NULL; + int rc; + + /* If VIR_TEST_RANGE is in use don't bother filling in the data, which + * also makes testConfXMLCheck succeed. */ + if (virTestHasRangeBitmap()) + return 0; + + if (virDirOpen(&dir, abs_srcdir "/qemuxml2argvdata") < 0) + return -1; + + while ((rc =3D virDirRead(dir, &ent, abs_srcdir "/qemuxml2argvdata")) = > 0) { + if (virStringHasSuffix(ent->d_name, ".xml")) { + g_hash_table_insert(existingTestCases, + g_strdup_printf(abs_srcdir "/qemuxml2argvd= ata/%s", ent->d_name), + NULL); + } + } + + return rc; +} + + static int mymain(void) { int ret =3D 0; g_autoptr(GHashTable) duplicateTests =3D virHashNew(NULL); + g_autoptr(GHashTable) existingTestCases =3D virHashNew(NULL); g_autoptr(GHashTable) capslatest =3D testQemuGetLatestCaps(); g_autoptr(GHashTable) qapiSchemaCache =3D virHashNew((GDestroyNotify) = g_hash_table_unref); g_autoptr(GHashTable) capscache =3D virHashNew(virObjectUnref); struct testQemuConf testConf =3D { .capslatest =3D capslatest, .capscache =3D capscache, .qapiSchemaCache =3D qapiSchemaCache, - .duplicateTests =3D duplicateTests }; + .duplicateTests =3D duplicateTests, + .existingTestCases =3D existingTestCa= ses }; if (!capslatest) return EXIT_FAILURE; + /* enumerate and store all available test cases to verify at the end t= hat + * all of them were invoked */ + if (testConfXMLEnumerate(existingTestCases) < 0) + return EXIT_FAILURE; + /* Set the timezone because we are mocking the time() function. * If we don't do that, then localtime() may return unpredictable * results. In order to detect things that just work by a blind @@ -2592,6 +2649,10 @@ mymain(void) DO_TEST_CAPS_LATEST("tap-vhost-incorrect"); DO_TEST_CAPS_LATEST("tap-vhost"); + /* check that all input files were actually used here */ + if (testConfXMLCheck(existingTestCases) < 0) + ret =3D -1; + qemuTestDriverFree(&driver); virFileWrapperClearPrefixes(); diff --git a/tests/testutils.c b/tests/testutils.c index e546422941..b20e447b99 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -746,6 +746,20 @@ virTestGetRegenerate(void) return testRegenerate; } + +/** + * virTestHasRangeBitmap: + * + * Returns whether the test was invoked with VIR_TEST_RANGE declared thus + * limiting the run only on specific test cases. + */ +bool +virTestHasRangeBitmap(void) +{ + return !!testBitmap; +} + + static int virTestSetEnvPath(void) { diff --git a/tests/testutils.h b/tests/testutils.h index cf8a346dff..bb84327b1e 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -82,6 +82,8 @@ unsigned int virTestGetExpensive(void); unsigned int virTestGetRegenerate(void); void virTestPropagateLibvirtError(void); +bool virTestHasRangeBitmap(void); + #define VIR_TEST_DEBUG(fmt, ...) \ do { \ if (virTestGetDebug()) \ diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 71e220de3a..0d570ec31e 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -70,6 +70,7 @@ struct testQemuConf { GHashTable *capslatest; GHashTable *qapiSchemaCache; GHashTable *duplicateTests; /* for checking duplicated invocations */ + GHashTable *existingTestCases; /* for checking missing invocations */ }; typedef enum { --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org