diff options
author | David Zeuthen <davidz@redhat.com> | 2007-11-03 14:40:13 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2007-11-03 14:40:13 -0400 |
commit | 1d037a7bc4180ba6a252ad2b8fc7e55bcbcd7551 (patch) | |
tree | e721f65209a0db67e6e34a5870a63f1906cc0f4a /test | |
parent | 7d149b6249bc94e0587e3a09d591df599cf26601 (diff) | |
download | polkit-1d037a7bc4180ba6a252ad2b8fc7e55bcbcd7551.tar.gz |
add unit test framework with gcov coverage support (make check-coverage)
This is what it looks like
==============================================================================
Test coverage for module polkit:
==============================================================================
polkit-sysdeps.c : 0% (0 of 38)
polkit-error.c : 0% (0 of 44)
polkit-result.c : 0% (0 of 16)
polkit-context.c : 0% (0 of 213)
polkit-action.c : 34% (20 of 58)
polkit-seat.c : 0% (0 of 34)
polkit-session.c : 0% (0 of 97)
polkit-caller.c : 0% (0 of 81)
polkit-policy-file-entry.c : 0% (0 of 72)
polkit-policy-file.c : 0% (0 of 220)
polkit-policy-cache.c : 0% (0 of 98)
polkit-policy-default.c : 0% (0 of 67)
polkit-debug.c : 0% (0 of 15)
polkit-utils.c : 0% (0 of 42)
polkit-config.c : 0% (0 of 263)
polkit-authorization.c : 0% (0 of 162)
polkit-authorization-constraint.c : 0% (0 of 107)
polkit-authorization-db.c : 0% (0 of 222)
Source lines : 6919
Actual statements : 1849
Executed statements : 20
Test coverage : 1%
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 5 | ||||
-rwxr-xr-x | test/create-coverage-report.sh | 57 |
2 files changed, 62 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..b37166c --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,5 @@ + +EXTRA_DIST = create-coverage-report.sh + +clean-local : + rm -f *~ diff --git a/test/create-coverage-report.sh b/test/create-coverage-report.sh new file mode 100755 index 0000000..336a5bd --- /dev/null +++ b/test/create-coverage-report.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +TOTAL_ACTUAL=0 +TOTAL_COVERED=0 +TOTAL_SOURCE=0 + +MODULE=$1 +shift + +echo "==============================================================================" +echo "Test coverage for module $MODULE:" +echo "==============================================================================" + +while [ $# -gt 0 ] ; do + gcov $1 -o .libs/ > /dev/null + + SOURCE=`cat $1 |wc -l` + ACTUAL=`grep -v " -:" $1.gcov |wc -l` + NOT_COVERED=`grep " #####:" $1.gcov |wc -l` + COVERED=$(($ACTUAL - $NOT_COVERED)) + PERCENT=$((100 * $COVERED / $ACTUAL)) + + TOTAL_SOURCE=$(($TOTAL_SOURCE + $SOURCE)) + TOTAL_ACTUAL=$(($TOTAL_ACTUAL + $ACTUAL)) + TOTAL_COVERED=$(($TOTAL_COVERED + $COVERED)) + + echo -n "$1" + + n=${#1} + while [ $n -lt 55 ] ; do + echo -n " " + n=$(($n + 1)) + done + + echo -n " : " + + if [ $PERCENT -lt 10 ] ; then + echo -n " $PERCENT%" + elif [ $PERCENT -lt 100 ] ; then + echo -n " $PERCENT%" + else + echo -n "100%" + fi + + echo " ($COVERED of $ACTUAL)" + + shift +done + +TOTAL_PERCENT=$((100 * $TOTAL_COVERED / $TOTAL_ACTUAL)) + +echo +echo "Source lines : $TOTAL_SOURCE" +echo "Actual statements : $TOTAL_ACTUAL" +echo "Executed statements : $TOTAL_COVERED" +echo "Test coverage : $TOTAL_PERCENT%" +echo |