From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 35EC63858020 for ; Fri, 17 Dec 2021 21:07:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 35EC63858020 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-73-YXcLHKcNO3OJ4aHqK6OW9g-1; Fri, 17 Dec 2021 16:07:51 -0500 X-MC-Unique: YXcLHKcNO3OJ4aHqK6OW9g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0DF7804328; Fri, 17 Dec 2021 21:07:43 +0000 (UTC) Received: from greed.delorie.com (ovpn-112-7.rdu2.redhat.com [10.10.112.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A075A196E2; Fri, 17 Dec 2021 21:07:43 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 1BHL7gYC2467574; Fri, 17 Dec 2021 16:07:42 -0500 From: DJ Delorie To: Alexandra =?utf-8?B?SMOhamtvdsOh?= Cc: libc-alpha@sourceware.org, mark@klomp.org, ahajkova@redhat.com Subject: Re: [PATCH] Add valgrind smoke test In-Reply-To: <20211217182633.1653228-1-ahajkova@redhat.com> Date: Fri, 17 Dec 2021 16:07:41 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Dec 2021 21:07:57 -0000 Alexandra Hjkov via Libc-alpha writes: > Check if whether valgrind is available in the test environment. > If not, skip the test. Run smoke tests with valgrind to verify dynamic loader. > First, check if algrind works with the system ld.so in the test > environment. Then run the actual test inside the test environment, > using the just build ld.so and new libraries. > > Co-authored-by: Mark Wielaard > diff --git a/elf/Makefile b/elf/Makefile > + valgrind-test \ New test. Ok. > @@ -256,6 +257,12 @@ tests-special += $(objpfx)tst-audit14-cmp.out $(objpfx)tst-audit15-cmp.out \ > +tests-special += $(objpfx)tst-valgrind-smoke.out > +$(objpfx)tst-valgrind-smoke.out: tst-valgrind-smoke.sh $(objpfx)ld.so $(objpfx)valgrind-test > + $(SHELL) $< $(objpfx)ld.so $(rtlddir)/$(rtld-installed-name) '$(test-wrapper-env)' '$(run-program-env)' '$(rpath-link)' $(objpfx)valgrind-test > $@; \ > + $(evaluate-test) We're passing everything to the script, which is $<, so "see below". Long lines should be wrapped, but Ok with that change. > diff --git a/elf/tst-valgrind-smoke.sh b/elf/tst-valgrind-smoke.sh > +#!/bin/sh > +# Valgrind smoke test. > +# Copyright (C) 2021 Free Software Foundation, Inc. > +# This file is part of the GNU C Library. > + > +# The GNU C Library is free software; you can redistribute it and/or > +# modify it under the terms of the GNU Lesser General Public > +# License as published by the Free Software Foundation; either > +# version 2.1 of the License, or (at your option) any later version. > + > +# The GNU C Library is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > +# Lesser General Public License for more details. > + > +# You should have received a copy of the GNU Lesser General Public > +# License along with the GNU C Library; if not, see > +# . Ok. > +set -e > + > +rtld="$1" > +system_rtld="$2" > +test_wrapper_env="$3" > +run_program_env="$4" > +library_path="$5" > +test_prog="$6" rtld is $(objpfx)ld.so system_rtld is $(rtlddir)/$(rtld-installed-name) test_wrapper_env is '$(test-wrapper-env)' (either just "env" or script to ssh, plus "env") run_program_env is '$(run-program-env)' (just env vars) library_path is '$(rpath-link)' test_prog is $(objpfx)valgrind-test ok > +# Test whether valgrind is available in the test > +# environment. If not, skip the test. > +${test_wrapper_env} ${run_program_env} \ > + /bin/sh -c "command -v valgrind" || exit 77 Run valgrind with no options; we should only exit if valgrind is missing. Ok. > +# Test valgrind works with the system ld.so in the test environment > +/bin/sh -c \ > + "${test_wrapper_env} ${run_program_env} \ > + valgrind -q --error-exitcode=1 \ > + ${system_rtld} ${test_prog} ${system_rtld}" || exit 77 runs on target, native valgrind with in-build test with native rtld... Note that the test_prog built against the new glibc probably won't run against the old installed glibc, esp if there's a version bump. You might need to use something other than the test_prog, like /bin/echo, for this test. Running the build/test on an older Fedora version should have picked this up. > +# Finally the actual test inside the test environment, > +# using the just build ld.so and new libraries to run > +# the smoke test under valgrind. > +/bin/sh -c \ > + "${test_wrapper_env} ${run_program_env} \ > + valgrind -q --error-exitcode=1 \ > + ${rtld} --library-path ${library_path} ${test_prog} ${rtld}" runs on target, native valgrind, runs target program with new rtld and libraries, ok. > diff --git a/elf/valgrind-test.c b/elf/valgrind-test.c > +/* This is the simple test intended to be called by > + tst-valgrind-smoke to perform vagrind smoke test. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > + > +int > +main (int argc, char **argv) > +{ > + // Do some non-trivial stuff that has been known to trigger > + // issues under valgrind in the past. > + // Setting up the locale textdomain makes sure to test some > + // string/path comparisons, file search and library loading. > + setlocale (LC_ALL, ""); > + bindtextdomain ("translit", ""); > + textdomain ("translit"); > + > + // Show what we are executing and how... > + char *me = realpath (argv[0], NULL); > + printf ("bin: %s\n", me); > + printf ("ld.so: %s\n", argv[1]); > + free (me); > + > + return 0; > +} Ok.