7c23c791e3c60cd7abc30d70d8fbb6a2a6dc22fc
[jansson.git] / test / scripts / valgrind.sh
1 # Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
2 #
3 # Jansson is free software; you can redistribute it and/or modify
4 # it under the terms of the MIT license. See LICENSE for details.
5
6 [ -z "$VALGRIND" ] && VALGRIND=0
7
8 VALGRIND_CMDLINE="valgrind --leak-check=full --show-reachable=yes --track-origins=yes -q"
9
10 if [ $VALGRIND -eq 1 ]; then
11     json_process="$VALGRIND_CMDLINE $json_process"
12 fi
13
14 valgrind_check() {
15     if [ $VALGRIND -eq 1 ]; then
16         # Check for Valgrind error output. The valgrind option
17         # --error-exitcode is not enough because Valgrind doesn't
18         # think unfreed allocs are errors.
19         if grep -E -q '^==[0-9]+== ' $1; then
20             touch $test_log/valgrind_error
21             return 1
22         fi
23     fi
24 }
25
26 valgrind_show_error() {
27     if [ $VALGRIND -eq 1 -a -f $test_log/valgrind_error ]; then
28         echo "valgrind detected an error"
29         return 0
30     fi
31     return 1
32 }