Code Coverage Analysis (GCOV/LCOV)

Aaron Arvey aarvey at cs.hmc.edu
Sun Oct 10 18:38:59 CDT 2004


Hello,

I've added in easy to configure code coverage analysis.  For more
information on code coverage please read the comments at the top of
the patch and visit http://ltp.sourceforge.net/coverage/lcov.php.

Aaron Arvey
-------------- next part --------------
We're using gcov and lcov to measure how well the Wine test suite
covers the wine source tree.  Here's our first cut at making it easy
to run wine compiled for coverage testing, and view the results
using the LTP's nifty lcov front end.
 
In order to apply and use this patch, you'll need to do something like:
      $> apt-get install lcov (or download from http://ltp.sourceforge.net/coverage/lcov.php)
      $> patch -p1 < enablegcov.patch
      $> autoconf
      $> ./configure --enable-gcov
      $> make depend && make
      $> make -k test  (or ./programs/winetest/winetest for gui)
      $> make lcov
      $> mozilla lcov.out/index.html

Changelog:
  * configure.ac
    new option "--enable-gcov"
  * Make.rules.in
    new variables LCOV_*, LOADERCFLAGS
  * Makefile.in
    new targets lcov, lcov-clean
  * loader/Makefile.in
    used LOADERFLAGS in place of EXTRAFLAGS
    (low level compilation issues when profiling code)


--- winev/configure.ac	2004-10-08 19:26:29.000000000 -0700
+++ winev.patched/configure.ac	2004-10-10 14:57:52.000000000 -0700
@@ -16,6 +16,7 @@
 AC_ARG_ENABLE(debug, AC_HELP_STRING([--disable-debug],[compile out all debugging messages]))
 AC_ARG_ENABLE(trace, AC_HELP_STRING([--disable-trace],[compile out TRACE messages]))
 AC_ARG_ENABLE(win64, AC_HELP_STRING([--enable-win64], [build a Win64 emulator on AMD64 (won't run Win32 binaries)]))
+AC_ARG_ENABLE(gcov, AC_HELP_STRING([--enable-gcov],[turn on code coverage analysis tools]))
 
 AC_ARG_WITH(opengl,    AC_HELP_STRING([--without-opengl],[do not use OpenGL]))
 AC_ARG_WITH(curses,    AC_HELP_STRING([--without-curses],[do not use curses]))
@@ -125,6 +126,8 @@
 AC_CHECK_PROGS(DB2PS, docbook2ps db2ps, false)
 AC_CHECK_PROGS(DB2TXT, docbook2txt db2txt, false)
 AC_CHECK_PROGS(FONTFORGE, fontforge, false)
+AC_CHECK_PROGS(LCOV, lcov, false)
+AC_CHECK_PROGS(GENHTML, genhtml, false)
 
 dnl **** Check for some libraries ****
 
@@ -696,6 +699,7 @@
 dnl **** Check for gcc specific options ****
 
 AC_SUBST(EXTRACFLAGS,"")
+AC_SUBST(LOADERCFLAGS,"")
 if test "x${GCC}" = "xyes"
 then
   EXTRACFLAGS="-Wall -pipe"
@@ -757,6 +761,31 @@
     EXTRACFLAGS="$EXTRACFLAGS -gstabs+"
   fi
 
+  dnl Check for --enable-gcov and add appropriate flags for gcc
+  dnl Note that these extra switches are NOT applied to the loader
+  if test "x$enable_gcov" = "xyes"; 
+  then
+    dnl Check for -fprofile-arcs and -ftest-coverage option
+    AC_CACHE_CHECK([for gcc -fprofile-arcs support],
+		    ac_cv_c_gcc_fprofile_arcs,
+                    [WINE_TRY_CFLAGS([-fprofile-arcs],
+		                     ac_cv_c_gcc_fprofile_arcs="yes",
+				     ac_cv_c_gcc_fprofile_arcs="no")])
+    AC_CACHE_CHECK([for gcc -ftest-coverage support],
+		    ac_cv_c_gcc_ftest_coverage,
+                    [WINE_TRY_CFLAGS([-ftest-coverage],
+		                     ac_cv_c_gcc_ftest_coverage="yes",
+				     ac_cv_c_gcc_ftest_coverage="no")])
+    if test "$ac_cv_c_gcc_fprofile_arcs" = "yes" && \
+       test "$ac_cv_c_gcc_ftest_coverage" = "yes"
+    then
+      EXTRACFLAGS="$EXTRACFLAGS -fprofile-arcs -ftest-coverage"
+      dnl Turn off optimization so code coverage tool
+      dnl can get accurate line numbers
+      EXTRACFLAGS=`echo "$EXTRACFLAGS" | sed -e 's/-O[0-9]*//g'`
+    fi
+  fi
+  
   dnl Check for noisy string.h
   saved_CFLAGS="$CFLAGS"
   CFLAGS="$CFLAGS -Wpointer-arith -Werror"
@@ -770,6 +799,11 @@
   fi
 fi
 
+dnl When adding in more 'EXTRAFLAGS' you must put them above this!
+dnl Strips out the code profiling abilities because the preloader
+dnl relies on low level assumptions which added code messes up.
+LOADERCFLAGS=`echo "$EXTRACFLAGS" | sed -e 's/-fprofile-arcs -ftest-coverage//g'`
+	
 dnl **** Check how to define a function in assembly code ****
 
 AC_CACHE_CHECK([how to define a function in assembly code], ac_cv_asm_func_def,
--- winev/Make.rules.in	2004-10-06 20:12:44.000000000 -0700
+++ winev.patched/Make.rules.in	2004-10-08 17:39:54.000000000 -0700
@@ -81,6 +81,9 @@
 LIBPORT      = -L$(TOPOBJDIR)/libs/port -lwine_port
 LIBUNICODE   = -L$(TOPOBJDIR)/libs/unicode -lwine_unicode
 LIBWINE      = -L$(TOPOBJDIR)/libs/wine -lwine
+LCOV_OUTPUT  = $(TOPSRCDIR)/lcov.out
+LCOV_LCOV    = @LCOV@
+LCOV_GENHTML = @GENHTML@
 
 @SET_MAKE@
 
@@ -104,7 +107,8 @@
 api_manext      = 3w
 conf_manext     = 5
 CLEAN_FILES     = *.o *.a *.so *.ln *.$(LIBEXT) \\\#*\\\# *~ *% .\\\#* *.bak *.orig *.rej \
-                  *.flc *.spec.c *.spec.def *.dbg.c *.tab.c *.tab.h @LEX_OUTPUT_ROOT at .c core
+                  *.flc *.spec.c *.spec.def *.dbg.c *.tab.c *.tab.h @LEX_OUTPUT_ROOT at .c core \
+		  *.bb *.bbg *.da
 
 OBJS = $(C_SRCS:.c=.o) $(EXTRA_OBJS)
 
--- winev/Makefile.in	2004-10-06 20:12:44.000000000 -0700
+++ winev.patched/Makefile.in	2004-10-10 14:38:42.000000000 -0700
@@ -14,6 +14,8 @@
 # manpages:        compile manpages for Wine API
 # htmlpages:       compile html pages for Wine API
 # sgmlpages:       compile sgml source for the Wine API Guide
+# lcov:            run lcov to gain code coverage abilities
+# lcov-clean:       remove directory with lcov data
 
 # Directories
 
@@ -153,6 +155,14 @@
 	$(MKINSTALLDIRS) $(TOPOBJDIR)/documentation/api-guide
 	cd dlls && $(MAKE) doc-sgml
 
+lcov:
+	$(LCOV_LCOV) --directory $(TOPOBJDIR) --capture --output-file wine.info --test-name WINE_LCOV 
+	LANG=C $(LCOV_GENHTML) --prefix . --output-directory $(LCOV_OUTPUT) --title "WINE Code Coverage" --show-details wine.info
+	@echo "Point a web browser at $(LCOV_OUTPUT)/index.html to see results."
+
+lcov-clean:
+	$(RM) -r $(LCOV_OUTPUT)
+
 clean::
 	$(RM) wine
 
--- winev/loader/Makefile.in	2004-08-11 13:59:09.000000000 -0700
+++ winev.patched/loader/Makefile.in	2004-10-08 17:39:54.000000000 -0700
@@ -23,6 +23,10 @@
 
 LIBPTHREAD  = @LIBPTHREAD@
 LDEXECFLAGS = @LDEXECFLAGS@
+LOADERCFLAGS = @LOADERCFLAGS@
+
+.c.o:
+	$(CC) -c $(INCLUDES) $(DEFS) $(DLLFLAGS) $(LOADERCFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $<
 
 wine-glibc: glibc.o Makefile.in
 	$(CC) -o $@ glibc.o $(LIBWINE) $(LIBPORT) $(LIBPTHREAD) $(EXTRALIBS) $(LDFLAGS)


More information about the wine-patches mailing list