Parcourir la source

made a start with automating coverage tests;
configure --with-lcov will try /usr/bin and /usr/local/bin for the lcov and genhtml binaries
(use --with-lcov=PATH to specify a full path to the lcov binary, genhtml is assumed to be in the same one)
this enables a new makefile target; coverage
make coverage removes old coverage results, performs the tests (by depending on make check), and generates a new report in coverage/


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@412 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen il y a 15 ans
Parent
commit
579aae2cc8
2 fichiers modifiés avec 68 ajouts et 6 suppressions
  1. 26 3
      Makefile.am
  2. 42 3
      configure.ac

+ 26 - 3
Makefile.am

@@ -1,5 +1,28 @@
 SUBDIRS = src
+USE_LCOV=@USE_LCOV@
+LCOV=@LCOV@
+GENHTML=@GENHTML@
+
+clean-coverage:
+	@if [ $(USE_LCOV) = yes ] ; then \
+		$(LCOV) --directory . --zerocounters; \
+		rm -rf coverage/; \
+	else \
+		echo "Code coverage not enabled at configuration time"; \
+		exit 1; \
+	fi
+
+perform-coverage: check
+
+report-coverage:
+	$(LCOV) --capture --directory . --output-file all.info
+	$(LCOV) --remove all.info \
+			c++/4.4/\* \
+			boost/\* \
+			gtest/\* \
+			usr/include/\* \
+		--output report.info
+	$(GENHTML) -o coverage report.info 
+
+coverage: clean-coverage perform-coverage report-coverage
 
-# is there a better way to automate this?
-test: all
-	find . -name \*unittests -type f -executable -exec {} \;

+ 42 - 3
configure.ac

@@ -32,12 +32,51 @@ AC_TRY_COMPILE([
         AC_DEFINE(HAVE_SIN_LEN, 1, Define to 1 if sockaddr_in has a sin_len member)],
         AC_MSG_RESULT(no))
 
-#
-# Check availablity of gtest, which will be used for unit tests.
-#
+AC_ARG_WITH(lcov,
+[  --with-lcov         enable gtest and coverage target using the specified lcov], lcov="yes", lcov="no")
+
 AC_ARG_WITH(gtest,
 [  --with-gtest=PATH       specify a path to gtest header files (PATH/include) and library (PATH/lib)],
     gtest_path="$withval", gtest_path="no")
+
+
+USE_LCOV="no"
+if test "$lcov" != "no"; then
+	# force gtest if not set
+	if test "$gtest_path" = "no"; then
+		gtest_path="yes"
+	fi
+	if test "$lcov" != "yes"; then
+		LCOV_PATHS=$lcov
+	else
+		LCOV_PATHS="/usr/bin/lcov /usr/local/bin/lcov"
+	fi
+	for f in $LCOV_PATHS; do
+		if test -x "$f"; then
+			USE_LCOV="yes"
+			LCOV=$f
+		fi
+	done
+	if test $USE_LCOV != "yes"; then
+		AC_MSG_ERROR([Cannot find lcov in: $LCOV_PATHS])
+	fi
+	# is genhtml always in the same directory?
+	GENHTML=`echo "$LCOV" | sed s/lcov$/genhtml/`
+	if test ! -x $GENHTML; then
+		AC_MSG_ERROR([genhtml not found, needed for lcov])
+	fi
+	CPPFLAGS="$(CPPFLAGS) -fprofile-arcs -ftest-coverage"
+	LIBS=" $(LIBS) -lgcov"
+	AC_SUBST(CPPFLAGS)
+	AC_SUBST(LIBS)
+	AC_SUBST(LCOV)
+	AC_SUBST(GENHTML)
+fi
+AC_SUBST(USE_LCOV)
+
+#
+# Check availablity of gtest, which will be used for unit tests.
+#
 if test "$gtest_path" != "no"
 then
 	if test "$gtest_path" != "yes"; then