ci: collect test coverage and deploy a html report through gitlab pages

Use lcov for both Fedora and MSYS2 to create coverage reports and add a second
ci stage which merges the coverage and creates a html report using genhtml.

In the final stage, which is only run on master, the result is published on
gitlab pages.

https://bugzilla.gnome.org/show_bug.cgi?id=795636
This commit is contained in:
Christoph Reiter 2018-04-27 17:04:52 +02:00 committed by Philip Withnall
parent e8798a4c22
commit 961be2b0bf
5 changed files with 104 additions and 1 deletions

View File

@ -2,6 +2,8 @@ image: registry.gitlab.gnome.org/gnome/glib/master:v1
stages:
- build
- coverage
- deploy
cache:
paths:
@ -9,18 +11,23 @@ cache:
fedora-meson-x86_64:
stage: build
variables:
CFLAGS: "-coverage -ftest-coverage -fprofile-arcs"
script:
- meson --prefix /usr --libdir /usr/lib64 --buildtype debug --werror -Dsystemtap=true -Ddtrace=true _build .
- cd _build
- ninja
- meson test
- cd ..
- mkdir -p _coverage
- lcov --rc lcov_branch_coverage=1 --directory . --capture --no-external --output-file "_coverage/${CI_JOB_NAME}.lcov"
except:
- tags
artifacts:
when: on_failure
name: "glib-_${CI_COMMIT_REF_NAME}"
paths:
- "${CI_PROJECT_DIR}/_build/meson-logs"
- "${CI_PROJECT_DIR}/_coverage"
msys2-mingw32:
stage: build
@ -32,6 +39,27 @@ msys2-mingw32:
script:
- C:\msys64\usr\bin\pacman --noconfirm -Syyuu --ask 20
- C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh"
artifacts:
paths:
- _coverage/
coverage:
stage: coverage
artifacts:
paths:
- _coverage/
script:
- bash -x ./.gitlab-ci/coverage-docker.sh
pages:
stage: deploy
script:
- mv _coverage/ public/
artifacts:
paths:
- public
only:
- master
dist-job:
stage: build

View File

@ -3,6 +3,7 @@ FROM fedora:27
RUN dnf -y install \
desktop-file-utils \
elfutils-libelf-devel \
findutils \
gcc \
gcc-c++ \
gettext \
@ -11,6 +12,7 @@ RUN dnf -y install \
glibc-headers \
gtk-doc \
itstool \
lcov \
libattr-devel \
libffi-devel \
libmount-devel \

30
.gitlab-ci/coverage-docker.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
set -e
# Fixup Windows paths
python3 ./.gitlab-ci/fixup-cov-paths.py _coverage/*.lcov
# Remove coverage from generated code in the build directory
for path in _coverage/*.lcov; do
lcov --rc lcov_branch_coverage=1 -r "${path}" '*/_build/*' -o "$(pwd)/${path}"
done
genhtml \
--ignore-errors=source \
--rc lcov_branch_coverage=1 \
_coverage/*.lcov \
-o _coverage/coverage
cd _coverage
rm -f *.lcov
cat >index.html <<EOL
<html>
<body>
<ul>
<li><a href="coverage/index.html">Coverage</a></li>
</ul>
</body>
</html>
EOL

View File

@ -0,0 +1,29 @@
import sys
import os
import io
def main(argv):
# 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("\\\\", "/")
glib_dir = "/glib/"
end = text.index(glib_dir)
start = text[:end].rindex(":") + 1
old_root = text[start:end]
assert os.path.basename(os.getcwd()) == "glib"
new_root = os.path.dirname(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)
if __name__ == "__main__":
sys.exit(main(sys.argv))

View File

@ -28,6 +28,7 @@ export CCACHE_BASEDIR="$(pwd)"
export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
pip3 install --upgrade --user meson
export PATH="$HOME/.local/bin:$PATH"
export CFLAGS="-coverage -ftest-coverage -fprofile-arcs"
meson --werror --buildtype debug _build
cd _build
@ -35,3 +36,16 @@ ninja
# FIXME: fix the test suite
meson test || true
cd ..
curl -O -J -L "https://github.com/linux-test-project/lcov/releases/download/v1.13/lcov-1.13.tar.gz"
echo "44972c878482cc06a05fe78eaa3645cbfcbad6634615c3309858b207965d8a23 lcov-1.13.tar.gz" | sha256sum -c
tar -xvzf lcov-1.13.tar.gz
mkdir -p _coverage
./lcov-1.13/bin/lcov \
--rc lcov_branch_coverage=1 \
--directory . \
--capture \
--no-external \
--output-file "_coverage/${CI_JOB_NAME}.lcov"