2015-11-23 18:23:45 +00:00
#!/bin/bash
die( ) {
echo " $@ "
exit 5
}
SCRIPT_PATH = " ${ SCRIPT_PATH :- $( readlink -f " $( dirname " $0 " ) " ) } "
2013-07-26 12:16:47 +00:00
2015-06-04 15:24:08 +00:00
VALGRIND_ERROR = 37
2016-10-15 13:34:05 +00:00
2015-11-23 18:23:45 +00:00
if [ " $1 " = = "--called-from-make" ] ; then
shift
NMTST_LIBTOOL = ( $1 --mode= execute) ; shift
NMTST_VALGRIND = " $1 " ; shift
2016-10-15 14:24:59 +00:00
NMTST_CHANGE_DIRECTORY =
if [ [ " $NMTST_VALGRIND " = = no ] ] ; then
NMTST_VALGRIND =
fi
2015-11-23 18:23:45 +00:00
SUPPRESSIONS = " $1 " ; shift
if [ " $1 " = "--launch-dbus" ] ; then
NMTST_LAUNCH_DBUS = yes
shift
2016-10-15 14:24:59 +00:00
elif [ " $1 " = "--launch-dbus=auto" ] ; then
NMTST_LAUNCH_DBUS =
shift
2015-11-23 18:23:45 +00:00
else
NMTST_LAUNCH_DBUS = no
fi
TEST = " $1 " ; shift
2016-10-15 13:34:05 +00:00
2015-11-23 18:23:45 +00:00
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
; ;
2016-10-15 13:34:05 +00:00
"--valgrind" )
NMTST_NO_VALGRIND =
NMTST_VALGRIND = valgrind
shift;
; ;
"--no-valgrind" )
NMTST_NO_VALGRIND = no
NMTST_VALGRIND = ""
shift;
; ;
2015-11-23 18:23:45 +00:00
"--" )
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
2016-10-15 14:24:59 +00:00
fi
2015-11-23 18:23:45 +00:00
2016-10-15 14:24:59 +00:00
[ -x " $TEST " ] || die " Test \" $TEST \" does not exist "
TEST_PATH = " $( readlink -f " $( dirname " $TEST " ) " ) "
2015-11-23 18:23:45 +00:00
2016-10-15 14:24:59 +00:00
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
2015-11-23 18:23:45 +00:00
fi
2016-10-15 14:24:59 +00:00
fi
2015-11-23 18:23:45 +00:00
2016-10-15 14:24:59 +00:00
# some tests require you to cd into the base directory.
# do that.
if [ " $NMTST_CHANGE_DIRECTORY " != "" ] ; then
cd " $TEST_PATH "
TEST = " ./ $( basename " $TEST " ) "
2015-11-23 18:23:45 +00:00
fi
2016-01-22 14:57:46 +00:00
NMTST_DBUS_RUN_SESSION = ( )
2015-11-23 18:23:45 +00:00
if [ " $NMTST_LAUNCH_DBUS " = = "yes" ] ; then
2016-01-22 14:57:46 +00:00
if ! which dbus-run-session & >/dev/null ; then
eval ` dbus-launch --sh-syntax`
trap " kill $DBUS_SESSION_BUS_PID " EXIT
else
NMTST_DBUS_RUN_SESSION = ( dbus-run-session --)
fi
2015-02-08 10:52:22 +00:00
fi
2013-07-26 12:16:47 +00:00
2016-10-15 13:34:05 +00:00
[ -x " $TEST " ] || die " Cannot execute test \" $TEST \" "
if [ " $NMTST_NO_VALGRIND " != "" -o " $NMTST_VALGRIND " = = "" ] ; then
2016-10-15 13:57:33 +00:00
" ${ NMTST_DBUS_RUN_SESSION [@] } " \
" $TEST " " $@ "
exit $?
2015-02-09 14:46:15 +00:00
fi
2016-10-15 13:34:05 +00:00
2015-12-05 19:21:55 +00:00
LOGFILE = " ${ TEST } .valgrind-log "
2013-07-26 12:16:47 +00:00
export G_SLICE = always-malloc
export G_DEBUG = gc-friendly
2016-01-22 14:57:46 +00:00
" ${ NMTST_DBUS_RUN_SESSION [@] } " \
2016-10-15 13:34:05 +00:00
" ${ NMTST_LIBTOOL [@] } " \
" $NMTST_VALGRIND " \
2016-10-15 13:57:33 +00:00
--quiet \
--error-exitcode= $VALGRIND_ERROR \
--leak-check= full \
--gen-suppressions= all \
--suppressions= " $SUPPRESSIONS " \
--num-callers= 100 \
--log-file= " $LOGFILE " \
" $TEST " \
" $@ "
2013-07-26 12:16:47 +00:00
RESULT = $?
2015-06-04 15:24:08 +00:00
test -s " $LOGFILE "
HAS_ERRORS = $?
2015-02-08 18:28:55 +00:00
2015-02-04 09:34:05 +00:00
if [ $RESULT -ne 0 -a $RESULT -ne 77 ] ; then
2016-10-15 13:57:33 +00:00
if [ $HAS_ERRORS -ne 0 ] ; then
rm -f " $LOGFILE "
elif [ $RESULT -ne $VALGRIND_ERROR ] ; then
# the test (probably) didn't fail due to valgrind.
echo "The test failed. Also check the valgrind log at '`realpath " $LOGFILE "`'" >& 2
else
echo "valgrind failed! Check the log at '`realpath " $LOGFILE "`'" >& 2
UNRESOLVED = $( awk -F: '/obj:\// {print $NF}' " $LOGFILE " | sort | uniq)
if [ -n " $UNRESOLVED " ] ; then
echo Some addresses could not be resolved into symbols. >& 2
echo The errors might get suppressed when you install the debuging symbols. >& 2
if [ -x /usr/bin/dnf ] ; then
echo Hint: dnf debuginfo-install $UNRESOLVED >& 2
elif [ -x /usr/bin/debuginfo-install ] ; then
echo Hint: debuginfo-install $UNRESOLVED >& 2
else
echo Files without debugging symbols: $UNRESOLVED >& 2
fi
fi
fi
exit $RESULT
2013-07-26 12:16:47 +00:00
fi
2016-02-19 00:06:28 +00:00
if [ $HAS_ERRORS -eq 0 ] ; then
2016-10-15 13:57:33 +00:00
# valgrind doesn't support setns syscall and spams the logfile.
# hack around it...
if [ " $( basename " $TEST " ) " = 'test-link-linux' -a -z " $( sed -e '/^--[0-9]\+-- WARNING: unhandled .* syscall: /,/^--[0-9]\+-- it at http.*\.$/d' " $LOGFILE " ) " ] ; then
HAS_ERRORS = 1
fi
2016-02-19 00:06:28 +00:00
fi
2015-06-04 15:24:08 +00:00
if [ $HAS_ERRORS -eq 0 ] ; then
2016-10-15 13:57:33 +00:00
# shouldn't actually happen...
echo "valgrind succeeded, but log is not empty: '`realpath " $LOGFILE "`'" >& 2
exit 1
2015-06-04 15:24:08 +00:00
fi
rm -f " $LOGFILE "
2015-06-04 10:30:30 +00:00
2013-07-26 12:16:47 +00:00
exit $RESULT