From e28fe69030608e06775ca1711d9e1664b8b36758 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 6 Nov 2020 19:00:49 +0100 Subject: CI: bring back lcov support The newest lcov supports gcc 10 again. Also collect coverage before the tests run as a baseline and add a config file so every lcov call uses the same settings (taken on glib) --- .gitlab-ci/coverage-docker.sh | 9 ++++++--- .gitlab-ci/fixup-lcov-paths.py | 27 +++++++++------------------ .gitlab-ci/lcovrc | 13 +++++++++++++ .gitlab-ci/test-docker.sh | 6 +++++- .gitlab-ci/test-msys2.sh | 23 +++++++++++++---------- 5 files changed, 46 insertions(+), 32 deletions(-) create mode 100644 .gitlab-ci/lcovrc diff --git a/.gitlab-ci/coverage-docker.sh b/.gitlab-ci/coverage-docker.sh index e594f1c0..3072c2fe 100755 --- a/.gitlab-ci/coverage-docker.sh +++ b/.gitlab-ci/coverage-docker.sh @@ -10,13 +10,16 @@ python ./.gitlab-ci/fixup-covpy-paths.py coverage/.coverage* # Remove external headers (except gi tests) for path in coverage/*.lcov; do - lcov --rc lcov_branch_coverage=1 -r "${path}" '/usr/include/*' -o "${path}" - lcov --rc lcov_branch_coverage=1 -r "${path}" '/home/*' -o "${path}" + lcov --config-file .gitlab-ci/lcovrc -r "${path}" '/usr/include/*' -o "${path}" + lcov --config-file .gitlab-ci/lcovrc -r "${path}" '/home/*' -o "${path}" + lcov --config-file .gitlab-ci/lcovrc -r "${path}" '*/msys64/*' -o "${path}" + lcov --config-file .gitlab-ci/lcovrc -r "${path}" '*subprojects/*' -o "${path}" + lcov --config-file .gitlab-ci/lcovrc -r "${path}" '*tmp-introspect*' -o "${path}" done python -m coverage combine coverage python -m coverage html --show-contexts --ignore-errors -d coverage/report-python -genhtml --ignore-errors=source --rc lcov_branch_coverage=1 \ +genhtml --ignore-errors=source --config-file .gitlab-ci/lcovrc \ coverage/*.lcov -o coverage/report-c cd coverage diff --git a/.gitlab-ci/fixup-lcov-paths.py b/.gitlab-ci/fixup-lcov-paths.py index a6f43e44..ecd77425 100644 --- a/.gitlab-ci/fixup-lcov-paths.py +++ b/.gitlab-ci/fixup-lcov-paths.py @@ -1,34 +1,25 @@ -from __future__ import print_function - import sys import os import io +import re def main(argv): - # Fix paths in coverage files to match our current source layout - # so that coverage report generators can find the source. - # Mostly needed for Windows. + # Fix paths in lcov files generated on a Windows host so they match our + # current source layout. paths = argv[1:] for path in paths: print("cov-fixup:", path) text = io.open(path, "r", encoding="utf-8").read() text = text.replace("\\\\", "/") - end = text.index("/gi/") - try: - # coverage.py - start = text[:end].rindex("\"") + 1 - except ValueError: - # lcov - start = text[:end].rindex(":") + 1 - old_root = text[start:end] new_root = os.getcwd() - if old_root != new_root: - print("replacing %r with %r" % (old_root, new_root)) - text = text.replace(old_root, new_root) - with io.open(path, "w", encoding="utf-8") as h: - h.write(text) + for old_root in set(re.findall(":(.*?)/gi/.*?$", text, re.MULTILINE)): + if old_root != new_root: + print("replacing %r with %r" % (old_root, new_root)) + text = text.replace(old_root, new_root) + with io.open(path, "w", encoding="utf-8") as h: + h.write(text) if __name__ == "__main__": diff --git a/.gitlab-ci/lcovrc b/.gitlab-ci/lcovrc new file mode 100644 index 00000000..ac5997b7 --- /dev/null +++ b/.gitlab-ci/lcovrc @@ -0,0 +1,13 @@ +# lcov and genhtml configuration +# See http://ltp.sourceforge.net/coverage/lcov/lcovrc.5.php + +# Always enable branch coverage +lcov_branch_coverage = 1 + +# Exclude precondition assertions, as we can never reasonably get full branch +# coverage of them, as they should never normally fail. +# See https://github.com/linux-test-project/lcov/issues/44 +lcov_excl_br_line = LCOV_EXCL_BR_LINE|g_return_if_fail|g_return_val_if_fail|g_assert|g_assert_ + +# Similarly for unreachable assertions. +lcov_excl_line = LCOV_EXCL_LINE|g_return_if_reached|g_return_val_if_reached|g_assert_not_reached diff --git a/.gitlab-ci/test-docker.sh b/.gitlab-ci/test-docker.sh index dcf4636b..bb865a01 100755 --- a/.gitlab-ci/test-docker.sh +++ b/.gitlab-ci/test-docker.sh @@ -47,8 +47,12 @@ fi; # BUILD & TEST AGAIN USING SETUP.PY python setup.py build_tests + +lcov --config-file .gitlab-ci/lcovrc --directory . --capture --initial --output-file \ + "${COV_DIR}/${CI_JOB_NAME}-baseline.lcov" + xvfb-run -a python -m coverage run --context "${COV_KEY}" tests/runtests.py # COLLECT GCOV COVERAGE -lcov --rc lcov_branch_coverage=1 --directory . --capture --output-file \ +lcov --config-file .gitlab-ci/lcovrc --directory . --capture --output-file \ "${COV_DIR}/${CI_JOB_NAME}.lcov" diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index 133e2e60..e11688bc 100755 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -17,6 +17,7 @@ pacman --noconfirm -Suy pacman --noconfirm -S --needed \ base-devel \ + lcov \ mingw-w64-$MSYS2_ARCH-toolchain \ mingw-w64-$MSYS2_ARCH-ccache \ mingw-w64-$MSYS2_ARCH-$PYTHON-cairo \ @@ -28,8 +29,7 @@ pacman --noconfirm -S --needed \ mingw-w64-$MSYS2_ARCH-libffi \ mingw-w64-$MSYS2_ARCH-glib2 \ mingw-w64-$MSYS2_ARCH-gtk3 \ - git \ - perl + git # ccache setup export PATH="$MSYSTEM/lib/ccache/bin:$PATH" @@ -49,13 +49,16 @@ export COVERAGE_FILE="${COV_DIR}/.coverage.${COV_KEY}" export PYTHONDEVMODE=1 $PYTHON setup.py build_tests -MSYSTEM= $PYTHON -m coverage run --context "${COV_KEY}" tests/runtests.py -# FIXME: lcov doesn't support gcc9 -#~ curl -O -J -L "https://github.com/linux-test-project/lcov/archive/master.tar.gz" -#~ tar -xvzf lcov-master.tar.gz +lcov \ + --config-file .gitlab-ci/lcovrc \ + --directory "$(pwd)" \ + --capture --initial --output-file \ + "${COV_DIR}/${COV_KEY}-baseline.lcov" + +MSYSTEM= $PYTHON -m coverage run --context "${COV_KEY}" tests/runtests.py -#~ ./lcov-master/bin/lcov \ - #~ --rc lcov_branch_coverage=1 --no-external \ - #~ --directory . --capture --output-file \ - #~ "${COV_DIR}/${COV_KEY}.lcov" +lcov \ + --config-file .gitlab-ci/lcovrc \ + --directory "$(pwd)" --capture --output-file \ + "${COV_DIR}/${COV_KEY}.lcov" -- cgit v1.2.1