From patchwork Wed Jan 12 17:15:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= X-Patchwork-Id: 49931 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5686B394002F for ; Wed, 12 Jan 2022 17:16:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5686B394002F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1642007771; bh=lmbsOahauALskGy8lDBxNRL1cdP43kGLhp5r8w/p0ss=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=D/7iaKpWZSX2X7FOzL6pvD2nsx1iiRl1QfFazrMroGs5yNOxRNIM2CsREgQykfnr4 GuCsiO62BopJXQZsMu+IJC6puExTU9ZHN/WOlM20Q5Z+VPYOaAO1RrGHkmkf8OWx2l 7iYyHp3ERCwrft2082O5FAKV9IjCyXLS7KBWcCoQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with UTF8SMTPS id 3ADBD3858406 for ; Wed, 12 Jan 2022 17:15:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3ADBD3858406 Received: by mail-ed1-x52b.google.com with SMTP id u21so12681045edd.5 for ; Wed, 12 Jan 2022 09:15:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lmbsOahauALskGy8lDBxNRL1cdP43kGLhp5r8w/p0ss=; b=4NOKM3OsU2cVWEs9c+C/b0ApBt5W+JnQ0+wsO2HuDA0xIcZ+6XIBdShJ3FrLUjAsMf pqA379rSSh8B2yFCOpVg2U4vBAf9HeShiklcy/kbWogGNZVA5GWTOSKrtQJV4F8kFLP8 59aSOQuiSsz/as3Y5a2idLqlYlGeaWE8Ee+Hf9Q7gtQQtHoVQyYyIO+U5W7MDS7I0GNA I7825zqlDm+S9LTHOvzRcdpX3gLTo/YlsjqXIT+XVlq+oczLiUBFvQxtbQIVxOPzxQwz AggkBx/GTql/vuplX9zrOHqAeLaqDDBvLAikxKmFpAI9yZhuu5oNogTqIPijQlGB3p1h fhjg== X-Gm-Message-State: AOAM531cEInTNYvVkanh3uIiT78zaWaLVXixv2es7fqhmuNgeOhl+Usi 5xEYOlYCb2HlYU0VCZ24rMWkIS8kh1w= X-Google-Smtp-Source: ABdhPJxd6JV3XCXtMTZGU3IyR6q8cy9GqeGU0YoKNkw/IkcNr+GDCvroDa5ptiYvLcB4+/UVOl1sEg== X-Received: by 2002:a17:906:2cd5:: with SMTP id r21mr541447ejr.435.1642007748161; Wed, 12 Jan 2022 09:15:48 -0800 (PST) Received: from picard.redhat.com (ip-244-183.pel.cz. [213.226.244.183]) by smtp.gmail.com with ESMTPSA id 1sm90645ejo.192.2022.01.12.09.15.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 09:15:47 -0800 (PST) X-Google-Original-From: =?unknown-8bit?q?Alexandra_H=C3=A1jkov=C3=A1_ahajkov?= =?unknown-8bit?q?a=40redhat=2Ecom?= To: libc-alpha@sourceware.org Subject: [PATCH] Add valgrind smoke test Date: Wed, 12 Jan 2022 18:15:39 +0100 Message-Id: <20220112171539.3205267-1-ahajkova@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20211206144043.858697-1-ahajkova@redhat.com> References: <20211206144043.858697-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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-Patchwork-Original-From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1_via_Libc-alpha?= From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Reply-To: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Cc: Mark Wielaard , =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 | 49 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 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 b86d116be9..77829cf967 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -327,6 +327,7 @@ tests += \ unload6 \ unload7 \ unload8 \ + valgrind-test \ # reldep9 tests-cxx = \ tst-dlopen-nodelete-reloc \ @@ -361,6 +362,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..7ce4af6897 --- /dev/null +++ b/elf/tst-valgrind-smoke.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# Valgrind smoke test. +# Copyright (C) 2022 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 +# . + +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. +${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..71b8a09b35 --- /dev/null +++ b/elf/valgrind-test.c @@ -0,0 +1,49 @@ +/* This is the simple test intended to be called by + tst-valgrind-smoke to perform vagrind smoke test. + Copyright (C) 2022 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 +#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. */ + xsetlocale (LC_ALL, ""); + if (bindtextdomain ("translit", "") == NULL) + return errno; + if (textdomain ("translit") == NULL) + return errno; + + /* 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; +}