#!/bin/sh # Get TEST_OUTPUT_DIRECTORY from GIT-BUILD-OPTIONS if it's there... source "$(dirname "$0")/../../GIT-BUILD-OPTIONS" # ... otherwise set it to the default value. : $(TEST_OUTPUT_DIRECTORY=$(dirname "$0")/..) setglobal output = '' setglobal count = '0' setglobal total_count = '0' setglobal missing_message = '' setglobal new_line = '' '' # start outputting the current valgrind error in $out_prefix.++$count, # and the test case which failed in the corresponding .message file proc start_output { test -z $output || return # progress setglobal total_count = $shExpr('$total_count+1') test -t 2 && printf "\rFound %d errors" $total_count >&2 setglobal count = $shExpr('$count+1') setglobal output = "$out_prefix.$count" : > $output echo "*** $1 ***" > $output.message } proc finish_output { test ! -z $output || return setglobal output = '' # if a test case has more than one valgrind error, we need to # copy the last .message file to the previous errors test -z $missing_message || do { while test $missing_message -lt $count { cp $out_prefix.$count.message \ $out_prefix.$missing_message.message setglobal missing_message = $shExpr('$missing_message+1') } setglobal missing_message = '' } } # group the valgrind errors by backtrace proc output_all { setglobal last_line = '' setglobal j = '0' setglobal i = '1' while test $i -le $count { # output echo "$i $[tr '\n' ' ]" setglobal i = $shExpr('$i+1') } | sort -t ' ' -k 2 | # order by while read number line { # find duplicates, do not output backtrace twice if test $line != $last_line { setglobal last_line = $line setglobal j = $shExpr('$j+1') printf "\nValgrind error $j:\n\n" cat $out_prefix.$number printf "\nfound in:\n" } # print the test case where this came from printf "\n" cat $out_prefix.$number.message } } proc handle_one { setglobal OLDIFS = $IFS setglobal IFS = $new_line while read line { match $line { # backtrace, possibly a new one with ==[0-9]* # Does the current valgrind error have a message yet? match $output { with *.message test -z $missing_message && setglobal missing_message = $count setglobal output = '' } start_output $[basename $1] echo $line | sed 's/==[0-9]*==/==valgrind==/' >> $output # end of backtrace with '}' test -z $output || do { echo $line >> $output test $output = $(output%.message) && setglobal output = "$output.message" } # end of test case with '' finish_output # normal line; if $output is set, print the line with * test -z $output || echo $line >> $output } } < $1 setglobal IFS = $OLDIFS # just to be safe finish_output } for test_script in ["$TEST_OUTPUT_DIRECTORY"/test-results/*.out] { handle_one $test_script } output_all