aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2013-03-27 11:03:56 +0100
committerTobias Brunner <tobias@strongswan.org>2013-06-11 11:03:11 +0200
commit1f14b4a1f91f0b76369d3283a6771757e6437a23 (patch)
treeddd154edb17a23730f755132f8ee288343c57945
parent952073b8a71f950365eee3a486c3827d1ae42e9e (diff)
downloadstrongswan-1f14b4a1f91f0b76369d3283a6771757e6437a23.tar.bz2
strongswan-1f14b4a1f91f0b76369d3283a6771757e6437a23.tar.xz
Add --enable-coverage configure option
This configure flag enables lcov [1] coverage generation and is intended to be used with unit tests (--enable-unit-tests is implied). A html coverage report can be generated by issuing the following command in the toplevel build directory: make coverage [1] - http://ltp.sourceforge.net/coverage/lcov.php Based on a patch by Adrian-Ken Rueegsegger.
-rw-r--r--.gitignore4
-rw-r--r--HACKING5
-rw-r--r--Makefile.am28
-rw-r--r--configure.in25
4 files changed, 61 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 024d9e452..3deb9fdb5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,7 @@ apidoc/
*.tar.bz2
*.tar.gz
.DS_Store
+coverage/
+*.gcno
+*.gcda
+*.gcov \ No newline at end of file
diff --git a/HACKING b/HACKING
index dbb347e6f..8755fd63f 100644
--- a/HACKING
+++ b/HACKING
@@ -18,8 +18,11 @@ the code, you need the following tools:
- lex/flex
- yacc/bison
- gperf
+
+ Optionally:
- check
- - optionally Doxygen
+ - lcov/genhtml
+ - Doxygen
To check out the master branch, use:
diff --git a/Makefile.am b/Makefile.am
index 1fc1fcdb3..c7ece4a21 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -37,5 +37,33 @@ Doxyfile : Doxyfile.in
apidoc : Doxyfile
doxygen
+if COVERAGE
+cov-reset:
+ @rm -rf $(top_builddir)/coverage
+ @find $(top_builddir) -name "*.gcda" -delete
+ @lcov --zerocounters --directory $(top_builddir)
+
+cov-report:
+ @mkdir $(top_builddir)/coverage
+ lcov -c -o $(top_builddir)/coverage/coverage.info -d $(top_builddir)
+ genhtml --num-spaces 4 --legend \
+ -t "$(PACKAGE_STRING)" \
+ -o $(top_builddir)/coverage/html \
+ -p `readlink -m $(abs_top_srcdir)`/src \
+ $(top_builddir)/coverage/coverage.info
+ @echo "Coverage Report at $(top_builddir)/coverage/html" >&2
+
+coverage:
+ @$(MAKE) cov-reset
+ @$(MAKE) check
+ @$(MAKE) cov-report
+else
+cov-reset:
+
+coverage:
+ @echo "reconfigure with --enable-coverage"
+endif
+
clean-local:
+ @$(MAKE) cov-reset
rm -rf apidoc
diff --git a/configure.in b/configure.in
index b366a6a0d..6a7f9ffb5 100644
--- a/configure.in
+++ b/configure.in
@@ -243,6 +243,7 @@ ARG_ENABL_SET([monolithic], [build monolithic version of libstrongswan that
ARG_ENABL_SET([bfd-backtraces], [use binutils libbfd to resolve backtraces for memory leaks and segfaults.])
ARG_ENABL_SET([unwind-backtraces],[use libunwind to create backtraces for memory leaks and segfaults.])
ARG_ENABL_SET([unit-tests], [enable unit tests using the check test framework.])
+ARG_ENABL_SET([coverage], [enable lcov coverage report generation.])
ARG_ENABL_SET([tkm], [enable Trusted Key Manager support.])
ARG_ENABL_SET([cmd], [enable the command line IKE client charon-cmd.])
@@ -362,6 +363,10 @@ if test x$medcli = xtrue; then
mediation=true
fi
+if test x$coverage = xtrue; then
+ unit_tests=true
+fi
+
# ===========================================
# check required libraries and header files
# ===========================================
@@ -917,6 +922,25 @@ if test x$unit_tests = xtrue; then
AC_SUBST(CHECK_LIBS)
fi
+if test x$coverage = xtrue; then
+ AC_PATH_PROG([LCOV], [lcov], [], [$PATH:/bin:/usr/bin:/usr/local/bin])
+ if test x$LCOV = x; then
+ AC_MSG_ERROR([lcov not found])
+ fi
+ AC_PATH_PROG([GENHTML], [genhtml], [], [$PATH:/bin:/usr/bin:/usr/local/bin])
+ if test x$GENHTML = x; then
+ AC_MSG_ERROR([genhtml not found])
+ fi
+
+ COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
+ COVERAGE_LDFLAGS="-fprofile-arcs"
+ AC_SUBST(COVERAGE_CFLAGS)
+ AC_SUBST(COVERAGE_LDFLAGS)
+
+ AC_MSG_NOTICE([coverage enabled, adding "-g -O0" to CFLAGS])
+ CFLAGS="${CFLAGS} -g -O0"
+fi
+
# ===============================================
# collect plugin list for strongSwan components
# ===============================================
@@ -1241,6 +1265,7 @@ AM_CONDITIONAL(USE_TROUSERS, test x$tss = xtrousers)
AM_CONDITIONAL(MONOLITHIC, test x$monolithic = xtrue)
AM_CONDITIONAL(USE_SILENT_RULES, test x$enable_silent_rules = xyes)
AM_CONDITIONAL(UNITTESTS, test x$unit_tests = xtrue)
+AM_CONDITIONAL(COVERAGE, test x$coverage = xtrue)
AM_CONDITIONAL(USE_TKM, test x$tkm = xtrue)
AM_CONDITIONAL(USE_CMD, test x$cmd = xtrue)