summaryrefslogtreecommitdiff
path: root/tests/valgrind-wrapper.in
blob: ed9a053d3e64c8abf18d0f242d1c66b5e62d5685 (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
#! /bin/sh

wrap_program=`basename '@wrap_program@'`

# Strip the first directory from $PATH that contains $wrap_program,
# so that below we run the real $wrap_program, not ourselves.
not_found=true
new_path=
first=true
save_IFS=$IFS
IFS=:
for dir in $PATH; do
    IFS=$save_IFS
    if $not_found && test -x "$dir/$wrap_program"; then
        not_found=false
    else
        if $first; then
            first=false
            new_path=$dir
        else
            new_path=$new_path:$dir
        fi
    fi
done
IFS=$save_IFS
if $not_found; then
    echo "$0: error: cannot find $wrap_program in \$PATH" >&2
    exit 1
fi
PATH=$new_path
export PATH

: ${VALGRIND:=valgrind -q --log-file=valgrind.%p --leak-check=full}
exec $VALGRIND $wrap_program "$@"
echo "$0: failed to execute $VALGRIND $wrap_program" "$@" >&2
exit 1