From: Thomas H.P. Andersen Date: Thu, 28 Mar 2013 13:54:06 +0000 (+0100) Subject: Add test coverage and generate report with lcov X-Git-Tag: v206~109 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=6aea6d10f460853111ca8744201ec8dade97de3c 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. ] --- diff --git a/.gitignore b/.gitignore index 5f9ba906a..f4f1e4592 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /busctl /cdrom_id /collect +/coverage/ /gtk-doc.make /hostnamectl /install-tree diff --git a/Makefile.am b/Makefile.am index 2283d0578..9105274c0 100644 --- a/Makefile.am +++ b/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 diff --git a/configure.ac b/configure.ac index 1e196f730..afbe8e904 100644 --- a/configure.ac +++ b/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} diff --git a/src/.gitignore b/src/.gitignore index afabb6a5d..e6ac2d7b8 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -4,3 +4,5 @@ load-fragment-gperf.gperf org.freedesktop.systemd1.policy.in org.freedesktop.systemd1.policy 99-systemd.rules +*.gcno +*.gcda