1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#! /bin/sh
formatter=fmt_text
do_coverage () {
if [ $# -eq 0 ]
then
set x *.o
shift
if [ $# -eq 0 ]
then
echo "I'm confused - where are all the object files?" >&2
exit 1
fi
fi
for objfile
do
gcov $objfile
done
}
get_file_info () {
cat "$@" | expand | cut -c1-16 | sed -e 's/^ *//' -e 's/ *$//'
}
do_hits () {
get_file_info "$@" | egrep -c "^ *[0-9]+ *$"
}
do_misses () {
get_file_info "$@" | egrep -c "^ *###### *$"
}
do_all2 () {
# set -x
awk '
function endfile (m, h, of, f) {
if (length(of)) {
printf("%10d %10d %s\n", m, h, of);
misses=0; hits=0;
}
}
BEGIN { misses=0; hits=0; }
{
if (FILENAME != oldfile) {
endfile(misses, hits, oldfile, FILENAME);
oldfile = FILENAME;
}
}
END {
endfile(misses, hits, oldfile, FILENAME);
}
/^ *######/ { ++misses; }
/^ *[0-9]+/ { ++hits; }
' "$@" < /dev/null
}
do_summary () {
if [ $# -eq 0 ]
then
set x *.gcov
shift
if [ $# -eq 0 ]
then
echo "I'm confused - did you run the 'coverage' command first?" >&2
exit 1
fi
fi
do_all2 "$@" | sort -rn | $formatter
# do_all2 "$@"
}
do_detail () {
less -j9 "+/######" *.gcov
}
usage () {
exec >&2
cat <<EOF
usage: $0 summary|coverage [object file list]
EOF
exit 1
}
fmt_text () {
awk '{printf("%10d %10d %s\n", $1, $2, $3);}'
}
fmt_html () {
NOW="$(date)"
cat<<EOF
<html>
<head>
<title>Test Suite Coverage Summary</title>
</head>
<body>
<h1>Test Suite Coverage Summary</h1>
These tests were run at $NOW
<br>
<table border="1">
<tr><th> Misses </th><th> Hits </th><th> Filename </th></tr>
EOF
while read m h f
do
printf "<tr><td>%d</td><td>%d</td><td>%s</td></tr>\n" \
$m $h "$f"
done
cat <<EOF
</table>
</body>
</html>
EOF
}
do_f_option () {
case "$1" in
text) formatter=fmt_text ;;
html) formatter=fmt_html ;;
*) echo "Unknown formatting method $1" >&2; usage ;;
esac
}
do_sub_command () {
while [ $# -gt 0 ]
do
case "$1" in
-f) do_f_option "$2" ; shift 2 ;;
summary) shift; do_summary "$@" ; exit $? ;;
detail) shift; do_detail "$@" ; exit $? ;;
coverage) shift; do_coverage "$@" ; exit $? ;;
*) usage ;;
esac
done
}
do_sub_command "$@"
|