chiark / gitweb /
Add test coverage and generate report with lcov
authorThomas H.P. Andersen <phomes@gmail.com>
Thu, 28 Mar 2013 13:54:06 +0000 (14:54 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 14 Jul 2013 01:56:33 +0000 (21:56 -0400)
Enable coverage with --enable-coverage.
"make coverage" will create the report locally,
"make coverage-sync" will upload the report to
http://www.freedesktop.org/software/systemd/coverage/.

Requires lcov version 1.10 to handle naming in systemd and to
use the --no-external option.

[zj: make the coverage at least generate something with
     separate build dir, simplify rules a bit: all errors
     are mine. ]

.gitignore
Makefile.am
configure.ac
src/.gitignore

index 5f9ba90..f4f1e45 100644 (file)
@@ -7,6 +7,7 @@
 /busctl
 /cdrom_id
 /collect
+/coverage/
 /gtk-doc.make
 /hostnamectl
 /install-tree
index 2283d05..9105274 100644 (file)
@@ -1390,6 +1390,44 @@ test_sched_prio_LDADD = \
        libsystemd-daemon.la
 
 # ------------------------------------------------------------------------------
+## .PHONY so it always rebuilds it
+.PHONY: coverage lcov-run lcov-report
+
+# run lcov from scratch, always
+coverage:
+       $(MAKE) lcov-run
+       $(MAKE) lcov-report
+
+coverage_dir = coverage
+coverage_opts = --base-directory $(srcdir) --directory $(builddir) --rc 'geninfo_adjust_src_path=$(abspath $(srcdir))=>$(abspath $(builddir))'
+
+if ENABLE_COVERAGE
+# reset run coverage tests
+lcov-run:
+       @rm -rf $(coverage_dir)
+       lcov $(coverage_opts) --zerocounters
+       -$(MAKE) check
+
+# generate report based on current coverage data
+lcov-report:
+       $(MKDIR_P) $(coverage_dir)
+       lcov $(coverage_opts) --compat-libtool --capture --no-external \
+               | sed 's|$(abspath $(builddir))|$(abspath $(srcdir))|' > $(coverage_dir)/.lcov.info
+       genhtml -t "systemd test coverage" -o $(coverage_dir) $(coverage_dir)/.lcov.info
+       @echo "Coverage report generated in $(abs_builddir)/$(coverage_dir)/index.html"
+
+# lcov doesn't work properly with vpath builds, make sure that bad
+# output is not uploaded by mistake.
+coverage-sync: coverage
+       test "$(builddir)" = "$(srcdir)"
+       rsync -rlv --delete --omit-dir-times coverage/ $(www_target)/coverage
+
+else
+lcov-run lcov-report:
+       echo "Need to reconfigure with --enable-coverage"
+endif
+
+# ------------------------------------------------------------------------------
 systemd_initctl_SOURCES = \
        src/initctl/initctl.c
 
index 1e196f7..afbe8e9 100644 (file)
@@ -215,6 +215,29 @@ m4_pattern_forbid([^_?PKG_[A-Z_]+$],[*** pkg.m4 missing, please install pkg-conf
 PKG_CHECK_MODULES(DBUS, [dbus-1 >= 1.3.2])
 
 # ------------------------------------------------------------------------------
+have_coverage=no
+AC_ARG_ENABLE(coverage, AS_HELP_STRING([--enable-coverage], [enable test coverage]))
+if test "x$enable_coverage" = "xyes" ; then
+        AC_CHECK_PROG(lcov_found, [lcov], [yes], [no])
+        if test "x$lcov_found" = xno ; then
+                AC_MSG_ERROR([*** lcov support requested but the program was not found])
+        else
+                lcov_version_major="`lcov --version | cut -d ' ' -f 4 | cut -d '.' -f 1`"
+                lcov_version_minor="`lcov --version | cut -d ' ' -f 4 | cut -d '.' -f 2`"
+                if test "$lcov_version_major" -eq 1 -a "$lcov_version_minor" -lt 10; then
+                        AC_MSG_ERROR([*** lcov version is too old. 1.10 required])
+                else
+                        have_coverage=yes
+                        CC_CHECK_FLAGS_APPEND([with_coverage_cflags], [CFLAGS], [\
+                        -fprofile-arcs \
+                        -ftest-coverage])
+                        AC_SUBST([OUR_CFLAGS], "$with_cflags $with_coverage_cflags")
+                fi
+        fi
+fi
+AM_CONDITIONAL(ENABLE_COVERAGE, [test "$have_coverage" = "yes"])
+
+# ------------------------------------------------------------------------------
 have_kmod=no
 AC_ARG_ENABLE(kmod, AS_HELP_STRING([--disable-kmod], [disable loadable modules support]))
 if test "x$enable_kmod" != "xno"; then
@@ -1000,6 +1023,7 @@ AC_MSG_RESULT([
         Python Headers:          ${have_python_devel}
         man pages:               ${have_manpages}
         gtk-doc:                 ${enable_gtk_doc}
+        test coverage:           ${have_coverage}
         Split /usr:              ${enable_split_usr}
         SysV compatibility:      ${SYSTEM_SYSV_COMPAT}
 
index afabb6a..e6ac2d7 100644 (file)
@@ -4,3 +4,5 @@ load-fragment-gperf.gperf
 org.freedesktop.systemd1.policy.in
 org.freedesktop.systemd1.policy
 99-systemd.rules
+*.gcno
+*.gcda