gfs2-utils: RHEL7 - gfs2-utils build: Add test coverage option

Andrew Price andyp at fedoraproject.org
Tue Apr 7 21:22:14 UTC 2015


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=e1af32506a4e616d09d075901abe47684b7d9719
Commit:        e1af32506a4e616d09d075901abe47684b7d9719
Parent:        f2d9e5d0830609bc0e89e6c7e6d201d5f2265c71
Author:        Andrew Price <anprice at redhat.com>
AuthorDate:    Wed Sep 17 18:36:36 2014 +0100
Committer:     Andrew Price <anprice at redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100

gfs2-utils build: Add test coverage option

Add an --enable-gcov configure option to simplify building with the
required flags to generate test coverage reports.

Signed-off-by: Andrew Price <anprice at redhat.com>
---
 configure.ac     |   15 ++++++++++++++-
 doc/README.tests |   12 ++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index b93eec9..a978e52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,7 +68,7 @@ test x"$YACC" = x && AC_MSG_ERROR([bison not found])
 # args. Global CFLAGS are ignored during this test.
 cc_supports_flag() {
 	local CFLAGS="$@"
-	AC_MSG_CHECKING([whether $CC supports "$@"])
+	AC_MSG_CHECKING([whether $CC supports $CFLAGS])
 	AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(){return 0;}])],
 			  [RC=0; AC_MSG_RESULT([yes])],
 			  [RC=1; AC_MSG_RESULT([no])])
@@ -89,6 +89,9 @@ check_lib_no_libs() {
 AC_ARG_ENABLE([debug],
 	[  --enable-debug          enable debug build. ],
 	[ default="no" ])
+AC_ARG_ENABLE([gcov],
+	[  --enable-gcov           enable coverage instrumentation.],
+	[ default="no" ])
 
 # We use the Check framework for unit tests
 PKG_CHECK_MODULES([check], [check >= 0.9.8],
@@ -166,6 +169,15 @@ else
 	GDB_FLAGS="-g"
 fi
 
+# gcov works without optimization
+if test "x${enable_gcov}" = xyes; then
+	GCOV_CFLAGS="-fprofile-arcs -ftest-coverage"
+	if ! cc_supports_flag $GCOV_CFLAGS; then
+		AC_MSG_ERROR([your compiler does not support coverage instrumentation])
+	fi
+	OPT_CFLAGS="-O0 $GCOV_CFLAGS"
+fi
+
 # extra warnings
 EXTRA_WARNINGS=""
 
@@ -223,3 +235,4 @@ AC_CONFIG_FILES([Makefile
 AC_OUTPUT
 
 test x"$have_check" = "xyes" || AC_MSG_NOTICE([package 'check' not found; unit tests will not be built])
+test x"${enable_gcov}" = "xyes" && AC_MSG_NOTICE([code coverage enabled; optimization will be disabled])
diff --git a/doc/README.tests b/doc/README.tests
index fa35803..79f51f6 100644
--- a/doc/README.tests
+++ b/doc/README.tests
@@ -40,3 +40,15 @@ Documentation for Autotest, including the AT_* macros used to define tests, can
 be found in the autoconf manual at:
 
     http://www.gnu.org/software/autoconf/manual/index.html
+
+Test coverage instrumentation can be enabled using the --enable-gcov option at
+the configure stage. Once the tools have been built and run with this option
+enabled, coverage data will be written to files in the source directories for
+use by tools such as gcov or lcov. For example, to generate a HTML report of
+testsuite code coverage, using lcov, in a directory named 'coverage':
+
+    ./autogen.sh
+    ./configure --enable-gcov
+    make check
+    lcov --directory . -c -o gfs2-utils.info
+    genhtml -o coverage gfs2-utils.info


More information about the cluster-commits mailing list