Hi,
I've attached a new version of this patch that excludes printing of coverage on non-source-tree files.
The printout looks like this:

with gcov:
File `assoc.c' Lines executed:1.66% of 181
File `items.c' Lines executed:2.82% of 248
File `memcached.c' Lines executed:9.40% of 1554
File `slabs.c' Lines executed:14.84% of 128
File `stats.c' Lines executed:2.60% of 77

with tcov:
assoc.c : 1.02 Percent of the file executed
items.c : 2.39 Percent of the file executed
memcached.c : 8.15 Percent of the file executed
slabs.c : 15.65 Percent of the file executed
stats.c : 1.72 Percent of the file executed

-Victor

dormando wrote:
Hey,

Think this could be modified to not spit coverage on files not in the
source tree?

File '/usr/include/gentoo-multilib/amd64/sys/stat.h'
Lines executed:0.00% of 1
/usr/include/gentoo-multilib/amd64/sys/stat.h:creating 'stat.h.gcov'

File '/usr/include/gentoo-multilib/amd64/stdlib.h'
Lines executed:27.27% of 11
/usr/include/gentoo-multilib/amd64/stdlib.h:creating 'stdlib.h.gcov'

File 'slabs.c'
Lines executed:16.39% of 122
slabs.c:creating 'slabs.c.gcov'

File '/usr/include/gentoo-multilib/amd64/stdlib.h'
Lines executed:0.00% of 3
/usr/include/gentoo-multilib/amd64/stdlib.h:creating 'stdlib.h.gcov'

Anyone else have comments?
-Dormando

On Thu, 4 Sep 2008, Victor Kirkebo wrote:

This patch adds test coverage to the 'make test' target.
gcov is used for gcc and tcov is used for Sun studio compiler.

Victor



--
Victor Kirkebo
Database Technology Group
TRO01, x43408/(+47)73842108

diff --git a/Makefile.am b/Makefile.am
index 29085ec..1c86e83 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,6 +7,7 @@ memcached_LDADD = @DTRACE_OBJ@ @DAEMON_OBJ@
 memcached_debug_LDADD = @DTRACE_DEBUG_OBJ@ @DAEMON_OBJ@
 memcached_DEPENDENCIES = @DTRACE_OBJ@ @DAEMON_OBJ@
 memcached_debug_DEPENDENCIES = @DTRACE_DEBUG_OBJ@ @DAEMON_OBJ@
+memcached_debug_CFLAGS = @PROFILER_FLAGS@
 
 memcached_dtrace.h:
 	${DTRACE} -h -s memcached_dtrace.d 
@@ -26,6 +27,26 @@ EXTRA_DIST = doc scripts TODO t memcached.spec daemon.c memcached_dtrace.d
 
 test:	memcached-debug
 	prove $(srcdir)/t
+	@if test `basename $(PROFILER)` = "gcov"; then \
+	  for file in memcached_debug-*.gc??; do \
+	    mv -f $$file `echo $$file | sed 's/memcached_debug-//'`; \
+	  done && \
+	  for file in *.gcda; do \
+	    srcfile=`echo $$file | sed 's/.gcda/.c/'`; \
+	    if test -n "`echo $(memcached_debug_SOURCES) | grep $$srcfile`"; then \
+	      echo `$(PROFILER) $$srcfile` | sed 's/'$$srcfile':.*//'; \
+	    fi \
+	  done \
+	elif test `basename $(PROFILER)` = "tcov"; then \
+	  files=`grep SRCFILE memcached-debug.profile/tcovd | sed 's/SRCFILE://' | sort | uniq` && \
+	  $(PROFILER) -x memcached-debug.profile $$files 2>&1; \
+	  for file in *.tcov; do \
+	    srcfile=`echo $$file | sed 's/.tcov//'`; \
+	    if test -n "`echo $(memcached_debug_SOURCES) | grep $$srcfile`"; then \
+	      echo $$srcfile : `grep 'Percent of the file executed' $$file`; \
+	    fi \
+	  done \
+	else :; fi
 
 dist-hook:
 	rm -rf $(distdir)/doc/.svn/
diff --git a/configure.ac b/configure.ac
index 01c51cf..1a8afe3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,32 @@ AC_SUBST(DTRACE_OBJ)
 AC_SUBST(DTRACE_DEBUG_OBJ)
 AC_SUBST(DTRACEFLAGS)
 
+if test "$GCC" = "yes"
+then
+   AC_PATH_PROG([PROFILER], [gcov], "no", [$PATH])
+   if test "x$PROFILER" != "xno"; then
+      PROFILER_FLAGS="-fprofile-arcs -ftest-coverage"    
+   fi
+else
+   AC_RUN_IFELSE(
+      [AC_LANG_PROGRAM([], [dnl
+#ifdef __SUNPRO_C
+   return 0;
+#else
+   return 1;
+#endif
+      ])
+    ],[
+       AC_PATH_PROG([PROFILER], [tcov], "no", [$PATH])
+       if test "x$PROFILER" != "xno"; then
+          PROFILER_FLAGS=-xprofile=tcov
+       fi
+    ])
+fi
+
+AC_SUBST(PROFILER_FLAGS)
+
+
 AC_ARG_ENABLE(64bit,
   [AS_HELP_STRING([--enable-64bit],[build 64bit verison])])
 if test "x$enable_64bit" == "xyes"

Reply via email to