[gnome-keyring] Implement coverage of tests using gcov and lcov.



commit 5bf7553731217d4134d19feca0ca827b0645b445
Author: Stef Walter <stef memberwebs com>
Date:   Tue Jun 8 17:19:50 2010 +0000

    Implement coverage of tests using gcov and lcov.

 .gitignore           |    3 +++
 Makefile.am          |   11 +++++++++++
 configure.in         |   48 ++++++++++++++++++++++++++++++++++++++++--------
 testing/.gitignore   |    2 ++
 testing/Makefile.am  |    4 ++++
 testing/testing.make |   11 +++++++----
 6 files changed, 67 insertions(+), 12 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index df85403..990c679 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,9 @@ run-tests
 .libs
 .deps
 .anjuta*
+*.gcov
+*.gcno
+*.gcda
 
 /compile
 /ABOUT-NLS
diff --git a/Makefile.am b/Makefile.am
index fb9ec48..4106ac3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,3 +57,14 @@ dist-hook:
 
 install-pam:
 	@echo "WARNING: install-pam is no longer used, use the --with-pam-dir configure option instead"
+
+if WITH_COVERAGE
+check-am:
+	$(LCOV) --directory . --zerocounters
+
+coverage: check
+	mkdir -p testing/coverage
+	$(LCOV) --directory . --capture --output-file testing/coverage.info
+	$(GENHTML) --output-directory testing/coverage testing/coverage.info
+	echo "Coverage info in: testing/coverage/index.html"
+endif
\ No newline at end of file
diff --git a/configure.in b/configure.in
index edf5dae..0940e09 100644
--- a/configure.in
+++ b/configure.in
@@ -444,15 +444,47 @@ fi
 
 AM_CONDITIONAL(WITH_TESTS, test "$enable_tests" = "yes")
 
-AC_ARG_ENABLE(coverage,
-		AC_HELP_STRING([--enable-coverage],
-			[Build coverage testing into gnome-keyring]))
-			
-if test "$enable_coverage" = "yes"; then
-	CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
-	LDFLAGS="$LDFLAGS -fprofile-arcs -ftest-coverage"
+# ----------------------------------------------------------------------
+# Coverage
+
+AC_MSG_CHECKING([whether to build with gcov testing])
+AC_ARG_ENABLE([gcov],
+		AS_HELP_STRING([--enable-gcov],
+			[Whether to enable coverage testing ]),
+		[],
+		[enable_gcov=no])
+
+AC_MSG_RESULT([$enable_gcov])
+
+if test "$enable_gcov" = "yes"; then
+	if test "$GCC" != "yes"; then
+		AC_MSG_ERROR(Coverage testing requires GCC)
+	fi
+
+	AC_PATH_PROG(GCOV, gcov, no)
+	if test "$GCOV" = "no" ; then
+		AC_MSG_ERROR(gcov tool is not available)
+	fi
+
+	AC_PATH_PROG(LCOV, lcov, no)
+	if test "$LCOV" = "no" ; then
+		AC_MSG_ERROR(lcov tool is not installed)
+	fi
+
+	AC_PATH_PROG(GENHTML, genhtml, no)
+	if test "$GENHTML" = "no" ; then
+		AC_MSG_ERROR(lcov's genhtml tool is not installed)
+	fi
+
+	CFLAGS="$CFLAGS -O0 -g -fprofile-arcs -ftest-coverage"
+	LDFLAGS="$LDFLAGS -lgcov"
 fi
 
+AM_CONDITIONAL([WITH_COVERAGE], [test "$enable_gcov" = "yes"])
+AC_SUBST(LCOV)
+AC_SUBST(GCOV)
+AC_SUBST(GENHTML)
+
 # ----------------------------------------------------------------------
 # Valgrind
 
@@ -609,5 +641,5 @@ echo "  Debug Build:          $debug_status"
 echo "  Valgrind:             $valgrind_status"
 echo "  Pkcs#11 Tests         $p11_tests_status"
 echo "  Tests, -Werror:       $tests_status"
+echo "  Test Coverage:        $enable_gcov"
 echo
-
diff --git a/testing/.gitignore b/testing/.gitignore
new file mode 100644
index 0000000..d85786a
--- /dev/null
+++ b/testing/.gitignore
@@ -0,0 +1,2 @@
+/coverage
+/coverage.info
diff --git a/testing/Makefile.am b/testing/Makefile.am
index 82bb215..6304d6f 100644
--- a/testing/Makefile.am
+++ b/testing/Makefile.am
@@ -17,3 +17,7 @@ LIBS = \
 	$(GTHREAD_LIBS)
 
 noinst_PROGRAMS =
+
+CLEANFILES = \
+	coverage \
+	coverage.info
diff --git a/testing/testing.make b/testing/testing.make
index d7575a8..3266e50 100644
--- a/testing/testing.make
+++ b/testing/testing.make
@@ -38,7 +38,11 @@ run_tests_LDADD = \
 	$(DAEMON_LIBS)
 
 run_tests_CFLAGS = \
-	$(TESTING_FLAGS)
+	$(TESTING_FLAGS) \
+	$(GCOV_CFLAGS)
+
+run_tests_LDFLAGS = \
+	$(GCOV_LDFLAGS)
 
 BUILT_SOURCES = \
 	test-framework.c \
@@ -48,7 +52,6 @@ BUILT_SOURCES = \
 # Run the tests
 
 test: $(noinst_PROGRAMS)
-	gtester --verbose -k -m=slow ./run-tests
+	TEST_DATA=$(srcdir)/test-data  gtester --verbose -k -m=slow ./run-tests
 
-check-am: $(noinst_PROGRAMS)
-	TEST_DATA=$(srcdir)/test-data gtester -m=slow --verbose ./run-tests
+check-am: $(noinst_PROGRAMS) test



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