2006-12-21 01:30:28 -05:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Calculate coverage of source files
|
|
|
|
#
|
|
|
|
|
|
|
|
gcovflags=-n
|
|
|
|
|
|
|
|
usage ()
|
|
|
|
{
|
|
|
|
cat <<EOF
|
|
|
|
usage: coverage [OPTIONS] [output-files]
|
|
|
|
where OPTIONS are:
|
|
|
|
--output generate .gcov files
|
|
|
|
--help -h -? print this message
|
|
|
|
EOF
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--output ) gcovflags= ; shift ;;
|
|
|
|
'-?' | -h | --help ) usage ;;
|
|
|
|
- ) shift ; break ;;
|
|
|
|
-* ) usage 1 ;;
|
|
|
|
* ) break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
{
|
|
|
|
for f in *.bb
|
2008-12-16 13:05:22 -05:00
|
|
|
do
|
2006-12-21 01:30:28 -05:00
|
|
|
test "$f" = "*.bb" && { echo "run 'make check' first"; exit 1; }
|
|
|
|
gcov $gcovflags "$f" 2>/dev/null
|
2008-12-16 13:05:22 -05:00
|
|
|
done
|
2006-12-21 01:30:28 -05:00
|
|
|
for f in $@
|
2008-12-16 13:05:22 -05:00
|
|
|
do
|
2006-12-21 01:30:28 -05:00
|
|
|
gcov $gcovflags "$f" 2>/dev/null
|
2008-12-16 13:05:22 -05:00
|
|
|
done
|
2006-12-21 01:30:28 -05:00
|
|
|
} |
|
|
|
|
awk '
|
|
|
|
BEGIN {
|
|
|
|
'"$(for f in "$@"; do echo 'include["'$f'"] = 1;'; done)"'
|
|
|
|
}
|
|
|
|
|
|
|
|
/^File/ {
|
|
|
|
if (sub(/^File `\/home\/ppessi\/sofia-proxy\/(proxy\/..\/)?/, "")) {
|
|
|
|
sub(/.$/, "");
|
|
|
|
file=$0;
|
|
|
|
if (file ~ /torture/) file = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
file = "";
|
|
|
|
}
|
2008-12-16 13:05:22 -05:00
|
|
|
file ~ /\.[hc]$/ && /Lines executed/ {
|
|
|
|
sub(/Lines executed:/, "");
|
2006-12-21 01:30:28 -05:00
|
|
|
covered = int($3*$1/100 + 0.5);
|
2008-12-16 13:05:22 -05:00
|
|
|
|
2006-12-21 01:30:28 -05:00
|
|
|
# printf "%-5u %-5u %-5u %-7s %s\n", $3, covered, $3 - covered, $1, file;
|
|
|
|
if ($3 == 0) {
|
|
|
|
/* skip */
|
|
|
|
}
|
|
|
|
else if (!lines[file]) {
|
|
|
|
names[i++] = file; lines[file] = $3; coverage[file] = covered;
|
|
|
|
coverage[file] = $3*$1/100;
|
|
|
|
}
|
|
|
|
else if (coverage[file] < covered) {
|
|
|
|
lines[file] = $3; coverage[file] = covered;
|
|
|
|
coverage[file] = $3*$1/100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-16 13:05:22 -05:00
|
|
|
/torture/ { next; }
|
2006-12-21 01:30:28 -05:00
|
|
|
/test/ { next; }
|
|
|
|
/\/usr\/include/ { next; }
|
|
|
|
|
2008-12-16 13:05:22 -05:00
|
|
|
/(source )?lines executed in file (.*\/)?[-A-Za-z_0-9]+\.[ch]/ {
|
2006-12-21 01:30:28 -05:00
|
|
|
file = $0;
|
|
|
|
sub(/.* in file /, "", file);
|
|
|
|
sub(/.*\//, "", file);
|
|
|
|
covered = int($3*$1/100 + 0.5);
|
|
|
|
#printf "%-5u %-5u %-5u %-7s %s\n", $3, covered, $3 - covered, $1, file;
|
|
|
|
|
|
|
|
if ($3 == 0) {
|
|
|
|
/* skip */
|
|
|
|
}
|
|
|
|
else if (!file in lines) {
|
|
|
|
lines[file] = $3; coverage[file] = $3*$1/100;
|
|
|
|
}
|
|
|
|
else if (coverage[file] <= $3*$1/100) {
|
|
|
|
lines[file] = $3; coverage[file] = $3*$1/100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
for (file in lines) {
|
|
|
|
if (!(file in include))
|
|
|
|
continue;
|
|
|
|
l = lines[file]; c = coverage[file];
|
|
|
|
covered = int(c + 0.5);
|
|
|
|
total += l; total_coverage += c;
|
2008-12-16 13:05:22 -05:00
|
|
|
printf "%-5u %-5u %-5u %6.2f%% %s\n",
|
2006-12-21 01:30:28 -05:00
|
|
|
l, covered, l - covered, 100.0 * c / l, file;
|
|
|
|
}
|
|
|
|
if (total) {
|
|
|
|
module = ENVIRON["PWD"];
|
|
|
|
gsub(/\/+$/, "", module);
|
|
|
|
gsub(/.*\//, "", module);
|
|
|
|
printf "%-5u %-5u %-5u %6.2f%% %s in %s\n",
|
|
|
|
total, total_coverage, total - total_coverage,
|
|
|
|
100.0 * total_coverage / total, "TOTAL", module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
' |
|
|
|
|
sort -n
|