Permalink
Browse files

Add code coverage build option

  • Loading branch information...
1 parent 0ba7c11 commit fd2ce44e395a5f0822d8d58b30b873b5abd1d906 @nickg committed Dec 26, 2012
Showing with 38 additions and 5 deletions.
  1. +4 −1 Makefile.am
  2. +14 −0 configure.ac
  3. +2 −2 src/Makefile.am
  4. +1 −1 src/rt/Makefile.am
  5. +17 −1 test/Makefile.am
View
@@ -7,4 +7,7 @@ ACLOCAL_AMFLAGS = -I m4
bootstrap: all
@cd lib && $(MAKE) $(AM_MAKEFLAGS) clean bootstrap
-.PHONY: bootstrap
+cov-reset cov-report:
+ cd test && $(MAKE) $(AM_MAKEFLAGS) $@
+
+.PHONY: bootstrap cov-reset cov-report
View
@@ -84,6 +84,20 @@ if ! test x$_cv_gnu_make_command = x ; then
fi
AC_SUBST(MAKEFLAGS)
+# Optional code coverage statistics
+AC_ARG_ENABLE([coverage],
+ [AS_HELP_STRING([--enable-coverage],
+ [Enable gcov for code coverage statistics])],
+ [enable_coverage=yes],
+ [])
+if test x$enable_coverage = xyes ; then
+ COV_CFLAGS="--coverage --no-inline"
+ COV_LDFLAGS="--coverage"
+fi
+AC_SUBST(COV_CFLAGS)
+AC_SUBST(COV_LDFLAGS)
+AM_CONDITIONAL([ENABLE_COVERAGE], [test "$enable_coverage" = yes])
+
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT([Makefile src/Makefile src/rt/Makefile test/Makefile \
lib/Makefile lib/std/Makefile lib/ieee/Makefile \
View
@@ -3,9 +3,9 @@ SUBDIRS = rt
bin_PROGRAMS = nvc
noinst_LIBRARIES = libcgen.a libnvc.a
-AM_CFLAGS = -Wall -Werror
+AM_CFLAGS = -Wall -Werror $(COV_CFLAGS)
AM_YFLAGS = -d --locations --report=all
-AM_LDFLAGS = -rdynamic $(LLVM_LDFLAGS)
+AM_LDFLAGS = -rdynamic $(LLVM_LDFLAGS) $(COV_LDFLAGS)
BUILT_SOURCES = parse.h
View
@@ -1,6 +1,6 @@
noinst_LIBRARIES = libnvc-rt.a libjit.a
-AM_CFLAGS = -Wall -Werror -I$(srcdir)/..
+AM_CFLAGS = -Wall -Werror $(COV_CFLAGS) -I$(srcdir)/..
libnvc_rt_a_SOURCES = rtkern.c slave.c shell.c alloc.c vcd.c heap.c \
pprint.c
View
@@ -6,12 +6,13 @@ TESTS = $(check_PROGRAMS) run_regr.rb
src = $(top_srcdir)/src
build = $(top_builddir)/src
shared = $(src)/util.c
+covdir = $(top_builddir)/coverage
AM_CFLAGS = -I $(src) -I $(build) -DTESTDIR=\"$(top_srcdir)/test\" \
$(CHECK_CFLAGS)
LDADD = -lcheck $(build)/rt/libnvc-rt.a $(build)/libnvc.a $(CHECK_LIBS) \
$(CURSES_LIB)
-AM_LDFLAGS = -rdynamic
+AM_LDFLAGS = -rdynamic $(COV_LDFLAGS)
test_lib_SOURCES = test_lib.c
test_ident_SOURCES = test_ident.c
@@ -21,3 +22,18 @@ test_simp_SOURCES = test_simp.c
clean-local:
-test -d logs && $(RM) -r logs
+
+if ENABLE_COVERAGE
+
+cov-reset:
+ rm -rf $(covdir)
+ find $(top_builddir) -name '*.gcda' -exec rm {} \;
+ lcov --directory $(build) --zerocounters
+
+cov-report:
+ mkdir -p $(covdir)
+ lcov --directory $(build) --capture --output-file $(covdir)/nvc.info
+ genhtml -o $(covdir) $(covdir)/nvc.info
+ -x-www-browser $(covdir)/index.html
+
+endif

0 comments on commit fd2ce44

Please sign in to comment.