Git 1.7.2.5
[git/jnareb-git/bp-gitweb.git] / t / valgrind / analyze.sh
blobd8105d9fabc3d0b0cb818d8c5504832f63c96b3e
1 #!/bin/sh
3 out_prefix=$(dirname "$0")/../test-results/valgrind.out
4 output=
5 count=0
6 total_count=0
7 missing_message=
8 new_line='
11 # start outputting the current valgrind error in $out_prefix.++$count,
12 # and the test case which failed in the corresponding .message file
13 start_output () {
14 test -z "$output" || return
16 # progress
17 total_count=$(($total_count+1))
18 test -t 2 && printf "\rFound %d errors" $total_count >&2
20 count=$(($count+1))
21 output=$out_prefix.$count
22 : > $output
24 echo "*** $1 ***" > $output.message
27 finish_output () {
28 test ! -z "$output" || return
29 output=
31 # if a test case has more than one valgrind error, we need to
32 # copy the last .message file to the previous errors
33 test -z "$missing_message" || {
34 while test $missing_message -lt $count
36 cp $out_prefix.$count.message \
37 $out_prefix.$missing_message.message
38 missing_message=$(($missing_message+1))
39 done
40 missing_message=
44 # group the valgrind errors by backtrace
45 output_all () {
46 last_line=
47 j=0
48 i=1
49 while test $i -le $count
51 # output <number> <backtrace-in-one-line>
52 echo "$i $(tr '\n' ' ' < $out_prefix.$i)"
53 i=$(($i+1))
54 done |
55 sort -t ' ' -k 2 | # order by <backtrace-in-one-line>
56 while read number line
58 # find duplicates, do not output backtrace twice
59 if test "$line" != "$last_line"
60 then
61 last_line=$line
62 j=$(($j+1))
63 printf "\nValgrind error $j:\n\n"
64 cat $out_prefix.$number
65 printf "\nfound in:\n"
67 # print the test case where this came from
68 printf "\n"
69 cat $out_prefix.$number.message
70 done
73 handle_one () {
74 OLDIFS=$IFS
75 IFS="$new_line"
76 while read line
78 case "$line" in
79 # backtrace, possibly a new one
80 ==[0-9]*)
82 # Does the current valgrind error have a message yet?
83 case "$output" in
84 *.message)
85 test -z "$missing_message" &&
86 missing_message=$count
87 output=
88 esac
90 start_output $(basename $1)
91 echo "$line" |
92 sed 's/==[0-9]*==/==valgrind==/' >> $output
94 # end of backtrace
95 '}')
96 test -z "$output" || {
97 echo "$line" >> $output
98 test $output = ${output%.message} &&
99 output=$output.message
102 # end of test case
104 finish_output
106 # normal line; if $output is set, print the line
108 test -z "$output" || echo "$line" >> $output
110 esac
111 done < $1
112 IFS=$OLDIFS
114 # just to be safe
115 finish_output
118 for test_script in "$(dirname "$0")"/../test-results/*.out
120 handle_one $test_script
121 done
123 output_all