diff --git a/.gitignore b/.gitignore index e238846..8628f7d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,9 @@ check_*.trs test-*.log .dirstamp check_jira_plugin -check_packaging \ No newline at end of file +check_packaging + +coverage/ + +*.gcno +*.gcda \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 2e3da29..7d61bd1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,5 @@ +include $(top_srcdir)/common.mk + ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = ${top_srcdir}/README.md \ @@ -14,3 +16,11 @@ SUBDIRS = \ src \ tests \ docs + +if COVERAGE +coverage: + mkdir -p coverage + lcov --compat-libtool --directory . --capture --output-file coverage/report + genhtml -o coverage/ coverage/report +AM_CFLAGS += --coverage +endif diff --git a/configure.ac b/configure.ac index 5105f01..ff8e274 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,25 @@ PKG_CHECK_MODULES([CHECK], [check >= 0.9]) AC_CONFIG_MACRO_DIR([m4]) +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 + AC_DEFINE([COVERAGE], [1], [Coverage enabled]) + fi + fi +fi +AM_CONDITIONAL([COVERAGE], [test "$have_coverage" = "yes"]) + AC_CONFIG_FILES([Makefile data/Makefile @@ -43,6 +62,8 @@ AC_MSG_RESULT([ bindir: ${bindir} datarootdir: ${datarootdir} + coverage: ${have_coverage} + compiler: ${CC} cflags: ${CFLAGS} ldflags: ${LDFLAGS} diff --git a/src/Makefile.am b/src/Makefile.am index e3ac88b..3e56be8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,8 @@ --include $(top_srcdir)/common.mk +include $(top_srcdir)/common.mk + +if COVERAGE +AM_CFLAGS += --coverage +endif bin_PROGRAMS = cve-check-tool diff --git a/tests/Makefile.am b/tests/Makefile.am index e545b55..3b2ad6d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,8 @@ --include $(top_srcdir)/common.mk +include $(top_srcdir)/common.mk +if COVERAGE +AM_CFLAGS += --coverage +endif TESTS = \ check_core \