From nobody Fri May 17 11:05:16 2024 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 1712324504744373.82946650432166; Fri, 5 Apr 2024 06:41:44 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7BB521735; Fri, 5 Apr 2024 09:41:43 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D85FE1A4C; Fri, 5 Apr 2024 09:39:45 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DCFF1195F; Fri, 5 Apr 2024 09:39:36 -0400 (EDT) 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 E50151966 for ; Fri, 5 Apr 2024 09:39:35 -0400 (EDT) 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-zgOvmnu3OdK5alHyk6OQbg-1; Fri, 05 Apr 2024 09:39:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 B8CD4101A532 for ; Fri, 5 Apr 2024 13:39:33 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 639963C85 for ; Fri, 5 Apr 2024 13:39:33 +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.7 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 autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: zgOvmnu3OdK5alHyk6OQbg-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 1/2] tests: mock: Accept spaces in build path Date: Fri, 5 Apr 2024 15:39:30 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: SDX46H4CEKMI3IJBNU2MRNSWUVIYXFHV X-Message-ID-Hash: SDX46H4CEKMI3IJBNU2MRNSWUVIYXFHV X-MailFrom: mprivozn@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"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1712324506856100001 If path to the build directory contains spaces (e.g. meson setup 'a b') then our mocks don't work. The problem is in glibc where not just a colon but also a space character is a delimiter for LD_PRELOAD [1]. Hence, a test using mock tries to preload something like libvirt.git/a b/libsomethingmock.so which is interpreted by glibc as two separate strings: "libvirt.git/a", "b/libsomethingmock.so". One trick to get around this is to set LD_PRELOAD to just the shared object file (without path) and let glibc find the mock in paths specified in LD_LIBRARY_PATH (where only a colon or a semicolon are valid separators [1]). This can be seen in action by running say: LD_DEBUG=3Dlibs ./virpcitest 1: https://man7.org/linux/man-pages/man8/ld.so.8.html Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/securityselinuxlabeltest.c | 2 +- tests/securityselinuxtest.c | 2 +- tests/testutils.c | 6 ++++-- tests/testutils.h | 12 +++++++++++- tests/viridentitytest.c | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabelt= est.c index 04bffe4356..7b7cf53569 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -347,4 +347,4 @@ mymain(void) =20 VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("domaincaps"), - abs_builddir "/libsecurityselinuxhelper.so") + "libsecurityselinuxhelper.so") diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c index 6a0f1617ae..6aadc6154f 100644 --- a/tests/securityselinuxtest.c +++ b/tests/securityselinuxtest.c @@ -332,4 +332,4 @@ mymain(void) return (ret =3D=3D 0) ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/libsecurityselinuxhelper.so") +VIR_TEST_MAIN_PRELOAD(mymain, "libsecurityselinuxhelper.so") diff --git a/tests/testutils.c b/tests/testutils.c index 8d4e7f84bf..3c5c298293 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -837,8 +837,10 @@ int virTestMain(int argc, =20 va_start(ap, func); while ((lib =3D va_arg(ap, const char *))) { - if (!virFileIsExecutable(lib)) { - perror(lib); + g_autofree char *abs_lib_path =3D g_strdup_printf("%s/%s", abs_bui= lddir, lib); + + if (!virFileIsExecutable(abs_lib_path)) { + perror(abs_lib_path); va_end(ap); return EXIT_FAILURE; } diff --git a/tests/testutils.h b/tests/testutils.h index bb84327b1e..e5469c5aa0 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -123,11 +123,13 @@ int virTestMain(int argc, =20 #ifdef __APPLE__ # define PRELOAD_VAR "DYLD_INSERT_LIBRARIES" +# define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH" # define FORCE_FLAT_NAMESPACE \ g_setenv("DYLD_FORCE_FLAT_NAMESPACE", "1", TRUE); # define MOCK_EXT ".dylib" #else # define PRELOAD_VAR "LD_PRELOAD" +# define LD_LIBRARY_PATH "LD_LIBRARY_PATH" # define FORCE_FLAT_NAMESPACE # define MOCK_EXT ".so" #endif @@ -137,12 +139,20 @@ int virTestMain(int argc, const char *preload =3D getenv(PRELOAD_VAR); \ if (preload =3D=3D NULL || strstr(preload, libs) =3D=3D NULL) { \ char *newenv; \ + char *new_library_path; \ + const char *cur_library_path =3D g_getenv(LD_LIBRARY_PATH); \ if (!preload) { \ newenv =3D (char *) libs; \ } else { \ newenv =3D g_strdup_printf("%s:%s", libs, preload); \ } \ + if (!cur_library_path) { \ + new_library_path =3D (char *) abs_builddir; \ + } else { \ + new_library_path =3D g_strdup_printf("%s:%s", abs_builddir= , cur_library_path); \ + } \ g_setenv(PRELOAD_VAR, newenv, TRUE); \ + g_setenv(LD_LIBRARY_PATH, new_library_path, TRUE); \ FORCE_FLAT_NAMESPACE \ execv(argv[0], argv); \ } \ @@ -153,7 +163,7 @@ int virTestMain(int argc, return virTestMain(argc, argv, func, __VA_ARGS__, NULL); \ } =20 -#define VIR_TEST_MOCK(mock) (abs_builddir "/lib" mock "mock" MOCK_EXT) +#define VIR_TEST_MOCK(mock) ("lib" mock "mock" MOCK_EXT) =20 virCaps *virTestGenericCapsInit(void); virCapsHostNUMA *virTestCapsBuildNUMATopology(int seq); diff --git a/tests/viridentitytest.c b/tests/viridentitytest.c index 73ed9f73df..74e3a03619 100644 --- a/tests/viridentitytest.c +++ b/tests/viridentitytest.c @@ -162,7 +162,7 @@ mymain(void) } =20 #if WITH_SELINUX -VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/libsecurityselinuxhelper.so") +VIR_TEST_MAIN_PRELOAD(mymain, "libsecurityselinuxhelper.so") #else VIR_TEST_MAIN(mymain) #endif --=20 2.43.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org From nobody Fri May 17 11:05:16 2024 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 1712324458169791.3423855538565; Fri, 5 Apr 2024 06:40:58 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0B3871995; Fri, 5 Apr 2024 09:40:57 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3C087199A; Fri, 5 Apr 2024 09:39:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AD799195F; Fri, 5 Apr 2024 09:39:36 -0400 (EDT) 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 3F7AB1947 for ; Fri, 5 Apr 2024 09:39:36 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-khVAW-lxMTG3fZexmzy-eQ-1; Fri, 05 Apr 2024 09:39:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 4D09C38143B8 for ; Fri, 5 Apr 2024 13:39:34 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBF903C54 for ; Fri, 5 Apr 2024 13:39:33 +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.7 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 autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: khVAW-lxMTG3fZexmzy-eQ-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH 2/2] tests: Allow spaces in path to virt-aa-helper Date: Fri, 5 Apr 2024 15:39:31 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: U6JEDYDS3RHWOKIZTSDQMVPSC5N7EBBJ X-Message-ID-Hash: U6JEDYDS3RHWOKIZTSDQMVPSC5N7EBBJ X-MailFrom: mprivozn@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"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1712324458534100001 The virt-aa-helper bash script constructs a path to itself when it runs. But it isn't prepared for the case when there is a space in the path leading to the script (something, something, double quotes, something). Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- tests/virt-aa-helper-test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/virt-aa-helper-test b/tests/virt-aa-helper-test index 9a97168330..4c8d31c9d7 100755 --- a/tests/virt-aa-helper-test +++ b/tests/virt-aa-helper-test @@ -130,9 +130,9 @@ testme() { echo "': " >$output set +e if [ -n "$input" ]; then - LD_LIBRARY_PATH=3D"$ld_library_path" $exe $extra_args $args < $inp= ut >"$tmpout" 2>&1 + LD_LIBRARY_PATH=3D"$ld_library_path" "${exe}" $extra_args $args < = $input >"$tmpout" 2>&1 else - LD_LIBRARY_PATH=3D"$ld_library_path" $exe $extra_args $args >"$tmp= out" 2>&1 + LD_LIBRARY_PATH=3D"$ld_library_path" "${exe}" $extra_args $args >"= $tmpout" 2>&1 fi rc=3D"$?" cat "$tmpout" >"$output" --=20 2.43.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org