summaryrefslogtreecommitdiff
path: root/tools/run-test-valgrind.sh
blob: 1b4e2c2f9b680016614be447adc73e45201f9974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

LIBTOOL="$1"; shift
VALGRIND="$1"; shift
SUPPRESSIONS="$1"; shift
if [ "$1" = "--launch-dbus" ]; then
    # Spawn DBus
    eval `dbus-launch --sh-syntax`
    trap "kill $DBUS_SESSION_BUS_PID" EXIT
    shift
fi
TEST="$1"

if [ "$NMTST_NO_VALGRIND" != "" ]; then
	"$@"
	exit $?
fi

LOGFILE="valgrind-`echo "$TEST" | tr -cd '[:alpha:]-'`.log"

export G_SLICE=always-malloc
export G_DEBUG=gc-friendly
$LIBTOOL --mode=execute "$VALGRIND" \
	--quiet \
	--error-exitcode=1 \
	--leak-check=full \
	--gen-suppressions=all \
	--suppressions="$SUPPRESSIONS" \
	--log-file="$LOGFILE" \
	"$@"
RESULT=$?

if [ $RESULT -eq 0 -a "$(wc -c "$LOGFILE" | awk '{print$1}')" -ne 0 ]; then
	echo "valgrind succeeded, but log is not empty: $LOGFILE"
	exit 1
fi

if [ $RESULT -ne 0 -a $RESULT -ne 77 ]; then
	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