tests: improve run-nm-test.sh to weak valgrind usage

- also when called from makefile, allow enabling valgrind even if it was not
  enabled via configure option. That is, even if you configured --without-valgrind,
  you can run tests via `NMTST_USE_VALGRIND=1 make check`. Previously, there
  was no way to run on valgrind during `make check` unless you also had
  configured --with-valgrind.
- Use $NMTST_VALGRIND variable to override the valgrind path. This now
  always takes precedence. For `make check`, the path can be determined
  by the configure script.
  If all unspecified, as last fallback "valgrind" is searched in the current
  $PATH.
- Allow to specify the suppressions file via $NMTST_SUPPRESSIONS.
  If unset, fall back to the default. The default during `make check`
  is determined by the configure options. The default for manual
  invocation is our one valgrind.suppressions file.
  To use no suppressions file, set NMTST_SUPPRESSIONS to empty.

Now, regardless of what you enabled during ./configure, you can
overwrite it via:

  $ NMTST_USE_VALGRIND=1 \
    NMTST_VALGRIND=~/bin/valgrind \
    NMTST_SUPPRESSIONS=my-suppressions \
    make check
This commit is contained in:
Thomas Haller 2016-12-14 13:48:03 +01:00
parent fee104621e
commit de5ce89494

View file

@ -34,35 +34,41 @@ else
CALLED_FROM_MAKE=0
fi
# Whether to use valgrind can be controlled via command line
# variables $NMTST_USE_VALGRIND set to true/false
#
# When --called-from-make, the variable has only
# effect when `./configure --with-valgrind`. Otherwise,
# valgrind is never used during `make check`.
# When `./configure --with-valgrind`, valgrind is used
# unless it's disabled via environment variable.
#
# When called directly, the arguments -v|-V overwrite the
# setting from the environment variable.
# When neither specified via command line or environemt
# variable, default to "false".
if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
if [ "$CALLED_FROM_MAKE" == 1 ]; then
NMTST_USE_VALGRIND=1
else
NMTST_USE_VALGRIND=0
fi
fi
if [ "$CALLED_FROM_MAKE" == 1 ]; then
NMTST_LIBTOOL=($1 --mode=execute); shift
NMTST_VALGRIND="$1"; shift
if [[ "$NMTST_VALGRIND" == no ]]; then
NMTST_USE_VALGRIND=0
NMTST_VALGRIND=
NMTST_VALGRIND_ARG="$1"; shift
if [[ "$NMTST_VALGRIND_ARG" == no ]]; then
NMTST_VALGRIND_ARG=
fi
SUPPRESSIONS="$1"; shift
if [[ -z "${NMTST_VALGRIND}" ]]; then
# the valgrind path can be specified via $NMTST_VALGRIND.
# Otherwise, it can be determined by the configure scripts.
# Otherwise, it is found in the current $PATH (below).
if [[ "$NMTST_VALGRIND_ARG" != "" ]]; then
NMTST_VALGRIND="${NMTST_VALGRIND_ARG}"
fi
fi
if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
# whether to use valgrind can be specified via $NMTST_USE_VALGRIND.
# Otherwise, it depends on the configure option.
if [ "$NMTST_VALGRIND_ARG" == "" ]; then
NMTST_USE_VALGRIND=0
else
NMTST_USE_VALGRIND=1
fi
fi
NMTST_SUPPRESSIONS_ARGS="$1"; shift
if [[ -z "${NMTST_SUPPRESSIONS+x}" ]]; then
if [[ "$NMTST_SUPPRESSIONS_ARGS" == "" ]]; then
NMTST_SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
else
NMTST_SUPPRESSIONS="${NMTST_SUPPRESSIONS_ARGS}"
fi
fi
if [ "$1" = "--launch-dbus" ]; then
NMTST_LAUNCH_DBUS=1
shift
@ -76,6 +82,11 @@ if [ "$CALLED_FROM_MAKE" == 1 ]; then
NMTST_MAKE_FIRST=0
else
if [[ -z "${NMTST_USE_VALGRIND+x}" ]]; then
# by default, disable valgrind checks.
NMTST_USE_VALGRIND=0
fi
if [ -n "${NMTST_LIBTOOL-:x}" ]; then
NMTST_LIBTOOL=(sh "$SCRIPT_PATH/../libtool" --mode=execute)
elif [ -n "${NMTST_LIBTOOL-x}" ]; then
@ -121,8 +132,8 @@ else
# we support calling the script directly. In this case,
# only pass the path to the test to run.
TEST="$1"; shift
if [ "$SUPPRESSIONS" == "" ]; then
SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
if [[ -z "${NMTST_SUPPRESSIONS+x}" ]]; then
NMTST_SUPPRESSIONS="$SCRIPT_PATH/../valgrind.suppressions"
fi
fi
@ -179,6 +190,12 @@ else
test -e "${NMTST_VALGRIND}" || die "cannot find valgrind binary from NMTST_VALGRIND=\"${NMTST_VALGRIND}\""
fi
if [[ "${NMTST_SUPPRESSIONS}" != "" ]]; then
NMTST_SUPPRESSIONS=("--suppressions=$NMTST_SUPPRESSIONS")
else
NMTST_SUPPRESSIONS=()
fi
LOGFILE="${TEST}.valgrind-log"
export G_SLICE=always-malloc
@ -190,7 +207,7 @@ export G_DEBUG=gc-friendly
--error-exitcode=$VALGRIND_ERROR \
--leak-check=full \
--gen-suppressions=all \
--suppressions="$SUPPRESSIONS" \
"${NMTST_SUPPRESSIONS[@]}" \
--num-callers=100 \
--log-file="$LOGFILE" \
"$TEST" \