valgrind-condense revision 3ce85a5f5264e7118beb6524e120fd8b53a13da4
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# Run Valgrind, condensing logged reports into an exit code.
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# Copyright (C) 2014 Red Hat
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# This program is free software; you can redistribute it and/or modify
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# it under the terms of the GNU General Public License as published by
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# the Free Software Foundation; either version 3 of the License, or
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# (at your option) any later version.
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# This program is distributed in the hope that it will be useful,
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# but WITHOUT ANY WARRANTY; without even the implied warranty of
0175d37a5ae5a4d146ca41b684bd38d9b03683cbMartti Rannanjärvi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# GNU General Public License for more details.
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# You should have received a copy of the GNU General Public License
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# along with this program. If not, see <http://www.gnu.org/licenses/>.
992a1726a41b42fa47204565ff17f7c635fcb421Phil CarmodyUsage: `basename "$0"` ERROR_EXITCODE [PATH_PATTERN...] [-- VALGRIND_ARG...]
992a1726a41b42fa47204565ff17f7c635fcb421Phil CarmodyRun Valgrind, condensing logged reports into an exit code.
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody ERROR_EXITCODE An exit code to return if at least one error is found in
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody Valgrind log files.
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody PATH_PATTERN An extended glob pattern matching (original) paths to
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody programs to execute under Valgrind. Execution is skipped
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody and success is returned for non-matching programs. Without
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody patterns, all programs match.
0175d37a5ae5a4d146ca41b684bd38d9b03683cbMartti Rannanjärvi VALGRIND_ARG An argument to pass to Valgrind after the arguments
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody specified by `basename "$0"`.
992a1726a41b42fa47204565ff17f7c635fcb421Phil CarmodyThe first non-option VALGRIND_ARG will be considered the path to the program
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyto execute under Valgrind and will be used in naming Valgrind log files as
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody PROGRAM_NAME.PID.valgrind.log
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodywhere PROGRAM_NAME is the filename portion of the program path and PID is the
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyexecuted process ID. If the last directory of the program path is ".libs" and
62461eb609e1d852e027cf4e07d30d51288678a2Aki Tuomithe filename begins with "lt-", both are removed to match the name of libtool
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyfrontend script. All files matching PROGRAM_NAME.*.valgrind.log are removed
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodybefore invoking Valgrind.
992a1726a41b42fa47204565ff17f7c635fcb421Phil CarmodyIf an error is found in Valgrind log files, ERROR_EXITCODE is returned,
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyotherwise Valgrind exit code is returned.
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyif [[ $# == 0 ]]; then
0175d37a5ae5a4d146ca41b684bd38d9b03683cbMartti Rannanjärvi# Extract path patterns
f9a1f7b6034d692cbd24c1895061b3834f486501Phil Carmodywhile [[ $# != 0 ]]; do
f9a1f7b6034d692cbd24c1895061b3834f486501Phil Carmody# Find program path argument
f9a1f7b6034d692cbd24c1895061b3834f486501Phil Carmody elif "$got_dash_dash" || [[ "$arg" != -* ]]; then
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyif [[ -z "${program_path+set}" ]]; then
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody# Match against path patterns, if any
0175d37a5ae5a4d146ca41b684bd38d9b03683cbMartti Rannanjärviif [[ ${#path_pattern_list[@]} != 0 ]]; then
98c59517ebce19556221065e9231f007bbdd0038Timo Sirainen for path_pattern in "${path_pattern_list[@]}"; do
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmody if [[ "$program_path" == $path_pattern ]]; then
f9a1f7b6034d692cbd24c1895061b3834f486501Phil Carmody# Generate original path from libtool path
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyprogram_path=`sed -e 's/^\(.*\/\)\?\.libs\/lt-\([^\/]\+\)$/\1\2/' \
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyvalgrind --log-file="$program_name.%p.valgrind.log" "$@" || status=$?
992a1726a41b42fa47204565ff17f7c635fcb421Phil Carmodyif grep -q '^==[0-9]\+== *ERROR SUMMARY: *[1-9]' \