From patchwork Fri Dec 17 18:26:33 2021 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: 49065 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 709EC3858420 for ; Fri, 17 Dec 2021 18:27:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 709EC3858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1639765628; bh=L+5zi/Izp3hrejJygCsx624or2MZhCwapJ2wCwbCCo8=; 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=L6MH//Q07gcAs4YRN/QUPsetgpNHl6ThsMw1XnG00R8FFhgcDRbNXLLP2tHBXkRGH LTo7R4ww2u9lZof1yEvykrI7B3fKVzcRfAKlRaRypvaVtm0b6v7IrnvV9myqIUpW2A PVXoKO6Rh7r5YfSXzSeC8wisOGtU7RZwn0oyGRE0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with UTF8SMTPS id 00BD33858407 for ; Fri, 17 Dec 2021 18:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 00BD33858407 Received: by mail-ed1-x529.google.com with SMTP id y13so11004082edd.13 for ; Fri, 17 Dec 2021 10:26:46 -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=L+5zi/Izp3hrejJygCsx624or2MZhCwapJ2wCwbCCo8=; b=ES2ZS706nC5smuRpqFhY0TzGO2yYK/aUta99ShqToNIl22v/yyRiUOmM3HeNukJLGx EHK1dHejQJ9PKfielj1sbN3MIcbkAQPMaqqDvQ5trMoT8yBQlXNsded7ATzmLVpPdVj8 HHH0DzvH5kLPxYzz0bzuX0xUSo5ZOm39SQXJ2F+GVnhMBspXsGozf3MYvCgHdifDeRyV lsugyy9Soj00UHVYVa4zHlU7UdGtT1IvVcHbw4IXuTvJVBeu33Q1vikbAmmLB+9RIvWA Vdjjv094yUmNitjna1txzvYAP4a8yPxNyEU7p+Yyjfyi/liklJuMqO/7yv5LTKayLeEA daAw== X-Gm-Message-State: AOAM5307ipBO/gADVIsPSzSTWAYSlYndsvfnZzh7Wj/UUdddd+3s2BqR OitwWyTGRdAKpyHSEOmU6YKFzgGSavs= X-Google-Smtp-Source: ABdhPJxfxu4kh5q7VJTrHC+QNvc1KBhgzVemhCAUnT7otrr/oW/Yqj+VMxlUh6ZPLi951A0dBUYaMg== X-Received: by 2002:a05:6402:278e:: with SMTP id b14mr3968392ede.354.1639765605969; Fri, 17 Dec 2021 10:26:45 -0800 (PST) Received: from picard.redhat.com (ip-244-183.pel.cz. [213.226.244.183]) by smtp.gmail.com with ESMTPSA id sg39sm3086086ejc.66.2021.12.17.10.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Dec 2021 10:26:45 -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: Fri, 17 Dec 2021 19:26:33 +0100 Message-Id: <20211217182633.1653228-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 | 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..9c9d331311 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..b51e2907a3 --- /dev/null +++ b/elf/tst-valgrind-smoke.sh @@ -0,0 +1,46 @@ +#!/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 +# . + +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} ${test_prog} ${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. + 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; +}