diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2017-11-24 17:33:40 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2017-11-24 17:33:40 +0100 |
commit | 31b2e4440240333779482038dc031d67631846a6 (patch) | |
tree | 64a1632d1fd9d5a021f51e1aaace692cde5a8044 | |
parent | a138efafda98b29b98e6f205d29ae14c1ac5faa3 (diff) | |
download | embedlog-31b2e4440240333779482038dc031d67631846a6.tar.gz embedlog-31b2e4440240333779482038dc031d67631846a6.tar.bz2 embedlog-31b2e4440240333779482038dc031d67631846a6.zip |
Added source coverage by tests
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | configure.ac | 15 | ||||
-rw-r--r-- | m4/gcov.m4 | 92 | ||||
-rw-r--r-- | tst/Makefile.am | 6 | ||||
-rw-r--r-- | tst/Makefile.am.coverage | 26 |
5 files changed, 141 insertions, 2 deletions
@@ -3,6 +3,10 @@ *.gch config.cache *libembedlog* +*.gcno +*.gcda +tst/coverage.info +tst/coveragereport/ Makefile Makefile.in aclocal.m4 diff --git a/configure.ac b/configure.ac index 1aeaf08..d9c1baa 100644 --- a/configure.ac +++ b/configure.ac @@ -6,10 +6,23 @@ AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_FILES([Makefile src/Makefile include/Makefile tst/Makefile]) AC_CONFIG_SRCDIR([configure.ac]) AC_CONFIG_HEADERS([config.h]) -AC_CHECK_LIB +#AC_CHECK_LIB AC_CHECK_FUNCS(access) + +### +# gcov coverage reporting +# + + +m4_include([m4/gcov.m4]) +AC_TDD_GCOV +AC_SUBST(COVERAGE_CFLAGS) +AC_SUBST(COVERAGE_CXXFLAGS) +AC_SUBST(COVERAGE_LDFLAGS) + + ### # --enable-feature options # diff --git a/m4/gcov.m4 b/m4/gcov.m4 new file mode 100644 index 0000000..3a6bd7e --- /dev/null +++ b/m4/gcov.m4 @@ -0,0 +1,92 @@ +# Copyright 2012 Canonical Ltd. +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 3, as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranties of +# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see <http://www.gnu.org/licenses/>. + +# Checks for existence of coverage tools: +# * gcov +# * lcov +# * genhtml +# * gcovr +# +# Sets ac_cv_check_gcov to yes if tooling is present +# and reports the executables to the variables LCOV, GCOVR and GENHTML. +AC_DEFUN([AC_TDD_GCOV], +[ + AC_ARG_ENABLE(gcov, + AS_HELP_STRING([--enable-gcov], + [enable coverage testing with gcov]), + [use_gcov=yes], [use_gcov=no]) + + AM_CONDITIONAL(HAVE_GCOV, test "x$use_gcov" = "xyes") + + if test "x$use_gcov" = "xyes"; then + # we need gcc: + if test "$GCC" != "yes"; then + AC_MSG_ERROR([GCC is required for --enable-gcov]) + fi + + # Check if ccache is being used + AC_CHECK_PROG(SHTOOL, shtool, shtool) + if test "$SHTOOL"; then + AS_CASE([`$SHTOOL path $CC`], + [*ccache*], [gcc_ccache=yes], + [gcc_ccache=no]) + fi + + if test "$gcc_ccache" = "yes" && (test -z "$CCACHE_DISABLE" || test "$CCACHE_DISABLE" != "1"); then + AC_MSG_ERROR([ccache must be disabled when --enable-gcov option is used. You can disable ccache by setting environment variable CCACHE_DISABLE=1.]) + fi + + lcov_version_list="1.6 1.7 1.8 1.9 1.11" + AC_CHECK_PROG(LCOV, lcov, lcov) + AC_CHECK_PROG(GENHTML, genhtml, genhtml) + + if test "$LCOV"; then + AC_CACHE_CHECK([for lcov version], glib_cv_lcov_version, [ + glib_cv_lcov_version=invalid + lcov_version=`$LCOV -v 2>/dev/null | $SED -e 's/^.* //'` + for lcov_check_version in $lcov_version_list; do + if test "$lcov_version" = "$lcov_check_version"; then + glib_cv_lcov_version="$lcov_check_version (ok)" + fi + done + ]) + else + lcov_msg="To enable code coverage reporting you must have one of the following lcov versions installed: $lcov_version_list" + AC_MSG_ERROR([$lcov_msg]) + fi + + case $glib_cv_lcov_version in + ""|invalid[)] + lcov_msg="You must have one of the following versions of lcov: $lcov_version_list (found: $lcov_version)." + AC_MSG_ERROR([$lcov_msg]) + LCOV="exit 0;" + ;; + esac + + if test -z "$GENHTML"; then + AC_MSG_ERROR([Could not find genhtml from the lcov package]) + fi + + # Remove all optimization flags from CFLAGS + changequote({,}) + CFLAGS=`echo "$CFLAGS" | $SED -e 's/-O[0-9]*//g'` + changequote([,]) + + # Add the special gcc flags + COVERAGE_CFLAGS="--coverage" + COVERAGE_CXXFLAGS="--coverage" + COVERAGE_LDFLAGS="-lgcov" + +fi +]) # AC_TDD_GCOV diff --git a/tst/Makefile.am b/tst/Makefile.am index 0877fb6..dbfdbee 100644 --- a/tst/Makefile.am +++ b/tst/Makefile.am @@ -1,3 +1,5 @@ +include Makefile.am.coverage + check_PROGRAMS = test test_SOURCES = main.c \ el-options.c \ @@ -16,7 +18,9 @@ if ENABLE_OUT_FILE test_SOURCES += ../src/el-file.c endif -test_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -O0 -g3 -ggdb -DNDEBUG +test_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -O0 -g3 -ggdb \ + -DNDEBUG $(COVERAGE_CFLAGS) +test_LDFLAGS = $(COVERAGE_LDFLAGS) test_LDADD = -lrb TESTS = $(check_PROGRAMS) diff --git a/tst/Makefile.am.coverage b/tst/Makefile.am.coverage new file mode 100644 index 0000000..8bb36db --- /dev/null +++ b/tst/Makefile.am.coverage @@ -0,0 +1,26 @@ +# Coverage targets + +if HAVE_GCOV + +.PHONY: clean-gcda +clean-gcda: + @echo Removing old coverage results + -find -name '*.gcda' -print | xargs -r rm + +.PHONY: coverage generate-coverage-html clean-coverage-html +coverage: clean-gcda + -$(MAKE) $(AM_MAKEFLAGS) -k check + $(MAKE) $(AM_MAKEFLAGS) generate-coverage-html + +generate-coverage-html: + @echo Collecting coverage data + $(LCOV) --directory $(top_builddir) --capture --output-file coverage.info --no-checksum --compat-libtool + LANG=C $(GENHTML) --prefix $(top_builddir) --output-directory coveragereport --title "Code Coverage" --legend --show-details coverage.info + +clean-coverage-html: clean-gcda + -$(LCOV) --directory $(top_builddir) -z + -rm -rf coverage.info coveragereport + +clean-local: clean-coverage-html + +endif # HAVE_GCOV |