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