[master] 69c9e7e7f build: New configure --enable-coverage option

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Aug 25 10:21:05 UTC 2021


commit 69c9e7e7f881885f57aee81ed5bb28aee6cf7617
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Aug 24 15:55:20 2021 +0200

    build: New configure --enable-coverage option
    
    Some of the autoconf logic is originally from Asad. In addition, the
    explicit call to __gcov_flush() is now vendored in vdef.h like other
    toolchain abstractions.

diff --git a/.gitignore b/.gitignore
index 4f6a67eaf..8e7e13ed0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -125,6 +125,10 @@ cscope.*out
 /lib/libvarnishapi/vsl_glob_test
 /lib/libvarnishapi/vxp_test
 
+# GCOV droppings
+*.gcda
+*.gcno
+
 # vtc-bisect.sh default vtc
 /bisect.vtc
 
diff --git a/Makefile.am b/Makefile.am
index 1c3bbfff9..d6fbc0139 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,6 +42,9 @@ install-data-local:
 	$(install_sh) -d -m 0755 $(DESTDIR)$(localstatedir)/varnish
 
 
+distclean-local:
+	find . '(' -name '*.gcda' -o -name '*.gcda' ')' -exec rm '{}' ';'
+
 distcleancheck_listfiles = \
 	find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
 		sh '{}' ';'
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 30235976f..799cf354c 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -65,10 +65,6 @@
  *
  */
 
-#ifdef GCOVING
-    int __gcov_flush(void);
-#endif
-
 static struct vsb pan_vsb_storage, *pan_vsb;
 static pthread_mutex_t panicstr_mtx;
 
@@ -812,9 +808,7 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
 	VSB_cat(pan_vsb, "\n");
 	VSB_putc(pan_vsb, '\0');	/* NUL termination */
 
-#ifdef GCOVING
-	__gcov_flush();
-#endif
+	v_gcov_flush();
 	abort();
 }
 
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index ab889506f..5692335a5 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -63,10 +63,6 @@ static const struct cli_cmd_desc *cmds[] = {
 #include "tbl/cli_cmds.h"
 };
 
-#ifdef GCOVING
-    int __gcov_flush(void);
-#endif
-
 static const int ncmds = sizeof cmds / sizeof cmds[0];
 
 static int		cli_i = -1, cli_o = -1;
@@ -112,9 +108,7 @@ mcf_panic(struct cli *cli, const char * const *av, void *priv)
 	(void)cli;
 	(void)av;
 	(void)priv;
-#ifdef GCOVING
-	__gcov_flush();
-#endif
+	v_gcov_flush();
 	AZ(strcmp("", "You asked for it"));
 	/* NOTREACHED */
 	abort();
diff --git a/configure.ac b/configure.ac
index b2c81109a..2d2e0416a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -769,6 +769,13 @@ case $CFLAGS in
     ;;
 esac
 
+# --enable-coverage
+AC_ARG_ENABLE(coverage,
+	AS_HELP_STRING([--enable-coverage],
+		[enable coverage (implies debugging symbols, default is NO)]),
+	    [],
+	    [enable_coverage=no])
+
 # --enable-debugging-symbols
 AC_ARG_ENABLE(debugging-symbols,
 	AS_HELP_STRING([--enable-debugging-symbols],
@@ -776,6 +783,25 @@ AC_ARG_ENABLE(debugging-symbols,
 	    [],
 	    [enable_debugging_symbols=no])
 
+if test "$enable_coverage" != no; then
+	AC_DEFINE([GCOVING], [1], [Define to 1 if code coverage is enabled.])
+	save_CFLAGS=$CFLAGS
+	CFLAGS=
+	AX_CHECK_COMPILE_FLAG([--coverage],
+		[COV_FLAGS=--coverage],
+		[AX_CHECK_COMPILE_FLAG([-fprofile-arcs -ftest-coverage],
+			[COV_FLAGS="-fprofile-arcs -ftest-coverage"])])
+	AX_CHECK_COMPILE_FLAG([-fprofile-abs-path],
+		[COV_FLAGS="$COV_FLAGS -fprofile-abs-path"])
+	AX_CHECK_COMPILE_FLAG([-fPIC], [COV_FLAGS="$COV_FLAGS -fPIC"])
+	CFLAGS=$COV_FLAGS
+	AC_CHECK_FUNCS([__gcov_flush])
+	AC_CHECK_FUNCS([__gcov_dump])
+	AC_CHECK_FUNCS([__llvm_gcov_flush])
+	CFLAGS="$save_CFLAGS $COV_FLAGS"
+	enable_debugging_symbols=yes
+fi
+
 if test "$enable_debugging_symbols" != no; then
 	if test "x$SUNCC" = "xyes" ; then
 		CFLAGS="${CFLAGS} -O0 -g"
diff --git a/include/vdef.h b/include/vdef.h
index fb6ce4f7a..ae072a2c3 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -112,6 +112,19 @@
 #  define v_dont_optimize
 #endif
 
+#ifdef HAVE___GCOV_FLUSH
+#  define v_gcov_flush() __gcov_flush()
+int __gcov_flush(void);
+#elif defined HAVE___GCOV_DUMP
+#  define v_gcov_flush() __gcov_dump()
+void __gcov_dump(void);
+#elif defined HAVE___LLVM_GCOV_FLUSH
+#  define v_gcov_flush() __llvm_gcov_flush()
+int __llvm_gcov_flush(void);
+#else
+#  define v_gcov_flush() do { } while (0)
+#endif
+
 /*********************************************************************
  * Fundamental numerical limits
   * These limits track RFC8941


More information about the varnish-commit mailing list