]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
build-sys: integrate coverage report
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 7 Jan 2015 21:17:15 +0000 (19:17 -0200)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 8 Jan 2015 01:02:34 +0000 (23:02 -0200)
Just pass --enable-coverage to configure and then "make coverage" to
have the coverage report at coverage dir.

.gitignore
Makefile.am
configure.ac

index 88c8149798dc4a962b5d3b72be40470112dcb5ba..f60cac629788aae24fc5fed7de305b9ca756aab1 100644 (file)
@@ -1,4 +1,6 @@
 *.o
+*.gcda
+*.gcno
 /*.tar.xz
 /*.md5sum
 .deps/
@@ -14,6 +16,7 @@
 /config.log
 /config.status
 /configure
+/coverage
 /libtool
 /stamp-h1
 /test-suite.log
index 5df38cb4f2fe88df0cb347a4be4fc21e4e091066..bf4f32895db75d1223cbd977cd133bbbe18fa46a 100644 (file)
@@ -326,6 +326,45 @@ distclean-local: $(DISTCLEAN_LOCAL_HOOKS)
 buildtest-TESTS:
        $(MAKE) $(AM_MAKEFLAGS) $(check_LTLIBRARIES) $(check_PROGRAMS)
 
+# ------------------------------------------------------------------------------
+# coverage
+# ------------------------------------------------------------------------------
+
+# .PHONY so it always rebuilds it
+.PHONY: coverage lcov-run lcov-report coverage-sync
+
+# run lcov from scratch, always
+coverage: all
+       $(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) --capture --no-external --ignore-errors graph \
+               | sed 's|$(abspath $(builddir))|$(abspath $(srcdir))|' > $(coverage_dir)/.lcov.info
+       lcov --remove $(coverage_dir)/.lcov.info --output-file $(coverage_dir)/.lcov-clean.info 'test-*'
+       genhtml -t "kmod test coverage" -o $(coverage_dir) $(coverage_dir)/.lcov-clean.info
+       @echo "Coverage report generated in $(abs_builddir)/$(coverage_dir)/index.html"
+
+else
+
+lcov-run lcov-report:
+       echo "Need to reconfigure with --enable-coverage"
+
+endif
+
 # ------------------------------------------------------------------------------
 # custom release helpers
 # ------------------------------------------------------------------------------
index 3be31982bdd00f576b6218b99a995f02f58f3baf..648ff127b43961b067fa6088c42c1c2b7290f0e8 100644 (file)
@@ -151,6 +151,28 @@ AS_IF([test "x$enable_python" = "xyes"], [
 ])
 AM_CONDITIONAL([BUILD_PYTHON], [test "x$enable_python" = "xyes"])
 
+AC_ARG_ENABLE([coverage],
+       AS_HELP_STRING([--enable-coverage], [enable test coverage @<:@default=disabled@:>@]),
+       [], [enable_coverage=no])
+AS_IF([test "x$enable_coverage" = "xyes"], [
+       AC_CHECK_PROG(have_coverage, [lcov], [yes], [no])
+       AS_IF([test "x$have_coverage" = xno],[
+               AC_MSG_ERROR([*** lcov support requested but the program was not found])
+       ], [
+               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`"
+               AS_IF([test "$lcov_version_major" -lt 1 -o "$lcov_version_minor" -lt 10], [
+                       AC_MSG_ERROR([*** lcov version is too old. 1.10 required])
+               ], [
+                       have_coverage=yes
+                        CC_CHECK_FLAGS_APPEND([with_coverage_cflags], [CFLAGS], [\
+                        -fprofile-arcs \
+                        -ftest-coverage])
+               ])
+        ])
+])
+AM_CONDITIONAL([ENABLE_COVERAGE], [test "x$enable_coverage" = "xyes"])
+
 m4_ifdef([GTK_DOC_CHECK], [
 GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat])
 ], [
@@ -204,7 +226,7 @@ CC_CHECK_FLAGS_APPEND(with_cflags, [CFLAGS], [\
                       -fvisibility=hidden \
                       -ffunction-sections \
                       -fdata-sections])
-AC_SUBST([OUR_CFLAGS], $with_cflags)
+AC_SUBST([OUR_CFLAGS], "$with_cflags $with_coverage_cflags")
 
 
 CC_CHECK_FLAGS_APPEND([with_ldflags], [LDFLAGS], [ \
@@ -249,6 +271,7 @@ AC_MSG_RESULT([
        logging:                ${enable_logging}
        compression:            xz=${with_xz}  zlib=${with_zlib}
        debug:                  ${enable_debug}
+       coverage:               ${enable_coverage}
        doc:                    ${enable_gtk_doc}
        man:                    ${enable_manpages}
 ])