summaryrefslogtreecommitdiff
path: root/test/generate-gcov-report.sh
blob: 2d9137100c4208f79a0b18bceb9e42981311cde4 (plain)
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
#!/bin/bash -e

if [[ $# -lt 2 ]]; then
    echo "Usage: ./generate-gcov-report.sh <rel-target-dir> <srcdir> [<srcdir> ... ]"
    exit 1
fi

target_dir=$1
shift
source_dirs=$*

if [[ "${target_dir:0:1}" != '/' ]]; then
    target_dir="$PWD/$target_dir"
fi
summary_file="$target_dir/summary.txt"

mkdir -p "$target_dir"
rm -f "$target_dir"/*.gcov

for dir in $source_dirs; do
	pushd "$dir" > /dev/null
	for file in *.c; do
		find ./ -name "*${file/\.c/.gcda}" \
			\!  -path "*selftest*" \
			-exec gcov {} \; > /dev/null
	done
	find ./ -name "*.gcov" \
		\! -path "*/`basename "$target_dir"`/*" \
		-exec mv {} "$target_dir" \;
	popd > /dev/null
done

echo "========== coverage report ========" > "$summary_file"
for file in "$target_dir"/*.gcov; do
	total=`grep -v " -:" "$file" | wc -l`
	missing=`grep "#####" "$file" | wc -l`
	hit=$((total - missing));
	percent=$((($hit * 100)/$total))
	fname=`basename "$file"`
	printf "%-50s total lines: %4s not tested: %4s (%3s%%)\n" "$fname" "$total" "$missing" "$percent">> "$summary_file"
done
echo "========== =============== ========" >> "$summary_file"