Commit d926134d authored by Pekka Pessi's avatar Pekka Pessi

rules/*.am, Makefile.am, sac-general.m4: added lcov and covcheck targets

If there is a recent enough lcov available (> 1.5, in other words, a version
downloaded from ltp.cvs.sourceforge.net and available from
http://sofia-sip.org/~ppessi/) there are lcov and covcheck targets defined in
rules/coverage.am and rules/lcov.am for a nice coverage summary. Use
./configure --enable-coverage CFLAGS

darcs-hash:20070426154459-55b16-d8c47adad79067d70994b42644dedf19e24da4b5.gz
parent cd754f80
......@@ -59,4 +59,10 @@ coverage built-sources clean-built-sources valcheck doxygen:
done ; \
test -z "$$fail"
.PHONY: coverage built-sources clean-built-sources valcheck doxygen manpages
PHONY = coverage built-sources clean-built-sources valcheck doxygen manpages
if ENABLE_COVERAGE
include rules/coverage.am
endif
.PHONY: $(PHONY)
......@@ -42,6 +42,8 @@ doxygen: built-sources
done
${top_srcdir}/libsofia-sip-ua/docs/hide_emails.sh docs/html
PHONY = doxygen
include $(top_srcdir)/rules/recursive.am
.PHONY: built-sources built-sources-am doxygen
.PHONY = $(PHONY)
\ No newline at end of file
......@@ -9,7 +9,7 @@
AUTOMAKE_OPTIONS = foreign
# select whicn optional sofia-sip modules have been enabled
# select which optional sofia-sip modules have been enabled
# in the build
OPT_LIBADD =
OPT_SUBDIRS_STUN =
......@@ -55,6 +55,8 @@ libsofia_sip_ua_la_LIBADD = bnf/libbnf.la \
libsofia_sip_ua_la_LDFLAGS = \
-version-info $(LIBVER_SOFIA_SIP_UA_CUR):$(LIBVER_SOFIA_SIP_UA_REV):$(LIBVER_SOFIA_SIP_UA_AGE)
PHONY = doxygen
include $(top_srcdir)/rules/recursive.am
doxygen: built-sources
......@@ -96,4 +98,8 @@ doxygen: built-sources
done
${srcdir}/docs/hide_emails.sh docs/html
.PHONY: built-sources built-sources-am empty-doxytags doxygen
if HAVE_LCOV
include $(top_srcdir)/rules/covcheck.am
endif
.PHONY: $(PHONY)
......@@ -130,16 +130,57 @@ AC_ARG_ENABLE(coverage,
[ --enable-coverage compile test-coverage [[disabled]]],
, enable_coverage=no)
if test X$enable_coverage != Xno ; then
case "${CC-cc}" in
*gcc*)
AC_SUBST([SOFIA_COVERAGE], ["-fprofile-arcs -ftest-coverage"])
;;
*) AC_MSG_ERROR([--enable-coverage requires gcc])
esac
if test X$enable_coverage = Xno ; then
:
elif test X$GCC != Xyes ; then
AC_MSG_ERROR([--enable-coverage requires gcc])
else
AC_SUBST([SOFIA_COVERAGE], ["-fprofile-arcs -ftest-coverage"])
dnl old_CFLAGS=$CFLAGS
dnl CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
dnl AC_SEARCH_LIBS(_gcov_init, gcov)
dnl CFLAGS=$old_CFLAGS
dnl
dnl libtool 1.5.22 and lower strip -fprofile-arcs from the flags
dnl passed to the linker, which is a bug; -fprofile-arcs implicitly
dnl links in -lgcov, so we do it explicitly here for the same effect
dnl
AC_CHECK_LIB(gcov, __gcov_init)
GCOV=`echo $CC | sed s/gcc/gcov/g`
AC_SUBST(GCOV)
AC_DEFINE([HAVE_COVERAGE], 1,
[Defined when gcov is enabled to force by changing config.h])
dnl Check for lcov utility
AC_CHECK_PROG([LCOV], [lcov], [lcov], [false])
if test X$LCOV != Xfalse ; then
AC_MSG_CHECKING([whether $LCOV accepts --compat-libtool])
if $LCOV --compat-libtool --help > /dev/null 2>&1 ; then
AC_MSG_RESULT(ok)
else
AC_MSG_RESULT(not supported)
AC_MSG_WARN([lcov option --compat-libtool is not supported])
AC_MSG_WARN([Update lcov to version > 1.5])
LCOV=false
fi
fi
AC_CHECK_PROG([GENHTML], [genhtml], [genhtml], [false])
AC_CHECK_PROG([GENPNG], [genpng], [genpng], [false])
if test X$LCOV != Xfalse ; then
AC_MSG_CHECKING([whether $GENPNG has all required modules])
if $GENPNG --help > /dev/null 2>&1 ; then
AC_MSG_RESULT(ok)
else
AC_MSG_RESULT(not supported)
AC_MSG_WARN([GD.pm perl module is not installed])
GENPNG=false
fi
fi
fi
AM_CONDITIONAL([ENABLE_COVERAGE], test X$enable_coverage != Xno)
AM_CONDITIONAL([HAVE_LCOV], test X$LCOV != Xfalse)
AM_CONDITIONAL([HAVE_GENPNG], test X$GENPNG != Xfalse)
AC_SUBST([MOSTLYCLEANFILES], "*.bb *.bbg *.da *.gcov *.gcda *.gcno")
])
......
#
# covcheck.am run tests - show results of lcov as error log
#
#
# Copyright (C) 2007 Nokia Corporation
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
# Licensed under LGPL. See file COPYING.
#
# Run check in current dir and show all uncovered lines as errors
covcheck:
-find . -name *.gcda | xargs rm -rf
$(MAKE) $(AM_MAKEFLAGS) check
${top_srcdir}/scripts/add-coverage --top_builddir=${top_builddir}
${top_srcdir}/scripts/uncovered --top_builddir=${top_builddir}
# Run check in current dir and show all uncovered lines as errors
uncovered:
@${top_srcdir}/scripts/uncovered --top_builddir=${top_builddir}
#
# Generate lcov output
#
#
# Copyright (C) 2007 Nokia Corporation
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
# Licensed under LGPL. See file COPYING.
#
if HAVE_LCOV
LCOV_SUBDIRS=libsofia-sip-ua libsofia-sip-ua-glib
include rules/lcov.am
lcov-upload: lcov
rsync -rvz -e ssh --delete lcov/* sofia-sip.org:/var/www/coverage/lcov/
include rules/covcheck.am
endif
#
# Generate coverage report
#
lcov:
make lcov-report
# rerun checks before lcov
lcov-rerun: clean-lcov
$(MAKE) $(AM_MAKEFLAGS) check
$(MAKE) $(AM_MAKEFLAGS) lcov-report
clean:: clean-lcov
clean-lcov:
-rm -rf lcov
find . -name "*.gcda" | xargs rm -f || true
if HAVE_GENPNG
GENHTML_FRAMES = --frames
else
GENHTML_FIX = true
endif
GENHTML_OPTIONS = --show-details --legend $(GENHTML_FRAMES)
#
# generate report based on current coverage data
#
lcov-report:
@-rm -rf lcov
mkdir lcov
for sub in ${LCOV_SUBDIRS}; do \
${LCOV} --compat-libtool --directory $$sub --capture --output-file lcov/$$sub.info0 && \
{ : remove system includes with with inlined functions ; \
${LCOV} -l lcov/$$sub.info0 | grep -v "`cd ${top_srcdir} && pwd`" ; \
: remove source files in builddir ; \
test ${top_srcdir} = ${top_builddir} || \
${LCOV} -l lcov/$$sub.info0 | grep "`cd ${top_builddir} && pwd`" ; \
: remove test programs ; \
${LCOV} -l lcov/$$sub.info0 | grep "/test\|/torture\|_test[.]c$$" ; } | cut -d: -f1 | \
xargs ${LCOV} -r lcov/$$sub.info0 > lcov/$$sub.info && \
${GENHTML} ${GENHTML_OPTIONS} --title "${PACKAGE_NAME}-${PACKAGE_VERSION}/$$sub" \
--output-directory lcov/$$sub lcov/$$sub.info || \
break; \
done
if HAVE_GENPNG
find lcov -name '*.overview.html' | \
xargs perl -pi.bak -e 's/usemap="[#]overview"/usemap="overview"/;'
find lcov -name '*.bak' | xargs rm -f
endif
PHONY += lcov-report lcov-rerun clean-lcov
......@@ -59,4 +59,7 @@ INTERNAL_INCLUDES = \
-I$(srcdir)/../url -I../url \
-I$(srcdir)/../su -I../su
include $(top_srcdir)/rules/valcheck.am
\ No newline at end of file
include $(top_srcdir)/rules/valcheck.am
if HAVE_LCOV
include $(top_srcdir)/rules/covcheck.am
endif
#! /bin/sh
#
# Add lcov results from last check run to ${top_srcdir}/lcov/module
#
# Copyright (C) 2007 Nokia Corporation
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
# Licensed under LGPL. See file COPYING.
#
usage()
{
test X$1 == X0 || exec >&2
echo usage: add-coverage [--top_builddir=DIR] [--top_srcdir=DIR] [PATH]
exit $1;
}
bdir=`pwd`;
prefix=lcov/
top=.
case $0 in */*) top=${0%/scripts/*} top_srcdir=$top;; esac
while test $# -gt 0;
do
case $1 in
--top_builddir ) test -z "$2" && usage 1; shift; top=$1; shift; ;;
--top_builddir=* ) top=${1#--top_builddir=}; shift ;;
--top_srcdir ) test -z "$2" && usage 1; shift; top=$1; shift; ;;
--top_srcdir=* ) top=${1#--top_srcdir=}; shift ;;
- ) shift; break ;;
-* ) usage 1; ;;
* ) break ;;
esac
done
abs_srcdir=`cd $top_srcdir; pwd`
cd $top
tdir=`pwd`;
if test $tdir != $bdir; then
prefix=lcov${bdir#$tdir}
fi
p=$prefix/$1
mkdir -p lcov
case $p in
lcov/ )
echo libsofia-sip-ua lcov/libsofia-sip-ua.info
echo libsofia-sip-ua-glib lcov/libsofia-sip-ua-glib.info
;;
lcov/?* )
base=${p#lcov/}
echo ${base%/} lcov/${base%%/*}.info
;;
* )
echo $0:$LINENO: internal error >& 2
exit 2
;;
esac | tee /dev/tty |
while read directory outputfile
do
# Remove changed source files
if test -r ${outputfile}0 ; then
find ${abs_srcdir}/${directory} -name '*.[hc]' -newer ${outputfile}0 |
xargs lcov -r ${outputfile}0 > ${outputfile}1 &&
mv ${outputfile}1 ${outputfile}0
fi
lcov --capture --compat-libtool \
--directory ${directory} --output-file ${outputfile}0 &&
{
# remove test programs and system includes with inlined functions
lcov -l ${outputfile}0 | grep -v "`cd ${top_srcdir} && pwd`"
lcov -l ${outputfile}0 | grep "/test\|/torture\|_test[.]c$"
} | cut -d: -f1 |
xargs lcov -r ${outputfile}0 > ${outputfile} &&
genhtml --title "sofia-sip-current/$directory" \
--output-directory lcov/${directory%%/*} ${outputfile}
done
#! /bin/sh
#
# mark uncovered lines as errors
#
#
# Copyright (C) 2007 Nokia Corporation
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
# Licensed under LGPL. See file COPYING.
#
usage()
{
test X$1 == X0 || exec >&2
echo usage: uncovered [--top_builddir=DIR] [PATH...]
exit $1;
}
bdir=`pwd`;
prefix=lcov/
top=.
case $0 in */*) top=${0%/scripts/*};; esac
while test $# -gt 0;
do
case $1 in
--top_builddir ) test -z "$2" && usage 1 ; shift; top=$1; shift; ;;
--top_builddir=* ) top=${1#--top_builddir=}; shift ;;
- ) shift; break ;;
-* ) usage 1; ;;
* ) break;
esac
done
cd $top
tdir=`pwd`;
if test $tdir != $bdir; then
prefix=lcov${bdir#$tdir}
fi
if test $# -gt 0; then
for p in $@
do
if test -d $bdir/$p ; then
find $prefix/$p -name '*.gcov.html'
else
echo $prefix/$p.gcov.html
fi
done
else
find $prefix/ -name '*.gcov.html'
fi |
xargs perl -e '
$base="'${prefix}/'";
while (<>) {
if (m:<pre[^>]*>:) { $pre=1; }
if ($pre && m:</pre[^>]*>:) {
$pre=0;
if ($uncovered) {
print $uncovered;
$uncovered = "";
}
}
if ($pre) {
s/<[^>]+>//g;
s/&lt;/</g; s/&gt;/>/g; s/&quot;/\"/g; s/&amp;/&/g;
if (m/^ *\d+ *[1-9]\d* :/) {
if ($uncovered) {
print $uncovered;
$uncovered = "";
}
}
else {
if ($uncovered) {
if (m/^[^:]+: [{]/) { # Hack: show line number if line starts with {
s/^ +(\d+)[^:]+:/$1:/;
}
else {
s/^ +(\d+)[^:]+:/sprintf("%*s", 1 + length($1), " ")/e;
}
$uncovered .= $f . ":" . $_;
}
elsif (m/^ *\d+ *0 :/) {
for ($f = $ARGV) {
s:^${base}/?::o;
s:[.]gcov[.]html$::;
}
s/^ +(\d+)[^:]+:/$1:/;
$uncovered = $f . ":" . $_;
}
}
}
}
' /dev/null
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment