Browse Source

Add test coverage and generate report with lcov

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. ]
keep-around/ba91431154ad7bac82ddf0a540ec1b40db62d782
Thomas H.P. Andersen 10 years ago
committed by Zbigniew Jędrzejewski-Szmek
parent
commit
6aea6d10f4
  1. 1
      .gitignore
  2. 38
      Makefile.am
  3. 24
      configure.ac
  4. 2
      src/.gitignore

1
.gitignore

@ -7,6 +7,7 @@
/busctl
/cdrom_id
/collect
/coverage/
/gtk-doc.make
/hostnamectl
/install-tree

38
Makefile.am

@ -1389,6 +1389,44 @@ test_sched_prio_LDADD = \
libsystemd-core.la \
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

24
configure.ac

@ -214,6 +214,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]))
@ -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}

2
src/.gitignore

@ -4,3 +4,5 @@ load-fragment-gperf.gperf
org.freedesktop.systemd1.policy.in
org.freedesktop.systemd1.policy
99-systemd.rules
*.gcno
*.gcda

Loading…
Cancel
Save