valgrind-condense revision 5f4f0428c182a9e77d29b39f3749fce03643ac8d
a34684a59b60a4173c25035d0c627ef17e6dc215rpluem# Run Valgrind, condensing logged reports into an exit code.
35006c658c32693022c67b70a3fcf53399e36bd7covener# Copyright (C) 2014 Red Hat
35006c658c32693022c67b70a3fcf53399e36bd7covener# This program is free software; you can redistribute it and/or modify
35006c658c32693022c67b70a3fcf53399e36bd7covener# it under the terms of the GNU General Public License as published by
4330364fc1db390a69cc84d4d0f62138bcd5bf80covener# the Free Software Foundation; either version 3 of the License, or
4330364fc1db390a69cc84d4d0f62138bcd5bf80covener# (at your option) any later version.
4330364fc1db390a69cc84d4d0f62138bcd5bf80covener# This program is distributed in the hope that it will be useful,
dd1e093863f13a4a3fbf09497cbd5cb039fadd76ylavic# but WITHOUT ANY WARRANTY; without even the implied warranty of
dd1e093863f13a4a3fbf09497cbd5cb039fadd76ylavic# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd1e093863f13a4a3fbf09497cbd5cb039fadd76ylavic# GNU General Public License for more details.
330e16bea8fe9cace4de90c349750c03dfb1fe64ylavic# You should have received a copy of the GNU General Public License
330e16bea8fe9cace4de90c349750c03dfb1fe64ylavic# along with this program. If not, see <http://www.gnu.org/licenses/>.
d7205b1a86c51c27b71a2c458dc453fd53a261c1covenerUsage: `basename "$0"` ERROR_EXITCODE [PATH_PATTERN...] [-- VALGRIND_ARG...]
d7205b1a86c51c27b71a2c458dc453fd53a261c1covenerRun Valgrind, condensing logged reports into an exit code.
44ff304057225e944e220e981d434a046d14cf06covener ERROR_EXITCODE An exit code to return if at least one error is found in
44ff304057225e944e220e981d434a046d14cf06covener Valgrind log files.
44ff304057225e944e220e981d434a046d14cf06covener PATH_PATTERN An extended glob pattern matching the (original) path to
ea30bfa68d711e27206df00abb140174b4e65ed7ylavic the program to execute under Valgrind. If the program path
ea30bfa68d711e27206df00abb140174b4e65ed7ylavic doesn't match any patterns, the program is executed
ea30bfa68d711e27206df00abb140174b4e65ed7ylavic directly, without Valgrind. Without patterns any program
ea30bfa68d711e27206df00abb140174b4e65ed7ylavic path matches.
291eb44b3adaf8247425286615b4f4b69fbea274minfrin VALGRIND_ARG An argument to pass to Valgrind after the arguments
291eb44b3adaf8247425286615b4f4b69fbea274minfrin specified by `basename "$0"`.
5d1ba75b8794925e67591c209085a49279791de9covenerThe first non-option VALGRIND_ARG, or the first VALGRIND_ARG after a "--",
5d1ba75b8794925e67591c209085a49279791de9covenerwill be considered the path to the program to execute under Valgrind and will
5d1ba75b8794925e67591c209085a49279791de9covenerbe used in naming Valgrind log files as such:
032982212dbcc7c3cce95bf89c503bb56e185ac7kbrand PROGRAM_NAME.PID.valgrind.log
032982212dbcc7c3cce95bf89c503bb56e185ac7kbrandwhere PROGRAM_NAME is the filename portion of the program path and PID is the
caad2986f81ab263f7af41467dd622dc9add17f3ylavicexecuted process ID. If the last directory of the program path is ".libs" and
caad2986f81ab263f7af41467dd622dc9add17f3ylavicthe filename begins with "lt-", both are removed to match the name of libtool
caad2986f81ab263f7af41467dd622dc9add17f3ylavicfrontend script. All files matching PROGRAM_NAME.*.valgrind.log are removed
caad2986f81ab263f7af41467dd622dc9add17f3ylavicbefore invoking Valgrind.
f7317ff316c2b141feea31bddb74d5d3fa1584edjortonIf an error is found in Valgrind log files, ERROR_EXITCODE is returned,
f7317ff316c2b141feea31bddb74d5d3fa1584edjortonotherwise Valgrind exit code is returned.
4472df9a373740420f81c4c14a331b54d2f91603covenerif [[ $# == 0 ]]; then
fa7ed98b9dc94c5845cf845aea0a44ecacd290c9humbedooh# Extract path patterns
0b67eb8568cd58bb77082703951679b42cf098actrawickwhile [[ $# != 0 ]]; do
09c87c777bed1655621bb20e1c46cb6b1a63279dcovener# Find program argv list in Valgrind arguments
cf8b985ec0a63b15a1c8f2990d96009a11e0d68ecovener if ! "$collecting_argv" && [[ "$arg" == "--" ]]; then
c85eff31536e6bfef1537b2435564d48665435d3rpluemif [[ ${#program_argv[@]} == 0 ]]; then
e6b4bd1113567627ab6bb6c6a7105e1e01a7d889jailletc# Match against path patterns, if any
e6b4bd1113567627ab6bb6c6a7105e1e01a7d889jailletcif [[ ${#path_pattern_list[@]} == 0 ]]; then
15660979a30d251681463de2e0584853890082accovener# Run the program
cfd9415521847b2f9394fad04fb701cfb955f503rjung # Generate original path from libtool path
cfd9415521847b2f9394fad04fb701cfb955f503rjung program_path=`sed -e 's/^\(.*\/\)\?\.libs\/lt-\([^\/]\+\)$/\1\2/' \
28c31fb73c1264bd1d0ff932573677030b024c7dwrowe valgrind --log-file="$program_name.%p.valgrind.log" "$@" || status=$?
4efd27d2bd53a819a194f8a942f8881c1927755eylavic "${program_argv[@]}"