Skip to content

Commit a3db0dc

Browse files
Add coverage to the unit test framework.
1 parent f35ce4f commit a3db0dc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

mythtv/libs/libmythbase/test/test_mythtimer/test_mythtimer.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ TARGET = test_mythtimer
66
DEPENDPATH += . ../..
77
INCLUDEPATH += . ../..
88

9+
eval(QMAKE_CXX = g++) {
10+
QMAKE_CXXFLAGS += -O0 -fprofile-arcs -ftest-coverage
11+
QMAKE_LFLAGS += -fprofile-arcs
12+
}
13+
914
# Input
1015
HEADERS += test_mythtimer.h
1116
SOURCES += test_mythtimer.cpp
@@ -14,3 +19,4 @@ HEADERS += mythtimer.h
1419
SOURCES += mythtimer.cpp
1520

1621
QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)
22+
QMAKE_CLEAN += ; rm -f *.gcov *.gcda *.gcno

mythtv/programs/scripts/unittests.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@
55
DIRNAME=`which dirname`
66
BASENAME=`which basename`
77
SED=`which sed`
8+
GCOV=`which gcov`
9+
GREP=`which grep`
810
TEST_FAILED=0
911

1012

1113
TESTS=`find -name "test_*.pro"`
1214

1315
for TEST in $TESTS
1416
do
15-
PATH=`$DIRNAME $TEST`
17+
FPATH=`$DIRNAME $TEST`
1618
EXEC=`$BASENAME $TEST | $SED -e 's/.pro//'`
17-
RUNNABLE=$PATH/$EXEC
19+
COV=`$BASENAME $TEST | $SED -e 's/test_//' | $SED -e 's/.pro/.cpp/'`
20+
COVGCNO=`$BASENAME $TEST | $SED -e 's/test_//' | $SED -e 's/.pro/.gcno/'`
21+
RUNNABLE=$FPATH/$EXEC
1822
if test -x $RUNNABLE -a -f $RUNNABLE ; then
1923
if ./$RUNNABLE ; then
24+
if test -x $GCOV -a -f $FPATH/$COVGCNO ; then
25+
P=`pwd` ; cd $FPATH # pushd==
26+
LINES=`$GCOV $COV | $GREP Lines | $SED -e 's/Lines//'`
27+
echo Coverage: $COV $LINES. See $FPATH/$COV.gcov for details
28+
cd $P # popd==
29+
fi
2030
echo
2131
else
2232
echo "error: A unit test failed."

0 commit comments

Comments
 (0)