* 'coverage-tweaks' of https://github.com/mrc0mmand/util-linux:
  ci: collect coverage on _exit() as well
  ci: hide coverage-related stuff begind --enable-coverage
  ci: tweak build dir's ACL when collecting coverage
  ci: fix indentation
This commit is contained in:
Karel Zak 2023-06-22 14:19:07 +02:00
commit 6a28c2f90a
5 changed files with 67 additions and 12 deletions

View file

@ -1,5 +1,5 @@
#!/bin/bash
set -ex
PHASES=(${@:-CONFIGURE MAKE INSTALL CHECK DISTCHECK})
@ -87,9 +87,7 @@ for phase in "${PHASES[@]}"; do
)
if [[ "$COVERAGE" == "yes" ]]; then
CFLAGS+=(--coverage)
CXXFLAGS+=(--coverage)
LDFLAGS+=(--coverage)
opts+=(--enable-coverage)
fi
if [[ "$SANITIZE" == "yes" ]]; then
@ -104,9 +102,9 @@ for phase in "${PHASES[@]}"; do
CXXFLAGS+=(-shared-libasan)
fi
if [[ "$HOST_TRIPLET" != "" ]]; then
opts+=(--host "$HOST_TRIPLET")
fi
if [[ "$HOST_TRIPLET" != "" ]]; then
opts+=(--host "$HOST_TRIPLET")
fi
git config --global --add safe.directory "$PWD"
git clean -xdf
@ -128,9 +126,9 @@ for phase in "${PHASES[@]}"; do
ninja -C build
;;
CODECHECK)
make checklibdoc
make checkxalloc
;;
make checklibdoc
make checkxalloc
;;
CHECK)
if [[ "$SANITIZE" == "yes" ]]; then
# All the following black magic is to make test/eject/umount work, since
@ -162,6 +160,20 @@ for phase in "${PHASES[@]}"; do
fi
fi
if [[ "$COVERAGE" == "yes" ]]; then
# Make (almost) everything under current directory readable/writable
# for everyone to allow gcov to write the .gcda files even with
# dropped privileges
find . tests/helpers/ -maxdepth 1 -type d ! -name . ! -name tests \
-exec setfacl -R -m 'd:g::rwX,d:o::rwX' -m 'g::rwX,o::rwX' '{}' \;
# Make sure we can access $PWD as an unpriv user
path="$PWD"
while [[ "$path" != / ]]; do
chmod o+rx "$path"
path="$(dirname "$path")"
done
fi
./tests/run.sh --show-diff
if [[ "$COVERAGE" == "yes" ]]; then

View file

@ -17,9 +17,14 @@ 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)
AM_LDFLAGS = $(ASAN_LDFLAGS) $(UBSAN_LDFLAGS) $(FUZZING_ENGINE_LDFLAGS) $(COVERAGE_LDFLAGS)
# Add gettext stuff to the global LDADD for systems with separate libintl
# library. The LTLIBINTL is generated by AM_GNU_GETTEXT macro.

View file

@ -215,6 +215,17 @@ AC_PROG_CXX
AM_CONDITIONAL([FUZZING_ENGINE], [test "x$enable_fuzzing_engine" = xyes])
AM_CONDITIONAL([OSS_FUZZ], [test "x$LIB_FUZZING_ENGINE" != x])
AC_ARG_ENABLE([coverage],
AS_HELP_STRING([--enable-coverage], [compile with gcov]),
[], [enable_coverage=no]
)
AS_IF([test "x$enable_coverage" = xyes], [
UL_WARN_ADD([--coverage])
COVERAGE_LDFLAGS="--coverage"
])
AC_SUBST([COVERAGE_LDFLAGS])
AM_CONDITIONAL([WITH_COVERAGE], [test "x$enable_coverage" = xyes])
dnl libtool-2
LT_INIT
@ -2891,7 +2902,8 @@ AC_MSG_RESULT([
ldflags: ${LDFLAGS}
suid ldflags: ${SUID_LDFLAGS}
ASAN enabled: ${enable_asan}
Fuzzing enabled: ${enable_fuzzing_engine}
Fuzzing enabled: ${enable_fuzzing_engine}
Coverage enabled ${enable_coverage}
cflags: ${CFLAGS}

View file

@ -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 \

25
include/coverage.h Normal file
View file

@ -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