From nobody Wed Dec 4 09:10:13 2024 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; 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=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 1715685050737833.356421624299; Tue, 14 May 2024 04:10:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6DA3A167; Tue, 14 May 2024 07:10:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 64FD01A4B; Tue, 14 May 2024 07:10:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BB94F19EE; Tue, 14 May 2024 07:09:58 -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 1CA2B1A42 for ; Tue, 14 May 2024 07:09:58 -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-252-QGoaIMZSNEiGhsa0vCtRBQ-1; Tue, 14 May 2024 07:09:40 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 B28093813BC9 for ; Tue, 14 May 2024 11:09:40 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CFEE400EAC for ; Tue, 14 May 2024 11:09:40 +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: QGoaIMZSNEiGhsa0vCtRBQ-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH] tests: Link some mocks with libtest_qemu_driver.so Date: Tue, 14 May 2024 13:06:18 +0200 Message-ID: <866b8a4192e973cb04dca4a374516b4c5073eb61.1715684595.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LASSCOPB56YRVMVM5RMGT7RRDYV3SKBD X-Message-ID-Hash: LASSCOPB56YRVMVM5RMGT7RRDYV3SKBD 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 X-ZM-MESSAGEID: 1715685052487100001 Content-Type: text/plain; charset="utf-8"; x-default="true" I've noticed some tests fail to run under valgrind with the following error: $ valgrind --leak-check=3Dfull --trace-children=3Dyes ./qemuxmlconftest valgrind: symbol lookup error: libvirt.git/_build/tests/libdomaincapsmock= .so: undefined symbol: virQEMUCapsGet But without valgrind the test passes just fine. While we usually don't want to change our code just to adhere to random tools, in this case we ought to make an exception because valgrind helps us to detect memory leaks. NB, the --trace-children=3Dyes is needed whenever a test re-executes itself, i.e. when it uses mocks. Otherwise we'd just get (boring) result for the first invocation of main() which does nothing more than sets up the environment and calls exec(). When running the test binary without valgrind I can see the libtest_qemu_driver.so being loaded even after exec: $ LD_DEBUG=3Dlibs ./qemuxmlconftest 2>&1 | grep -e libtest_qemu_driver.so -= e virQEMUCapsGet 6439: find library=3Dlibtest_qemu_driver.so [0]; searching 6439: trying file=3Dlibvirt.git/_build/tests/../src/libtest_qem= u_driver.so 6439: trying file=3Dlibvirt.git/_build/tests/glibc-hwcaps/x86-6= 4-v3/libtest_qemu_driver.so 6439: trying file=3Dlibvirt.git/_build/tests/glibc-hwcaps/x86-6= 4-v2/libtest_qemu_driver.so 6439: trying file=3Dlibvirt.git/_build/tests/libtest_qemu_drive= r.so 6439: calling init: libvirt.git/_build/tests/libtest_qemu_driver.= so 6439: find library=3Dlibtest_qemu_driver.so [0]; searching 6439: trying file=3Dlibvirt.git/_build/tests/libtest_qemu_drive= r.so 6439: calling init: libvirt.git/_build/tests/libtest_qemu_driver.= so 6439: calling fini: libvirt.git/_build/tests/libtest_qemu_driver.= so [0] But running the same under valgrind: $ LD_DEBUG=3Dlibs valgrind --leak-check=3Dfull --trace-children=3Dyes ./qem= uxmlconftest 2>&1 | grep -e libtest_qemu_driver.so -e virQEMUCapsGet 6515: find library=3Dlibtest_qemu_driver.so [0]; searching 6515: trying file=3Dlibvirt.git/_build/tests/../src/libtest_qem= u_driver.so 6515: trying file=3Dlibvirt.git/_build/tests/glibc-hwcaps/x86-6= 4-v3/libtest_qemu_driver.so 6515: trying file=3Dlibvirt.git/_build/tests/glibc-hwcaps/x86-6= 4-v2/libtest_qemu_driver.so 6515: trying file=3Dlibvirt.git/_build/tests/libtest_qemu_drive= r.so 6515: calling init: libvirt.git/_build/tests/libtest_qemu_driver.= so 6515: libvirt.git/_build/tests/libdomaincapsmock.so: error: symbo= l lookup error: undefined symbol: virQEMUCapsGet (fatal) valgrind: symbol lookup error: libvirt.git/_build/tests/libdomaincapsmock.s= o: undefined symbol: virQEMUCapsGet To me, it looks like valgrind forced linker to lookup symbols "sooner", as individual libraries are loaded. But I must admit I have no idea how valgrind does that (or if that's even valgrind's 'fault'). But fix is pretty simple: link mocks that rely on symbols from the QEMU driver with the QEMU driver, well, its test suite suitable version (libtest_qemu_driver.so). Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- This obsoletes some patches I've sent earlier: https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/RM5= 6P5RDBYCVYQVKHOFFKUZ2B276NQD3/ https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/ZB4= 444UO5VF3FBL2ARDLCRX3DSU3LAEN/ My initial fix was bothering me as I did not understand what was happening nor why it made the valgrind happy. I still don't quite understand what is going on, but at least this fix seems 'more correct'. tests/meson.build | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index ba2d319347..2f1eda1f95 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -73,7 +73,6 @@ endif # * deps - additional dependencies (optional, default []) =20 mock_libs =3D [ - { 'name': 'domaincapsmock' }, { 'name': 'vircgroupmock' }, { 'name': 'virdnsmasqmock' }, { 'name': 'virfilecachemock' }, @@ -175,7 +174,7 @@ if conf.has('WITH_QEMU') { 'name': 'qemucaps2xmlmock' }, { 'name': 'qemucapsprobemock', 'link_with': [ test_qemu_driver_lib ] }, { 'name': 'qemucpumock' }, - { 'name': 'qemuhotplugmock', 'link_with': [ test_utils_qemu_lib, test_= utils_lib ] }, + { 'name': 'qemuhotplugmock', 'link_with': [ test_qemu_driver_lib, test= _utils_qemu_lib, test_utils_lib ] }, { 'name': 'qemuxml2argvmock' }, { 'name': 'virhostidmock' }, ] @@ -185,6 +184,11 @@ else test_utils_qemu_monitor_lib =3D [] endif =20 +mock_libs +=3D [ + # domaincapsmock has some code guarded with WITH_QEMU + { 'name': 'domaincapsmock', 'link_with': [ test_qemu_driver_lib ] }, +] + test_file_wrapper_lib =3D static_library( 'test_file_wrapper', [ 'virfilewrapper.c' ], --=20 2.43.2