#!/bin/sh
out_prefix=$(dirname "$0")/../test-results/valgrind.out
output=
count=0
total_count=0
missing_message=
new_line='
'
start_output () {
test -z "$output" || return
total_count=$(($total_count+1))
test -t 2 && printf "\rFound %d errors" $total_count >&2
count=$(($count+1))
output=$out_prefix.$count
: > $output
echo "*** $1 ***" > $output.message
}
finish_output () {
test ! -z "$output" || return
output=
test -z "$missing_message" || {
while test $missing_message -lt $count
do
cp $out_prefix.$count.message \
$out_prefix.$missing_message.message
missing_message=$(($missing_message+1))
done
missing_message=
}
}
output_all () {
last_line=
j=0
i=1
while test $i -le $count
do
echo "$i $(tr '\n' ' ' < $out_prefix.$i)"
i=$(($i+1))
done |
sort -t ' ' -k 2 | while read number line
do
if test "$line" != "$last_line"
then
last_line=$line
j=$(($j+1))
printf "\nValgrind error $j:\n\n"
cat $out_prefix.$number
printf "\nfound in:\n"
fi
printf "\n"
cat $out_prefix.$number.message
done
}
handle_one () {
OLDIFS=$IFS
IFS="$new_line"
while read line
do
case "$line" in
==[0-9]*)
case "$output" in
*.message)
test -z "$missing_message" &&
missing_message=$count
output=
esac
start_output $(basename $1)
echo "$line" |
sed 's/==[0-9]*==/==valgrind==/' >> $output
;;
'}')
test -z "$output" || {
echo "$line" >> $output
test $output = ${output%.message} &&
output=$output.message
}
;;
'')
finish_output
;;
*)
test -z "$output" || echo "$line" >> $output
;;
esac
done < $1
IFS=$OLDIFS
finish_output
}
for test_script in "$(dirname "$0")"/../test-results/*.out
do
handle_one $test_script
done
output_all