From: Frantisek Sumsal Date: Tue, 20 Jun 2023 21:01:35 +0000 (+0200) Subject: ci: collect coverage on _exit() as well X-Git-Tag: v2.40-rc1~374^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0d003023cabecd45402a4d8e2529940ec778735;p=thirdparty%2Futil-linux.git ci: collect coverage on _exit() as well _exit() skips the gcov hooks, so we lose all coverage collected up to that point. Let's work around this by intercepting _exit() with our wrapper that calls __gcov_dump() just before _exit(). --- diff --git a/Makefile.am b/Makefile.am index e52a7f592d..0335f58937 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,6 +17,11 @@ AM_CPPFLAGS += \ endif endif +if WITH_COVERAGE +AM_CPPFLAGS += \ + -include $(top_srcdir)/include/coverage.h +endif + AM_CFLAGS = -fsigned-char $(WARN_CFLAGS) AM_CXXFLAGS = $(AM_CFLAGS) AM_LDFLAGS = $(ASAN_LDFLAGS) $(UBSAN_LDFLAGS) $(FUZZING_ENGINE_LDFLAGS) $(COVERAGE_LDFLAGS) diff --git a/include/Makemodule.am b/include/Makemodule.am index 068b0f8e80..52657f7d15 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -13,6 +13,7 @@ dist_noinst_HEADERS += \ include/closestream.h \ include/colors.h \ include/color-names.h \ + include/coverage.h \ include/cpuset.h \ include/crc32.h \ include/crc32c.h \ diff --git a/include/coverage.h b/include/coverage.h new file mode 100644 index 0000000000..f0148e5791 --- /dev/null +++ b/include/coverage.h @@ -0,0 +1,25 @@ +/* + * No copyright is claimed. This code is in the public domain; do with + * it what you wish. + */ +#ifndef UTIL_LINUX_COVERAGE_H +#define UTIL_LINUX_COVERAGE_H + +/* When built with --coverage (gcov) we need to explicitly call __gcov_dump() + * in places where we use _exit(), since _exit() skips at-exit hooks resulting + * in lost coverage. + * + * To make sure we don't miss any _exit() calls, this header file is included + * explicitly on the compiler command line via the -include directive (only + * when built with --coverage/-Db_coverage=true) + */ +void __gcov_dump(void); +void _exit(int); + +__attribute__((noreturn)) static inline void _coverage__exit(int status) { + __gcov_dump(); + _exit(status); +} +#define _exit(x) _coverage__exit(x) + +#endif