1#!/bin/bash
2#
3# Run code coverage on fsck_msdos
4#
5# To use this script, you must have already built fsck_msdos using the
6# CodeCoverage configuration.  You can do that by:
7#	xcodebuild -target fsck_msdos -configuration CodeCoverage
8#
9
10OBJECTS=build/msdosfs.build/CodeCoverage/fsck_msdos.build/Objects-normal/`arch`
11
12# Remove any pre-existing samples
13rm -f $OBJECTS/*.gcda *.gcov
14
15# Run the tests
16python test_fsck.py build/CodeCoverage/fsck_msdos || exit
17
18# Run gcov on each source file
19for FILE in fsck_msdos.tproj/*.c; do
20	gcov -o $OBJECTS $FILE
21done
22
23# Produce summaries for each file
24for FILE in *.gcov; do
25	cat $FILE | awk 'BEGIN {total=0; covered=0}
26		{if($1 != "-:") { total++; if($1 != "#####:") covered++}}
27		END {printf("%f%% of %d lines covered", 100 * covered/total, total)}'
28	echo " for ${FILE%.gcov}"
29done
30
31# Produce an overall percentage of coverage
32find . -name "*.gcov" | xargs cat | awk 'BEGIN {total=0; covered=0}
33	{if($1 != "-:") { total++; if($1 != "#####:") covered++}}
34	END {printf("Total: %f%% of %d lines covered\n", 100 * covered/total, total)}'
35