summaryrefslogtreecommitdiffstats
path: root/contrib/ci/valgrind-condense
diff options
context:
space:
mode:
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>2014-03-25 12:01:00 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-09-02 10:43:21 +0200
commit3ce85a5f5264e7118beb6524e120fd8b53a13da4 (patch)
treeec46ff937a47518ff9ed0f4dd67ebf2157fbc4bf /contrib/ci/valgrind-condense
parent6b5044001e4b0a0caf971a2cf5f27674e0d270f4 (diff)
downloadsssd-3ce85a5f5264e7118beb6524e120fd8b53a13da4.tar.gz
sssd-3ce85a5f5264e7118beb6524e120fd8b53a13da4.tar.xz
sssd-3ce85a5f5264e7118beb6524e120fd8b53a13da4.zip
Add basic support for CI test execution
Add basic support for executing continuous integration (CI) tests on RHEL6, RHEL7, Fedora 20, Fedora Rawhide and Debian Testing. This adds two front-end scripts which can be executed either locally by developers, or on a CI server: contrib/ci/run and contrib/ci/clean. The first one will run the tests and the second will wipe out the artifacts. See contrib/ci/README.md for further details. Reviewed-by: Michal Židek <mzidek@redhat.com> Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'contrib/ci/valgrind-condense')
-rwxr-xr-xcontrib/ci/valgrind-condense128
1 files changed, 128 insertions, 0 deletions
diff --git a/contrib/ci/valgrind-condense b/contrib/ci/valgrind-condense
new file mode 100755
index 000000000..b838039e2
--- /dev/null
+++ b/contrib/ci/valgrind-condense
@@ -0,0 +1,128 @@
+#!/bin/bash
+#
+# Run Valgrind, condensing logged reports into an exit code.
+#
+# Copyright (C) 2014 Red Hat
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+set -o nounset -o pipefail -o errexit
+shopt -s extglob
+
+function usage()
+{
+ cat <<EOF
+Usage: `basename "$0"` ERROR_EXITCODE [PATH_PATTERN...] [-- VALGRIND_ARG...]
+Run Valgrind, condensing logged reports into an exit code.
+
+Arguments:
+ ERROR_EXITCODE An exit code to return if at least one error is found in
+ Valgrind log files.
+ PATH_PATTERN An extended glob pattern matching (original) paths to
+ programs to execute under Valgrind. Execution is skipped
+ and success is returned for non-matching programs. Without
+ patterns, all programs match.
+ VALGRIND_ARG An argument to pass to Valgrind after the arguments
+ specified by `basename "$0"`.
+
+The first non-option VALGRIND_ARG will be considered the path to the program
+to execute under Valgrind and will be used in naming Valgrind log files as
+such:
+
+ PROGRAM_NAME.PID.valgrind.log
+
+where PROGRAM_NAME is the filename portion of the program path and PID is the
+executed process ID. If the last directory of the program path is ".libs" and
+the filename begins with "lt-", both are removed to match the name of libtool
+frontend script. All files matching PROGRAM_NAME.*.valgrind.log are removed
+before invoking Valgrind.
+
+If an error is found in Valgrind log files, ERROR_EXITCODE is returned,
+otherwise Valgrind exit code is returned.
+EOF
+}
+
+
+if [[ $# == 0 ]]; then
+ echo "Invalid number of arguments." >&2
+ usage >&2
+ exit 1
+fi
+
+declare error_exitcode="$1"; shift
+declare -a path_pattern_list=()
+declare arg
+declare got_dash_dash
+declare program_path
+declare path_pattern
+declare match
+declare program_name
+declare status=0
+
+# Extract path patterns
+while [[ $# != 0 ]]; do
+ arg="$1"
+ shift
+ if [[ "$arg" == "--" ]]; then
+ break
+ else
+ path_pattern_list+=("$arg")
+ fi
+done
+
+# Find program path argument
+got_dash_dash=false
+for arg in "$@"; do
+ if [[ "$arg" == "--" ]]; then
+ got_dash_dash=true
+ elif "$got_dash_dash" || [[ "$arg" != -* ]]; then
+ program_path="$arg"
+ break
+ fi
+done
+
+if [[ -z "${program_path+set}" ]]; then
+ echo "Program path not specified." >&2
+ usage >&2
+ exit 1
+fi
+
+# Match against path patterns, if any
+if [[ ${#path_pattern_list[@]} != 0 ]]; then
+ match=false
+ for path_pattern in "${path_pattern_list[@]}"; do
+ if [[ "$program_path" == $path_pattern ]]; then
+ match=true
+ fi
+ done
+ if ! $match; then
+ exit 0
+ fi
+fi
+
+# Generate original path from libtool path
+program_path=`sed -e 's/^\(.*\/\)\?\.libs\/lt-\([^\/]\+\)$/\1\2/' \
+ <<<"$program_path"`
+
+program_name=`basename "$program_path"`
+
+rm -f "$program_name".*.valgrind.log
+valgrind --log-file="$program_name.%p.valgrind.log" "$@" || status=$?
+
+if grep -q '^==[0-9]\+== *ERROR SUMMARY: *[1-9]' \
+ "$program_name".*.valgrind.log; then
+ exit "$error_exitcode"
+else
+ exit "$status"
+fi