From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x929.google.com (mail-ua1-x929.google.com [IPv6:2607:f8b0:4864:20::929]) by sourceware.org (Postfix) with ESMTPS id 380DF389AC29 for ; Mon, 10 Jan 2022 12:38:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 380DF389AC29 Received: by mail-ua1-x929.google.com with SMTP id p1so23080758uap.9 for ; Mon, 10 Jan 2022 04:38:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=ITNc579jD8IPFzvXbqrCqzfBAVpK0TWsnM0qubSzzoA=; b=BWPCVeTnofWSppWxe/HO7gnVb7d7Ps2QlOEbWd6+oV00uTikviRm+bv4p3PfR8oQV2 68Me9IwuCi5EXkViDz3selm6SG2RfuBGzP3kkXZVXoS4Cp0FVAxFEZg6XY1WyCsl8g6U TgywRgrtwAd4nBZBi/MmxlRMdZt/BAV8nLFpInOeNNKO3avjDXEyFq9hLo+TwJg8if5/ vvAmdbmjplRy1v5XiHAvk7JdOK7GtW9+99y4oZ+sKpqOClNa0ncCTVaF4ZmCYeI7H7zD ylk/lYTpFUK9Zg6qOP4wrbn0HNrjS4ApmY0jQRdETD4VY9Cmg2gVbXwQEI38rVKxdGnB ANVg== X-Gm-Message-State: AOAM533AwwmX/K640zvQ8K51Ut7EYas43ZyCxVQbp6VRH5eSsqpGx98Q BiDfSKWrrfx/wBD24gPY/q9ZCsKb5tg6Nw== X-Google-Smtp-Source: ABdhPJxcm7KgoimNvAD0JrvI551MLqE9T75auHnOg+e3oUaiEVhtPxl1MF6t+BdV8RZm0j7mKuJvmw== X-Received: by 2002:ab0:7390:: with SMTP id l16mr731042uap.73.1641818284517; Mon, 10 Jan 2022 04:38:04 -0800 (PST) Received: from ?IPV6:2804:431:c7ca:9d3:3f97:8103:cbb:d524? ([2804:431:c7ca:9d3:3f97:8103:cbb:d524]) by smtp.gmail.com with ESMTPSA id n17sm4022374vsg.29.2022.01.10.04.38.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Jan 2022 04:38:04 -0800 (PST) Message-ID: Date: Mon, 10 Jan 2022 09:38:02 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] Add valgrind smoke test Content-Language: en-US To: libc-alpha@sourceware.org References: <20211206144043.858697-1-ahajkova@redhat.com> <20211220113742.1951911-1-ahajkova@redhat.com> From: Adhemerval Zanella In-Reply-To: <20211220113742.1951911-1-ahajkova@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Mon, 10 Jan 2022 12:38:07 -0000 On 20/12/2021 08:37, Alexandra Hájková via Libc-alpha wrote: > From: Alexandra Hájková > > 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 > --- > elf/Makefile | 7 ++++++ > elf/tst-valgrind-smoke.sh | 46 +++++++++++++++++++++++++++++++++++++++ > elf/valgrind-test.c | 44 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 97 insertions(+) > create mode 100644 elf/tst-valgrind-smoke.sh > create mode 100644 elf/valgrind-test.c > > diff --git a/elf/Makefile b/elf/Makefile > index fe42caeb0e..c2da351c9e 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -230,6 +230,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ > tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ > tst-tls20 tst-tls21 tst-dlmopen-dlerror tst-dlmopen-gethostbyname \ > tst-dl-is_dso tst-ro-dynamic \ > + valgrind-test \ > tst-audit18 \ > tst-rtld-run-static \ > # reldep9 > @@ -256,6 +257,12 @@ tests-special += $(objpfx)tst-audit14-cmp.out $(objpfx)tst-audit15-cmp.out \ > endif > endif > endif > + > +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) > + > tests += $(tests-execstack-$(have-z-execstack)) > ifeq ($(run-built-tests),yes) > tests-special += $(objpfx)tst-leaks1-mem.out \ > diff --git a/elf/tst-valgrind-smoke.sh b/elf/tst-valgrind-smoke.sh > new file mode 100644 > index 0000000000..cc32136268 > --- /dev/null > +++ b/elf/tst-valgrind-smoke.sh > @@ -0,0 +1,46 @@ > +#!/bin/sh > +# Valgrind smoke test. > +# Copyright (C) 2021 Free Software Foundation, Inc. Update the Copyright date. > +# 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 > +# . > + > +set -e > + > +rtld="$1" > +system_rtld="$2" > +test_wrapper_env="$3" > +run_program_env="$4" > +library_path="$5" > +test_prog="$6" > + > +# Test whether valgrind is available in the test > +# environment. If not, skip the test. I think double space after period should be used on shell comments as well. > +${test_wrapper_env} ${run_program_env} \ > + /bin/sh -c "command -v valgrind" || exit 77 > + > +# 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} /bin/echo ${system_rtld}" || exit 77 > + > +# 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}" > diff --git a/elf/valgrind-test.c b/elf/valgrind-test.c > new file mode 100644 > index 0000000000..00c8ec1ad3 > --- /dev/null > +++ b/elf/valgrind-test.c > @@ -0,0 +1,44 @@ > +/* 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. Ditto. > + 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. Please use '/* ... */' comments. > + setlocale (LC_ALL, ""); Use xsetlocale. > + bindtextdomain ("translit", ""); > + textdomain ("translit"); Also check the return here. > + > + // 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; > +}