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