source: branches/stable/UNIT_TESTER/valgrind/arb_valgrind_logged

Last change on this file was 11166, checked in by westram, 11 years ago
  • let valgrind fail external valgrinded calls done from inside unittests with exitcode!=0 (if it detects errors)
    • if caller does not check the exitcode (or if test-success does not rely on exitcode==0) the whole testsuite still may succeed, even if some valgrind errors were reported (in external call)
  • Property svn:executable set to *
File size: 3.6 KB
Line 
1#!/bin/bash 
2
3BASEDIR=$ARBHOME/UNIT_TESTER/valgrind
4LOGGING_BASE=$BASEDIR/arb_valgrind_logging_
5LOGGED_BASE=$BASEDIR/arb_valgrind_logged_
6
7CALL() {
8    local LOGGING=$LOGGING_BASE$$.log
9    local LOGGED=$LOGGED_BASE$$.log
10    local EXE=$1
11    shift
12    arb_valgrind -e -L $LOGGED.stdout -E $LOGGED.stderr $EXE "$@" > $LOGGING
13    local EXITCODE=$?
14    sleep 2
15    cp $LOGGING $LOGGED
16    rm $LOGGING
17    cat $LOGGED.stdout
18    rm $LOGGED.stdout
19    cat $LOGGED.stderr 1>&2
20    rm $LOGGED.stderr
21    return $EXITCODE
22}
23
24rm_if() {
25    ( test -f $1 && rm $1 ) || true
26}
27
28have_logging() {
29    ls -1 $LOGGING_BASE*.log > /dev/null 2>&1
30    if [ "$?" = "0" ]; then
31        echo "1"
32    else
33        echo "0"
34    fi
35}
36have_logged() {
37    ls -1 $LOGGED_BASE*.log > /dev/null 2>&1
38    if [ "$?" = "0" ]; then
39        echo "1"
40    else
41        echo "0"
42    fi
43}
44
45count_logging() { 
46    if [ `have_logging` == 1 ]; then
47        echo $LOGGING_BASE*.log | wc -w
48    else
49        echo "0"
50    fi
51}
52count_logged() {
53    if [ `have_logged` == 1 ]; then
54        echo $LOGGED_BASE*.log | wc -w
55    else
56        echo "0"
57    fi
58}
59
60remove_flags() {
61    rm_if $BASEDIR/flag.valgrind
62    rm_if $BASEDIR/flag.valgrind.leaks
63    rm_if $BASEDIR/flag.valgrind.reachable
64    rm_if $BASEDIR/flag.valgrind.callseen
65}
66
67INIT() { 
68    if [ `have_logging` == 1 ]; then
69        rm $LOGGING_BASE*.log
70    fi
71   
72    if [ `have_logged` == 1 ]; then
73        rm $LOGGED_BASE*.log
74    fi
75
76    shift
77    local VALGRIND=$1
78    local CHECK_LEAKS=$2
79
80    remove_flags
81    if [ "$VALGRIND" == "E" ]; then
82        touch $BASEDIR/flag.valgrind
83        if [ "$CHECK_LEAKS" == "1" ]; then
84            touch $BASEDIR/flag.valgrind.leaks
85        fi
86        if [ "$CHECK_LEAKS" == "2" ]; then
87            touch $BASEDIR/flag.valgrind.leaks
88            touch $BASEDIR/flag.valgrind.reachable
89        fi
90    fi
91
92    # ls -al $BASEDIR
93}
94
95wait_all_valgrinds_complete() {
96    local WAIT=
97    local COUNT=`count_logging`
98    if [ "$COUNT" != "0" ]; then
99        while [ "$COUNT" != "0" ]; do
100            echo "arb_valgrind_logged sees $COUNT pending logs - waiting until they complete"
101            sleep 1
102            COUNT=`count_logging`
103            WAIT=x$WAIT
104            if [ "$WAIT" == "xxxxxxxxxxxxxxx" ]; then # wait 15 seconds
105                echo "Giving up"
106                false
107                return
108            fi
109        done
110        echo "all logs completed (i.e. all async valgrinds terminated)"
111    fi
112}
113
114dump_and_unlink() {
115    echo "---------- [ valgrind $1 ]"
116    cat $1
117    rm $1
118    echo "---------- [ end $1 ]"
119}
120
121dump_all() {
122    while [ ! -z "$1" ]; do
123        dump_and_unlink $1
124        shift
125    done
126}
127
128dump_all_logged() {
129    local COUNT=`count_logged`
130    if [ "$COUNT" == "0" ]; then
131        echo "Found no logs to dump"
132    else
133        echo "Dumping $COUNT logs:"
134        dump_all $LOGGED_BASE*.log
135    fi
136}
137
138WAIT() {
139    wait_all_valgrinds_complete
140    dump_all_logged
141    remove_flags
142}
143
144usage() {
145    echo "Usage: arb_valgrind_logged INIT"
146    echo "    delete any leftover logs"
147    echo ""
148    echo "Usage: arb_valgrind_logged CALL arb_valgrind-args"
149    echo "    Calls arb_valgrind asynchronously and redirects output into temp. logfile."
150    echo ""
151    echo "Usage: arb_valgrind_logged WAIT"
152    echo "    wait until all async calls terminate (=until all logs complete)"
153    echo "    then dump all logs (synchronously)"
154}
155
156if [ "$1" == "WAIT" ]; then
157    WAIT
158else
159    if [ "$1" == "INIT" ]; then
160        INIT $@
161    else
162        if [ "$1" == "CALL" ]; then
163            shift
164            CALL "$@"
165        else
166            usage
167            false
168        fi
169    fi
170fi
Note: See TracBrowser for help on using the repository browser.