Debian Codegraph @

test/generate-gcov-report.sh

raw
1 #!/bin/bash -e
2
3 if [[ $# -lt 2 ]]; then
4 echo "Usage: ./generate-gcov-report.sh <rel-target-dir> <srcdir> [<srcdir> ... ]"
5 exit 1
6 fi
7
8 target_dir=$1
9 shift
10 source_dirs=$*
11
12 if [[ "${target_dir:0:1}" != '/' ]]; then
13 target_dir="$PWD/$target_dir"
14 fi
15 summary_file="$target_dir/summary.txt"
16
17 mkdir -p "$target_dir"
18 rm -f "$target_dir"/*.gcov
19
20 for dir in $source_dirs; do
21 pushd "$dir" > /dev/null
22 for file in *.c; do
23 find ./ -name "*${file/\.c/.gcda}" \
24 \! -path "*selftest*" \
25 -exec gcov {} \; > /dev/null
26 done
27 find ./ -name "*.gcov" \
28 \! -path "*/`basename "$target_dir"`/*" \
29 -exec mv {} "$target_dir" \;
30 popd > /dev/null
31 done
32
33 echo "========== coverage report ========" > "$summary_file"
34 for file in "$target_dir"/*.gcov; do
35 total=`grep -v " -:" "$file" | wc -l`
36 missing=`grep "#####" "$file" | wc -l`
37 hit=$((total - missing));
38 percent=$((($hit * 100)/$total))
39 fname=`basename "$file"`
40 printf "%-50s total lines: %4s not tested: %4s (%3s%%)\n" "$fname" "$total" "$missing" "$percent">> "$summary_file"
41 done
42 echo "========== =============== ========" >> "$summary_file"