[libgee] Setup test code coverage with lcov



commit ea130c0837eefe404b53240f8c2ed642ae98a677
Author: Didier 'Ptitjes <ptitjes free fr>
Date:   Thu Sep 10 16:31:29 2009 +0200

    Setup test code coverage with lcov
    
    Code coverage analysis is enabled with --enable-coverage.

 .gitignore        |    2 ++
 Makefile.am       |   13 +++++++++++++
 configure.ac      |   19 +++++++++++++++++++
 gee/Makefile.am   |    2 ++
 tests/Makefile.am |   27 +++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 5c4ffb5..0c6ccee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,10 +24,12 @@ ylwrap
 compile
 stamp-h1
 *.pc
+lcov.info
 gee/gee-1.0.vapi
 gee/gee-internals-1.0.vapi
 benchmark/benchmarks
 tests/tests
+tests/coverage
 tests/testhashmap
 tests/testhashset
 tests/testtreemap
diff --git a/Makefile.am b/Makefile.am
index 4b3717d..844b0ff 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,6 +20,19 @@ SUBDIRS = \
 	$(BENCHMARK_SUBDIR) \
 	$(NULL)
 
+if ENABLE_COVERAGE
+coverage:
+	$(MAKE) -C tests coverage-reset
+	$(MAKE) -C tests test
+	$(MAKE) -C tests coverage-report
+else
+coverage:
+	@echo "The project has not been configured for coverage, check that you have gcov, lcov."
+	@echo "Of course, do not use --disable-coverage"
+	@exit 1
+endif
+.PHONY: coverage
+
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = gee-1.0.pc
 
diff --git a/configure.ac b/configure.ac
index 95a30e7..965f2b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,25 @@ AS_IF([test "x$enable_doc" != xno],
 	 AS_IF([test "$VALADOC" = :],
 		[AC_MSG_ERROR([valadoc not found])])])
 
+AC_ARG_ENABLE(coverage,
+	AS_HELP_STRING([--enable-coverage],
+	[compile with coverage profiling and debug (gcc only)]),
+	enable_coverage=$enableval,enable_coverage=no)
+AM_CONDITIONAL(ENABLE_COVERAGE, test x$enable_coverage != xno)
+
+AS_IF([test "x$enable_coverage" != xno],
+	[COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
+	 COVERAGE_LIBS="-lgcov"
+	 AC_SUBST(COVERAGE_CFLAGS)
+	 AC_SUBST(COVERAGE_LIBS)
+	 
+	 #FIXME: preserve non -Wall/-g/-O flags from users CFLAGS
+	 CFLAGS="-Wall -g -O0"
+	 AC_PATH_PROG(LCOV, lcov, :)
+	 AC_SUBST(LCOV)
+	 AS_IF([test "$LCOV" = :],
+		[AC_MSG_ERROR([lcov is necessary for testing code coverage (http://ltp.sourceforge.net/coverage/lcov.php)])])])
+
 AC_ARG_ENABLE(benchmark, AS_HELP_STRING([--enable-benchmark], [Enable benchmark]), enable_benchmark=$enableval, enable_benchmark=no)
 AM_CONDITIONAL(ENABLE_BENCHMARK, test x$enable_benchmark = xyes)
 
diff --git a/gee/Makefile.am b/gee/Makefile.am
index 1c323ec..6fa4869 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -4,6 +4,7 @@ NULL =
 
 AM_CPPFLAGS = \
 	$(GLIB_CFLAGS) \
+	$(COVERAGE_CFLAGS) \
 	$(NULL)
 
 BUILT_SOURCES = gee.vala.stamp
@@ -65,6 +66,7 @@ gee-1.0.vapi gee.vala.stamp: $(libgee_la_VALASOURCES)
 
 libgee_la_LIBADD = \
 	$(GLIB_LIBS) \
+	$(COVERAGE_LIBS) \
 	$(NULL)
 
 libgee_la_LDFLAGS = -version-info 1:0:0
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 15f0088..4162ac5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -36,6 +36,33 @@ tests.vala.stamp: $(tests_VALASOURCES)
 tests_LDADD = $(progs_ldadd)
 EXTRA_DIST += $(tests_VALASOURCES)
 
+coverage-reset:
+	lcov --base-directory= top_srcdir@ --directory @top_srcdir@/gee --zerocounters
+
+coverage-report:
+	lcov --directory @top_srcdir@/gee \
+		--capture \
+		--output-file @top_builddir@/lcov.info
+
+	lcov --directory @top_srcdir@/gee \
+		--output-file @top_builddir@/lcov.info \
+		--remove @top_builddir@/lcov.info \
+		/usr/include/\*
+
+	$(mkdir_p) @top_builddir@/tests/coverage
+	git_commit=`GIT_DIR= top_srcdir@/.git git log -1 --pretty=format:%h 2>/dev/null`;\
+	genhtml --title "@PACKAGE_STRING@ $$git_commit" \
+		--output-directory @top_builddir@/tests/coverage @top_builddir@/lcov.info
+	@echo
+	@echo 'lcov report can be found in:'
+	@echo 'file://@abs_top_builddir@/tests/coverage/index.html'
+	@echo
+
+clean-local:
+	-rm -rf coverage
+
+.PHONY: coverage-report
+
 TEST_PROGS += testhashmap
 testhashmap_VALASOURCES = testhashmap.vala
 testhashmap_SOURCES = testhashmap.c



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]