3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-27 19:59:28 +01:00

build: Enable configuring with gcov

This allows generating code and test coverage reports using lcov &
genhtml.  Useful for understanding how much of the codebase is currently
covered by unit and autotests.
This commit is contained in:
Denis Kenzior 2023-06-19 15:29:28 -05:00
parent 6e98d6bf13
commit 92822bd53a
3 changed files with 58 additions and 1 deletions

View File

@ -749,12 +749,25 @@ if WIRED
endif endif
endif endif
clean-local: gcov-clean:
if GCOV
-$(LCOV) --quiet --directory $(builddir) -z
-rm -rf "$(builddir)/iwd-coverage.info" "$(builddir)/gcov"
-find . -name "*.gcda" -o -name "*.gcov" -o -name "*.gcno" -delete
endif
clean-local: gcov-clean
-rm -f unit/cert-*.pem unit/cert-*.csr unit/cert-*.srl unit/*-settings.8021x -rm -f unit/cert-*.pem unit/cert-*.csr unit/cert-*.srl unit/*-settings.8021x
maintainer-clean-local: maintainer-clean-local:
-rm -rf build-aux ell -rm -rf build-aux ell
gcov-report:
if GCOV
$(LCOV) --quiet --directory $(builddir) --capture --output-file "iwd-coverage.info"
LANG=C $(GENHTML) --quiet --prefix $(builddir) --output-directory "$(builddir)/gcov" --title "iwd Code Coverage" --legend "$(builddir)/iwd-coverage.info"
endif
src/builtin.h: src/genbuiltin config.status src/builtin.h: src/genbuiltin config.status
$(AM_V_at)$(MKDIR_P) $(@D) $(AM_V_at)$(MKDIR_P) $(@D)
$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@ $(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@

View File

@ -46,6 +46,27 @@ AC_DEFUN([AC_PROG_CC_UBSAN], [
]) ])
]) ])
AC_DEFUN([AC_PROG_CC_GCOV], [
AC_CACHE_CHECK([whether ${CC-cc} accepts -fprofile-arcs], ac_cv_prog_cc_profile_arcs, [
echo 'void f(){}' > conftest.c
if test -z "`${CC-cc} -fprofile-arcs -c conftest.c 2>&1`"; then
ac_cv_prog_cc_profile_arcs=yes
else
ac_cv_prog_cc_profile_arcs=no
fi
rm -rf conftest*
])
AC_CACHE_CHECK([whether ${CC-cc} accepts -ftest_coverage], ac_cv_prog_cc_test_coverage, [
echo 'void f(){}' > conftest.c
if test -z "`${CC-cc} -ftest-coverage -c conftest.c 2>&1`"; then
ac_cv_prog_cc_test_coverage=yes
else
ac_cv_prog_cc_test_coverage=no
fi
rm -rf conftest*
])
])
AC_DEFUN([COMPILER_FLAGS], [ AC_DEFUN([COMPILER_FLAGS], [
if (test "${CFLAGS}" = ""); then if (test "${CFLAGS}" = ""); then
CFLAGS="-Wall -fsigned-char -fno-exceptions" CFLAGS="-Wall -fsigned-char -fno-exceptions"

View File

@ -25,6 +25,7 @@ AC_PROG_CC_PIE
AC_PROG_CC_ASAN AC_PROG_CC_ASAN
AC_PROG_CC_LSAN AC_PROG_CC_LSAN
AC_PROG_CC_UBSAN AC_PROG_CC_UBSAN
AC_PROG_CC_GCOV
AC_PROG_INSTALL AC_PROG_INSTALL
AC_PROG_MKDIR_P AC_PROG_MKDIR_P
AC_PROG_LN_S AC_PROG_LN_S
@ -54,6 +55,28 @@ AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],
fi fi
]) ])
AC_ARG_ENABLE(gcov, AS_HELP_STRING([--enable-gcov],
[enable compiling with code coverage information]), [
if (test "${enableval}" = "yes" &&
test "${ac_cv_prog_cc_profile_arcs}" = "yes" &&
test "${ac_cv_prog_cc_test_coverage}" = "yes"); then
CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
fi
])
if (test "${enable_gcov}" = "yes"); then
AC_CHECK_PROGS(LCOV, [lcov], "no")
AC_CHECK_PROGS(GENHTML, [genhtml], "no")
if (test "${LCOV}" == "no"); then
AC_MSG_ERROR([lcov is required])
fi
if (test "${GENHTML}" == "no"); then
AC_MSG_ERROR([genhtml is required])
fi
fi
AM_CONDITIONAL(GCOV, test "${enable_gcov}" != "no")
AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie], AC_ARG_ENABLE(pie, AS_HELP_STRING([--enable-pie],
[enable position independent executables flag]), [ [enable position independent executables flag]), [
if (test "${enableval}" = "yes" && if (test "${enableval}" = "yes" &&