commit 92822bd53a4969e0e4482206e04aee19be01f227
parent 6e98d6bf135f0fa29534428a296ea52d664ce4b2
Author: Denis Kenzior <denkenz@gmail.com>
Date: Mon, 19 Jun 2023 15:29:28 -0500
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.
Diffstat:
3 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
@@ -749,12 +749,25 @@ if WIRED
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
maintainer-clean-local:
-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
$(AM_V_at)$(MKDIR_P) $(@D)
$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@
diff --git a/acinclude.m4 b/acinclude.m4
@@ -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], [
if (test "${CFLAGS}" = ""); then
CFLAGS="-Wall -fsigned-char -fno-exceptions"
diff --git a/configure.ac b/configure.ac
@@ -25,6 +25,7 @@ AC_PROG_CC_PIE
AC_PROG_CC_ASAN
AC_PROG_CC_LSAN
AC_PROG_CC_UBSAN
+AC_PROG_CC_GCOV
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_PROG_LN_S
@@ -54,6 +55,28 @@ AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug],
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],
[enable position independent executables flag]), [
if (test "${enableval}" = "yes" &&