Skip to content

Commit b0d0030

Browse files
committed
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().
1 parent b4b8f8c commit b0d0030

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Makefile.am

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ AM_CPPFLAGS += \
1717
endif
1818
endif
1919

20+
if WITH_COVERAGE
21+
AM_CPPFLAGS += \
22+
-include $(top_srcdir)/include/coverage.h
23+
endif
24+
2025
AM_CFLAGS = -fsigned-char $(WARN_CFLAGS)
2126
AM_CXXFLAGS = $(AM_CFLAGS)
2227
AM_LDFLAGS = $(ASAN_LDFLAGS) $(UBSAN_LDFLAGS) $(FUZZING_ENGINE_LDFLAGS) $(COVERAGE_LDFLAGS)

include/Makemodule.am

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dist_noinst_HEADERS += \
1313
include/closestream.h \
1414
include/colors.h \
1515
include/color-names.h \
16+
include/coverage.h \
1617
include/cpuset.h \
1718
include/crc32.h \
1819
include/crc32c.h \

include/coverage.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* No copyright is claimed. This code is in the public domain; do with
3+
* it what you wish.
4+
*/
5+
#ifndef UTIL_LINUX_COVERAGE_H
6+
#define UTIL_LINUX_COVERAGE_H
7+
8+
/* When built with --coverage (gcov) we need to explicitly call __gcov_dump()
9+
* in places where we use _exit(), since _exit() skips at-exit hooks resulting
10+
* in lost coverage.
11+
*
12+
* To make sure we don't miss any _exit() calls, this header file is included
13+
* explicitly on the compiler command line via the -include directive (only
14+
* when built with --coverage/-Db_coverage=true)
15+
*/
16+
void __gcov_dump(void);
17+
void _exit(int);
18+
19+
__attribute__((noreturn)) static inline void _coverage__exit(int status) {
20+
__gcov_dump();
21+
_exit(status);
22+
}
23+
#define _exit(x) _coverage__exit(x)
24+
25+
#endif

0 commit comments

Comments
 (0)