Add spec file
[jansson.git] / test / scripts / valgrind.sh
1 # Copyright (c) 2009-2011 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     test_runner="$VALGRIND_CMDLINE"
12     json_process="$VALGRIND_CMDLINE $json_process"
13 else
14     test_runner=""
15 fi
16
17 valgrind_check() {
18     if [ $VALGRIND -eq 1 ]; then
19         # Check for Valgrind error output. The valgrind option
20         # --error-exitcode is not enough because Valgrind doesn't
21         # think unfreed allocs are errors.
22         if grep -E -q '^==[0-9]+== ' $1; then
23             touch $test_log/valgrind_error
24             return 1
25         fi
26     fi
27 }
28
29 valgrind_show_error() {
30     if [ $VALGRIND -eq 1 -a -f $test_log/valgrind_error ]; then
31         echo "valgrind detected an error"
32         return 0
33     fi
34     return 1
35 }