From nobody Fri Nov 21 10:09:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1763628243; cv=none; d=zohomail.com; s=zohoarc; b=SxbryWKbRZsfxZFQmZy/ygoGI2icCukSpBxsrf7Q0UVvC1URgMIkzipYyw6jfKywB3YefmbRa9WCLYh34ZzZmdyhpOszMHiBEn0K1xNjDu2cCploWZg8Sg3Wx+GdKjoP2XGzF7jhNuEnQZPrN+B5FJEyXqqX+ql3ahLWCGFjsbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1763628243; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=ulW22UllAUbzuXpF9WisbdQWGrDJF9xaEeOX83sAImw=; b=kRvp5RxFOdx7SHFhSBKoWRdIct8AJdcq13f/I56EW75FFOsMn/8gVS16uBJbGKR2TlEDaIa4shaUhRbVF/4wtexQoAnewfAlImFFJzOFHdIf/Uo5/kgryVaXxLbMnDOcjl0/iUv7U1bPlHRvlA9I+/oczjGicm1+O+M8WFc3XLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1763628243404880.4752071647669; Thu, 20 Nov 2025 00:44:03 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id B94E941ABD; Thu, 20 Nov 2025 03:44:02 -0500 (EST) Received: from [172.19.199.53] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id CBFBD4460B; Thu, 20 Nov 2025 03:37:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1202541BEB; Thu, 20 Nov 2025 03:33:10 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3C12041C09 for ; Thu, 20 Nov 2025 03:33:09 -0500 (EST) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-JOAyXZlPNpuIjrJ06nTOaA-1; Thu, 20 Nov 2025 03:33:07 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BD3AF1956096 for ; Thu, 20 Nov 2025 08:33:06 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2259918004A3 for ; Thu, 20 Nov 2025 08:33:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763627588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ulW22UllAUbzuXpF9WisbdQWGrDJF9xaEeOX83sAImw=; b=RWGpxFDkODxEo/NsK168toBLGrRpceOt3GHpGuywUIiEanM32Gng3GrmfRz8codoJMkyNt IXx2FJB0ddq79bWZON/yyOxKEs7Yg8YK/SU0j65qJ1LYeyfpmQM4/XgWrNpWJKrACJZNkM v9bCf4WECgqxjDIhpwYkWvQoALc61bw= X-MC-Unique: JOAyXZlPNpuIjrJ06nTOaA-1 X-Mimecast-MFC-AGG-ID: JOAyXZlPNpuIjrJ06nTOaA_1763627586 To: devel@lists.libvirt.org Subject: [PATCH 7/9] vmx2xmltest: Drop custom file name parse function Date: Thu, 20 Nov 2025 09:32:52 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lOFspa4LT4_vG00vt9AWESp1en3oeHRhup-WhnFqRgU_1763627586 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BNR23RDTYZ4ZKGMP63WVANTN4I4Q6J4V X-Message-ID-Hash: BNR23RDTYZ4ZKGMP63WVANTN4I4Q6J4V X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1763628244227018900 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik Having a custom file name parsing function in vmx2xml that's different to the one used in production (esxParseVMXFileName()) might have served us well, but it also defeats the point of having a unit test. More specifically, if there's a bug in esxParseVMXFileName() then our unit test would not catch it. But now that we have vmx2xmlmock the custom parsing function can be dropped and the test can use the real one. Signed-off-by: Michal Privoznik --- tests/meson.build | 2 +- tests/vmx2xmltest.c | 61 +++++++-------------------------------------- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index 9adf172b7f..cd53e48aa4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -550,7 +550,7 @@ endif =20 if conf.has('WITH_VMX') tests +=3D [ - { 'name': 'vmx2xmltest' }, + { 'name': 'vmx2xmltest', 'include': [ esx_inc_dir ], 'link_with': [ es= x_lib ] }, { 'name': 'xml2vmxtest' }, ] mock_libs +=3D [ diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index bcd95ed87d..cb8e04af0d 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -8,6 +8,8 @@ =20 # include "internal.h" # include "vmx/vmx.h" +# define LIBVIRT_ESX_DRIVERPRIV_H_ALLOW +# include "esx_driverpriv.h" =20 # define VIR_FROM_THIS VIR_FROM_VMWARE =20 @@ -104,60 +106,12 @@ testCompareHelper(const void *data) return ret; } =20 -static int -testParseVMXFileName(const char *fileName, - void *opaque G_GNUC_UNUSED, - char **src, - bool allow_missing) -{ - g_autofree char *copyOfFileName =3D NULL; - char *tmp =3D NULL; - char *saveptr =3D NULL; - char *datastoreName =3D NULL; - char *directoryAndFileName =3D NULL; - - *src =3D NULL; - - if (STRPREFIX(fileName, "/vmfs/volumes/")) { - /* Found absolute path referencing a file inside a datastore */ - copyOfFileName =3D g_strdup(fileName); - - /* Expected format: '/vmfs/volumes//' */ - if ((tmp =3D STRSKIP(copyOfFileName, "/vmfs/volumes/")) =3D=3D NUL= L || - (datastoreName =3D strtok_r(tmp, "/", &saveptr)) =3D=3D NULL || - (directoryAndFileName =3D strtok_r(NULL, "", &saveptr)) =3D=3D= NULL) { - return -1; - } - - if (STREQ(datastoreName, "missing") || - STRPREFIX(directoryAndFileName, "missing")) { - if (allow_missing) - return 0; - - virReportError(VIR_ERR_INTERNAL_ERROR, - "Referenced missing file '%s'", fileName); - return -1; - } - - *src =3D g_strdup_printf("[%s] %s", datastoreName, directoryAndFil= eName); - } else if (STRPREFIX(fileName, "/")) { - /* Found absolute path referencing a file outside a datastore */ - *src =3D g_strdup(fileName); - } else if (strchr(fileName, '/') !=3D NULL) { - /* Found relative path, this is not supported */ - return -1; - } else { - /* Found single file name referencing a file inside a datastore */ - *src =3D g_strdup_printf("[datastore] directory/%s", fileName); - } - - return 0; -} =20 static int mymain(void) { int ret =3D 0; + esxVMX_Data data =3D { 0 }; =20 # define DO_TEST_FULL(file, should_fail) \ do { \ @@ -180,8 +134,10 @@ mymain(void) if (!(xmlopt =3D virVMXDomainXMLConfInit(caps))) return EXIT_FAILURE; =20 - ctx.opaque =3D NULL; - ctx.parseFileName =3D testParseVMXFileName; + data.datastorePathWithoutFileName =3D (char*) "[datastore] directory"; + + ctx.opaque =3D &data; + ctx.parseFileName =3D esxParseVMXFileName; ctx.formatFileName =3D NULL; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; @@ -296,7 +252,8 @@ mymain(void) return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("vmx2xml")) =20 #else =20 --=20 2.51.0