diff options
author | Thomas Haller <thaller@redhat.com> | 2015-11-23 19:23:45 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-11-24 11:02:55 +0100 |
commit | 4dacf0b1ad716747310e56188a0d283ee47ebee0 (patch) | |
tree | 1ea5cffecf3ae2c8e1b8e0a488233f37ed3ae327 | |
parent | 73cb57910835ef46d43bb92309def186e38534cf (diff) | |
download | NetworkManager-4dacf0b1ad716747310e56188a0d283ee47ebee0.tar.gz |
nmtst/valgrind: allow calling 'run-test-valgrind.sh' script directly
When you want to run valgrind for a test, you either had to
invoke valgrind manually, or doing it via `make check` (provided
you configured --with-valgrind).
Make it more convenient to run valgrind by passing the test
to run to the "run-test-valgrind.sh" wrapper.
This also allows to pass -p/-s to the test, which is not possible
during `make check` because selecting tests conflicts with "--tap".
The following invocations are largely equivalent and work as
expected:
$ ./tools/run-test-valgrind.sh ./src/platform/tests/test-link-linux -p /link/software/detect/vlan
$ NMTST_DEBUG=no-debug,p=/link/software/detect/vlan ./tools/run-test-valgrind.sh ./src/platform/tests/test-link-linux
-rw-r--r-- | configure.ac | 2 | ||||
-rwxr-xr-x | tools/run-test-valgrind.sh | 93 |
2 files changed, 85 insertions, 10 deletions
diff --git a/configure.ac b/configure.ac index 6f38831d3a..fd5a47c5a4 100644 --- a/configure.ac +++ b/configure.ac @@ -945,7 +945,7 @@ else fi fi AS_IF([test "$with_valgrind" != "no"], - AC_SUBST(VALGRIND_RULES, 'LOG_COMPILER = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" '"$with_valgrind_suppressions"), + AC_SUBST(VALGRIND_RULES, 'LOG_COMPILER = "$(top_srcdir)/tools/run-test-valgrind.sh" --called-from-make "$(LIBTOOL)" "$(with_valgrind)" '"$with_valgrind_suppressions"), AC_SUBST(VALGRIND_RULES, [])) AM_CONDITIONAL(WITH_VALGRIND, test "${with_valgrind}" != "no") diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index ff5bc44ce3..424f633d06 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -1,19 +1,93 @@ -#!/bin/sh +#!/bin/bash + +die() { + echo "$@" + exit 5 +} + +SCRIPT_PATH="${SCRIPT_PATH:-$(readlink -f "$(dirname "$0")")}" -LIBTOOL="$1"; shift -VALGRIND="$1"; shift -SUPPRESSIONS="$1"; shift VALGRIND_ERROR=37 -if [ "$1" = "--launch-dbus" ]; then +if [ "$1" == "--called-from-make" ]; then + shift + NMTST_LIBTOOL=($1 --mode=execute); shift + NMTST_VALGRIND="$1"; shift + SUPPRESSIONS="$1"; shift + if [ "$1" = "--launch-dbus" ]; then + NMTST_LAUNCH_DBUS=yes + shift + else + NMTST_LAUNCH_DBUS=no + fi + TEST="$1"; shift +else + if [ -n "${NMTST_LIBTOOL-:x}" ]; then + NMTST_LIBTOOL=(sh "$SCRIPT_PATH/../libtool" --mode=execute) + elif [ -n "${NMTST_LIBTOOL-x}" ]; then + NMTST_LIBTOOL=() + else + NMTST_LIBTOOL=($NMTST_LIBTOOL --mode=execute) + fi + for a in "$@"; do + case "$a" in + "--launch-dbus") + NMTST_LAUNCH_DBUS=yes + shift + ;; + "--no-launch-dbus"|"-D") + NMTST_LAUNCH_DBUS=no + shift + ;; + "--no-libtool") + NMTST_LIBTOOL=() + shift + ;; + "--") + shift + break + ;; + *) + break + ;; + esac + done + # we support calling the script directly. In this case, + # only pass the path to the test to run. + TEST="$1"; shift + NMTST_VALGRIND="${NMTST_VALGRIND:-valgrind}" + if [ "$SUPPRESSIONS" == "" ]; then + SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions" + fi + + [ -x "$TEST" ] || die "Test \"$TEST\" does not exist" + + TEST_PATH="$(readlink -f "$(dirname "$TEST")")" + + if [ -n "${NMTST_LAUNCH_DBUS-x}" ]; then + # autodetect whether to launch D-Bus based on the test path. + if [[ $TEST_PATH == */libnm/tests || $TEST_PATH == */libnm-glib/tests ]]; then + NMTST_LAUNCH_DBUS=yes + else + NMTST_LAUNCH_DBUS=no + fi + fi + + # some tests require you to cd into the base directory. + # do that. + if [ "$NMTST_VALGRIND_NO_CD" == "" ]; then + cd "$TEST_PATH" + TEST="./$(basename "$TEST")" + fi +fi + +if [ "$NMTST_LAUNCH_DBUS" == "yes" ]; then # Spawn DBus eval `dbus-launch --sh-syntax` trap "kill $DBUS_SESSION_BUS_PID" EXIT - shift fi -TEST="$1" if [ "$NMTST_NO_VALGRIND" != "" ]; then - "$@" + "$TEST" "$@" exit $? fi @@ -21,7 +95,7 @@ LOGFILE="valgrind-`echo "$TEST" | tr -cd '[:alpha:]-'`.log" export G_SLICE=always-malloc export G_DEBUG=gc-friendly -$LIBTOOL --mode=execute "$VALGRIND" \ +"${NMTST_LIBTOOL[@]}" "$NMTST_VALGRIND" \ --quiet \ --error-exitcode=$VALGRIND_ERROR \ --leak-check=full \ @@ -29,6 +103,7 @@ $LIBTOOL --mode=execute "$VALGRIND" \ --suppressions="$SUPPRESSIONS" \ --num-callers=100 \ --log-file="$LOGFILE" \ + "$TEST" \ "$@" RESULT=$? |