From patchwork Mon Dec 20 11:37:42 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: 49117 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 E8B993857811 for ; Mon, 20 Dec 2021 11:38:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8B993857811 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1640000296; bh=Ga3NOjzO7PRH9g5bfUo6mMDmfnNhe38s5U5VI/g8+Kw=; 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=ITRiTWlfBN72q3VVtiNLhqTexdq9q/HDwZe1OFa5CZ9lMeVJORFtMylSRcn18oKXv 7mb/p/ElqPg/BdRiilnq+EAXDq7N4hmFWzPv1zoL+CCH+ptQsv3uWjR/SlyTnHYycy I1iV9QKFcmhEHcnjH7qnRsdMu/+S4VwLF9fpwB2g= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with UTF8SMTPS id 188013858405 for ; Mon, 20 Dec 2021 11:37:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 188013858405 Received: by mail-ed1-x534.google.com with SMTP id j21so32597424edt.9 for ; Mon, 20 Dec 2021 03:37:55 -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=Ga3NOjzO7PRH9g5bfUo6mMDmfnNhe38s5U5VI/g8+Kw=; b=UAaGIaaJb+ipT87oPJRwp/0jYf/xuNvV/kX1N0/+ZNJ+edE5hVyMKwk1ObnkOyYuJQ uqcuBGxbwOEQqsfbHkpYAe+f8X9lFRE+LbL5Ox4YsOcz+P04JWY3sVb3ZSJhOXg19luO CthpSit0Pt18hFG6+ahjIS8m/t0Wx/fNkAAohehvdgA9NegrOr5dGZqCfZyj6cdCfwv2 +67K7DNNbe/W3CHROeAY+N4FdgfM5mkrMP6CCmmhMBwmD5mm/KulMmAiRb1FqLEkXkd2 0LOWwMqa3fb0urwzTo1b6wMphYmYeBlygRqNU7c7kfv3/k7spNJkF+aVjhtA+YofBK4a L6pA== X-Gm-Message-State: AOAM53277WwdzwJwSi3O8+64a6NA0sj4n/ejiJTz2URuwjCjIBqVKvgh 1o5t+icIiONP9fDNB+fWwlQwcElnuqY= X-Google-Smtp-Source: ABdhPJwS3e+owEUAB4sNpuiQAfKM1WwK7zEa0glLfrralPh/GB5UEiQLJejmsNa/hlyHAIs2xwvsUQ== X-Received: by 2002:a05:6402:11c7:: with SMTP id j7mr15434933edw.83.1640000273948; Mon, 20 Dec 2021 03:37:53 -0800 (PST) Received: from picard.redhat.com (ip-244-183.pel.cz. [213.226.244.183]) by smtp.gmail.com with ESMTPSA id hq29sm1607121ejc.141.2021.12.20.03.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 03:37:53 -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: Mon, 20 Dec 2021 12:37:42 +0100 Message-Id: <20211220113742.1951911-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..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. +# 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..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; +}