feat: add code coverage with branch coverage
All checks were successful
CI Code / Check spelling (pull_request) Successful in 19s
CI Code / Check coding style (pull_request) Successful in 39s
CI Code / Code Coverage (pull_request) Successful in 15m36s
CI Code / Linux (arch) (pull_request) Successful in 16m18s
CI Code / Linux (debian) (pull_request) Successful in 16m44s
CI Code / Linux (ubuntu) (pull_request) Successful in 17m42s

- Add --enable-coverage option to configure.ac
- Add coverage/coverage-html targets to Makefile.am
- Add coverage CI job with lcov + Codecov upload
- Include both unit and functional tests in coverage
- Enable branch coverage (step towards MC/DC)
- Add lcov to all Dockerfiles
- Add coverage/ to .gitignore
This commit is contained in:
2026-01-19 16:39:06 +03:00
parent 5a34a4a1d3
commit c1a60dc603
9 changed files with 57 additions and 0 deletions

View File

@@ -98,3 +98,33 @@ jobs:
- name: Check spelling
run: |
codespell
coverage:
runs-on: ubuntu-latest
name: Code Coverage
steps:
- uses: actions/checkout@v4
- name: Build and run coverage
run: |
docker build -f Dockerfile.debian -t profanity-cov .
docker run -v ${{ github.workspace }}/coverage:/coverage profanity-cov bash -c '
./bootstrap.sh
./configure --enable-coverage --enable-otr --enable-pgp --enable-omemo --enable-plugins
make -j$(nproc)
make check || true
make check-functional-parallel || true
lcov --capture --directory . --output-file /coverage/coverage.info \
--rc branch_coverage=1 \
--ignore-errors inconsistent
lcov --remove /coverage/coverage.info \
"/usr/include/*" "*/tests/*" \
--output-file /coverage/coverage.info \
--rc branch_coverage=1 \
--ignore-errors inconsistent,empty,unused
'
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage/coverage.info
fail_ci_if_error: false
verbose: true

1
.gitignore vendored
View File

@@ -107,3 +107,4 @@ breaks
*.tar.*
*.zip
*.log*
coverage/

View File

@@ -17,6 +17,7 @@ RUN pacman -S --needed --noconfirm \
check \
cmake \
cmocka \
lcov \
curl \
debuginfod \
doxygen \

View File

@@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ccache \
gcc \
git \
lcov \
libcmocka-dev \
libcurl3-dev \
libgcrypt-dev \

View File

@@ -14,6 +14,7 @@ RUN dnf install -y \
ccache \
gcc \
git \
lcov \
glib2-devel \
glibc-all-langpacks \
gtk2-devel \

View File

@@ -13,6 +13,7 @@ RUN zypper --non-interactive in --no-recommends \
ccache \
gcc \
git \
lcov \
glib2-devel \
glibc-locale \
gtk2-devel \

View File

@@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
ccache \
gcc \
git \
lcov \
libcmocka-dev \
libcurl3-dev \
libgcrypt-dev \

View File

@@ -386,6 +386,20 @@ check-unit: tests/unittests/unittests
@VALGRIND_CHECK_RULES@
VALGRIND_SUPPRESSIONS_FILES=prof.supp
# Code coverage targets (requires --enable-coverage)
coverage-clean:
find . -name '*.gcda' -delete
find . -name '*.gcno' -delete
rm -rf coverage-html coverage.info
coverage-report: check
lcov --capture --directory . --output-file coverage.info --ignore-errors inconsistent
lcov --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.info --ignore-errors inconsistent
genhtml coverage.info --output-directory coverage-html
@echo "Coverage report generated in coverage-html/index.html"
.PHONY: coverage-clean coverage-report
format: $(all_c_sources)
clang-format -i $(all_c_sources)

View File

@@ -69,6 +69,8 @@ AC_ARG_ENABLE([gdk-pixbuf],
[AS_HELP_STRING([--enable-gdk-pixbuf], [enable GDK Pixbuf support to scale avatars before uploading])])
AC_ARG_ENABLE([omemo-qrcode],
[AS_HELP_STRING([--enable-omemo-qrcode], [enable ability to display omemo qr code])])
AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage], [enable code coverage analysis])])
m4_include([m4/ax_valgrind_check.m4])
AX_VALGRIND_DFLT([drd], [off])
@@ -386,6 +388,11 @@ AC_SUBST([FORKPTY_LIB])
AM_CFLAGS="$AM_CFLAGS -Wall -Wno-deprecated-declarations -std=gnu99 -ggdb3"
AM_LDFLAGS="$AM_LDFLAGS -export-dynamic"
AS_IF([test "x$enable_coverage" = xyes],
[AM_CFLAGS="$AM_CFLAGS --coverage -O0"
AM_LDFLAGS="$AM_LDFLAGS --coverage"
AC_MSG_NOTICE([Code coverage analysis enabled])])
AS_IF([test "x$PACKAGE_STATUS" = xdevelopment],
[AM_CFLAGS="$AM_CFLAGS -Wunused -Werror"])
AS_IF([test "x$PLATFORM" = xosx],