1#!/bin/bash -e 2 3if [[ $# -lt 2 ]]; then 4 echo "Usage: ./generate-gcov-report.sh <rel-target-dir> <srcdir> [<srcdir> ... ]" 5 exit 1 6fi 7 8target_dir=$1 9shift 10source_dirs=$* 11 12if [[ "${target_dir:0:1}" != '/' ]]; then 13 target_dir="$PWD/$target_dir" 14fi 15summary_file="$target_dir/summary.txt" 16 17mkdir -p "$target_dir" 18rm -f "$target_dir"/*.gcov 19 20for 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 31done 32 33echo "========== coverage report ========" > "$summary_file" 34for 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" 41done 42echo "========== =============== ========" >> "$summary_file" 43