From nobody Tue Mar 3 05:10:36 2026 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=1771921673; cv=none; d=zohomail.com; s=zohoarc; b=Cz/r3dJhM/5wMMLDwekSecDWCLLoQKo62p6gn1++lOzU62oIVdThctD8Vmb3ABt/w8PXv1ZUajJMRTWgaTIiiFsTblAFBQufBCkA4viHqp7/hB0jgJhBUi44YyP2hhnMOGSGXjWQVdN+y5kc2D0Dl2M/LyGI06Om0yU3apv4o+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771921673; 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=p1EvBG4ZOsuskyQk2IJ5WFUfr9gmL0pRH0VUzVf3JuA=; b=Vr5jmks9uUEfYUPw73DBGed1DEP62keAi7c1sUlaDmhx5xSbRrkbvBniRUlW4p1+qTU0xoeMHwIRp1x8f6puBe+6j/MOdzXMtuv00T6cDa1qr7U/2puWiFC+1KtAh2JLcMo8u9i5jhbgdnn9ZO+R6D8sBj4tlNQfzGpj+Gzyv7U= 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 1771921673651866.2884031703697; Tue, 24 Feb 2026 00:27:53 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id D06DB41C92; Tue, 24 Feb 2026 03:27:52 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id E83D741B8E; Tue, 24 Feb 2026 03:23:25 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 304FD41B69; Tue, 24 Feb 2026 03:22:51 -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 B141341B54 for ; Tue, 24 Feb 2026 03:22:50 -0500 (EST) Received: from mx-prod-mc-05.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-571-6dX7ZzYCMkqBIwEoi-Il3A-1; Tue, 24 Feb 2026 03:22:48 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28F5619560A6 for ; Tue, 24 Feb 2026 08:22:48 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.64.82]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C59071800465 for ; Tue, 24 Feb 2026 08:22:47 +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=-2.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,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=1771921370; 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=p1EvBG4ZOsuskyQk2IJ5WFUfr9gmL0pRH0VUzVf3JuA=; b=MnqKkhz+Jfq4oIwORcZ0e9GtBU+34Ne0F5fTBYppyInucFI90/K03C8HzDY7GcRXbwnU+R WDm2akEtveJhvf2fQzsC5mQ2/Zmkc6vHA0M3/3ZDs+5WU3Hc7Q9KTwcBAcI4zFexShSCuO qs2M7NBaZM70JlCnfQKqx0gz5+l9BAA= X-MC-Unique: 6dX7ZzYCMkqBIwEoi-Il3A-1 X-Mimecast-MFC-AGG-ID: 6dX7ZzYCMkqBIwEoi-Il3A_1771921368 To: devel@lists.libvirt.org Subject: [PATCH 7/8] tests: point $HOME and $XDG_* into usable fake root directory Date: Tue, 24 Feb 2026 03:22:41 -0500 Message-ID: <20260224082242.274009-8-laine@redhat.com> In-Reply-To: <20260224082242.274009-1-laine@redhat.com> References: <20260224082242.274009-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5gRBbBCGHqaSL3JPDP7RfshO2ORZZ_8eU1srzPNNd6M_1771921368 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ACNZCJQPJA77IET2AP4QNB33VC6AYTIL X-Message-ID-Hash: ACNZCJQPJA77IET2AP4QNB33VC6AYTIL X-MailFrom: laine@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: Laine Stump via Devel Reply-To: Laine Stump X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771921674373158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Laine Stump A long time ago we added some lines to "poison" the environment of test programs (specifically $HOME and $XDG_*) with nonexisting unusable paths so that any test program attempting to use the normal settings of those variables (which point into the filesystem of the system running the test) would fail (rather than silently messing up the test system). At some later time, someone wrote tests for hostdev devices that required that virGetUserRuntimeDirectory() (which normally uses either $XDG_RUNTIME_DIR or $HOME) return a directory that could actually be used as a part of the test; this was solved by mocking virGetUserRuntimeDirectory() to return a path underneath $LIBVIRT_FAKE_ROOT_DIR (which is created each time a test starts). Much much later, I wanted to add validation of the directory returned by virGetUserRuntimeDirectory(), but when this validation was added, the poisoned values that had been set (back in paragraph one "a long time ago") caused this validation to fail. My first attempt to fix this was to make the mocked virGetUserRuntimeDirectory() more generally available, and turn it on for all the tests that failed. But then I realized that a better solution would be to instead "nourish" (rather than "poison" - get it?) $HOME and $XDG_* with directories created under $LIBVIRT_FAKE_ROOT_DIR. This way we are actually testing the real virGetUserRuntimeDirectory() and any future validation, and also make some other tests cover more actual code in the future. In this patch the poisoning of the environment is removed, the call to the function creating the fake root dir is moved up to that location, and as a part of creating the fake root dir, we also set the aforementioned environment variables and create the directories associated with them (since the tests assume that they already exist). The now-redundant original mock of virGetUserRuntimeDirectory() will be removed in another patch. Signed-off-by: Laine Stump --- tests/testutils.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/tests/testutils.c b/tests/testutils.c index 814391b804..c984f66d0e 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -779,6 +779,20 @@ virTestSetEnvPath(void) =20 #define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX" =20 +static int +virTestFakeEnvSubDirInit(const char *envName, const char *fakeRootName, co= nst char *fakeSubDirName) +{ + g_autofree char *envVal =3D g_build_filename(fakeRootName, fakeSubDirN= ame, NULL); + + if (g_mkdir(envVal, 0777) < 0) { + fprintf(stderr, "Cannot create fake %s directory at %s", envName, = envVal); + return -1; + } + + g_setenv(envName, envVal, TRUE); + return 0; +} + char* virTestFakeRootDirInit(void) { @@ -791,6 +805,22 @@ virTestFakeRootDirInit(void) =20 g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE); =20 + /* the glib g_get_user_*_dir() functions use these environment variabl= es to + * determine locations for various data/log/config files. Setting them= here + * will assure that code under test that is using those directories wo= n't pollute + * the system under test. + */ + if (virTestFakeEnvSubDirInit("HOME", fakerootdir, "home") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_RUNTIME_DIR", fakerootdir, "user-run= time-dir") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_DATA_HOME", fakerootdir, "user-data-= home") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_CACHE_HOME", fakerootdir, "user-cach= e-home") < 0) + return NULL; + if (virTestFakeEnvSubDirInit("XDG_CONFIG_HOME", fakerootdir, "user-con= fig-home") < 0) + return NULL; + return g_steal_pointer(&fakerootdir); } =20 @@ -829,11 +859,8 @@ int virTestMain(int argc, preloads[npreloads] =3D NULL; } =20 - g_setenv("HOME", "/bad-test-used-env-home", TRUE); - g_setenv("XDG_RUNTIME_DIR", "/bad-test-used-env-xdg-runtime-dir", TRUE= ); - g_setenv("XDG_DATA_HOME", "/bad-test-used-env-xdg-data-home", TRUE); - g_setenv("XDG_CACHE_HOME", "/bad-test-used-env-xdg-cache-home", TRUE); - g_setenv("XDG_CONFIG_HOME", "/bad-test-used-env-xdg-config-home", TRUE= ); + if (!(fakerootdir =3D virTestFakeRootDirInit())) + return EXIT_FAILURE; =20 va_start(ap, func); while ((lib =3D va_arg(ap, const char *))) { @@ -907,9 +934,6 @@ int virTestMain(int argc, =20 failedTests =3D virBitmapNew(1); =20 - if (!(fakerootdir =3D virTestFakeRootDirInit())) - return EXIT_FAILURE; - ret =3D (func)(); =20 virResetLastError(); --=20 2.52.0