Replace the coverage script with a Makefile target.

This commit is contained in:
Dag-Erling Smørgrav 2021-10-21 12:38:03 +02:00
parent 29e80880cc
commit eed614622f
4 changed files with 43 additions and 43 deletions

View file

@ -17,3 +17,32 @@ EXTRA_DIST = \
RELNOTES \
autogen.sh \
misc/gendoc.pl
if WITH_CODE_COVERAGE
covdir = @abs_top_builddir@/cov
coverage: coverage-clean all coverage-prepare coverage-run coverage-report
coverage-clean:
-rm -rf "${covdir}"
coverage-prepare:
mkdir "${covdir}"
if CLANG_CODE_COVERAGE
profdata = ${covdir}/@PACKAGE@.profdata
# hardcoding libpam.so here is horrible, need to find a better solution
coverage-run:
LLVM_PROFILE_FILE="${covdir}/@PACKAGE@.%p.raw" \
${MAKE} -C "@abs_top_builddir@" check
coverage-report:
llvm-profdata@clang_ver@ merge \
--sparse "${covdir}/@PACKAGE@".*.raw -o "${profdata}"
llvm-cov@clang_ver@ show \
--format=html --tab-size=8 \
--output-dir="${covdir}" \
--instr-profile="${profdata}" \
--object "@abs_top_builddir@/lib/libpam/.libs/libpam.so"
@echo "coverage report: file://${covdir}/index.html"
endif
else
coverage:
echo "code coverage is not enabled." >&2
false
endif

View file

@ -127,17 +127,23 @@ AC_ARG_ENABLE([werror],
AC_ARG_ENABLE([code-coverage],
AS_HELP_STRING([--enable-code-coverage],
[enable code coverage]))
AM_CONDITIONAL([CODE_COVERAGE], [test x"$enable_code_coverage" = x"yes"])
AS_IF([test x"$enable_code_coverage" = x"yes"], [
AS_IF([test x"$ax_cv_c_compiler_vendor" = x"clang"], [
CFLAGS="${CFLAGS} -fprofile-instr-generate -fcoverage-mapping"
AM_COND_IF([WITH_TEST], [
AS_IF([test x"$ax_cv_c_compiler_vendor" = x"clang"], [
CFLAGS="${CFLAGS} -fprofile-instr-generate -fcoverage-mapping"
clang_code_coverage="yes"
AC_SUBST([clang_ver], [${CC#clang}])
], [
AC_MSG_ERROR([code coverage is only supported with clang])
])
AC_DEFINE([WITH_CODE_COVERAGE], [1], [Define to 1 if code coverage is enabled])
AC_MSG_NOTICE([code coverage enabled])
], [
AC_MSG_ERROR([code coverage is only supported with clang])
AC_MSG_ERROR([code coverage requires unit tests])
])
AC_DEFINE([CODE_COVERAGE], [1], [Define to 1 if code coverage is enabled])
AC_MSG_NOTICE([code coverage enabled])
])
AC_SUBST([enable_code_coverage], [$enable_code_coverage])
AM_CONDITIONAL([WITH_CODE_COVERAGE], [test x"$enable_code_coverage" = x"yes"])
AM_CONDITIONAL([CLANG_CODE_COVERAGE], [test x"$clang_code_coverage" = x"yes"])
AC_CONFIG_FILES([
Makefile
@ -160,6 +166,5 @@ AC_CONFIG_FILES([
modules/pam_unix/Makefile
t/Makefile
])
AC_CONFIG_FILES([misc/coverage.sh],[chmod +x misc/coverage.sh])
AC_CONFIG_FILES([misc/coverity.sh],[chmod +x misc/coverity.sh])
AC_OUTPUT

View file

@ -1 +1 @@
noinst_SCRIPTS = coverage.sh coverity.sh
noinst_SCRIPTS = coverity.sh

View file

@ -1,34 +0,0 @@
#!/bin/sh
usage() {
echo "usage: ${0##*/} [-jN]" >&2
exit 1
}
while getopts "j:" opt ; do
case $opt in
j)
j="-j$OPTARG"
;;
*)
usage
;;
esac
done
if ! [ "@enable_code_coverage@" = "yes" ] ; then
echo "Code coverage disabled." >&2
echo "Re-run ./configure with --enable-code-coverage and try again." >&2
exit 1
fi
srcdir="@abs_top_srcdir@"
profdir="@abs_top_builddir@/cov"
profraw="${profdir}/@PACKAGE@.%p.raw"
profdata="${profdir}/@PACKAGE@.profdata"
export LLVM_PROFILE_FILE="${profraw}"
[ -e "${profdir}" ] && rm -r "${profdir}"
gmake -C "${srcdir}" $j check
llvm-profdata merge -sparse "${profdir}/@PACKAGE@".*.raw -o "${profdata}"
llvm-cov show -instr-profile="${profdata}" -format=html -output-dir="${profdir}" \
--object "@abs_top_builddir@/lib/libpam/.libs/libpam.so"