ci: add coverage job

Uses the new llvm source-base coverage from nightly to generate coverage
reports:
- full html report as artifact
- cobertura report for gitlab MR integration
- output coverage summary for gitlab parsing

Here is the regexp to set in gitlab as "Test coverage parsing":
\s*lines\.*:\s*([\d\.]+%)

Ignore sys crates when calculating coverage are those are fully
generated anyway.

Resources:
- https://github.com/marco-c/rust-code-coverage-sample
- https://github.com/mozilla/grcov/issues/468#issuecomment-691615245
- https://www.greycastle.se/how-to-show-flutter-test-coverage-in-gitlab-ci/
This commit is contained in:
Guillaume Desmottes 2021-01-08 15:36:07 +01:00
parent 4a92966ed5
commit 01e1cfce54
3 changed files with 40 additions and 5 deletions

View file

@ -81,7 +81,7 @@ stages:
- .fdo.container-build@debian - .fdo.container-build@debian
stage: container-base stage: container-base
variables: variables:
FDO_DISTRIBUTION_PACKAGES: "build-essential curl python3-setuptools liborc-0.4-dev libglib2.0-dev libxml2-dev libgtk-3-dev libegl1-mesa libgles2-mesa libgl1-mesa-dri libgl1-mesa-glx libwayland-egl1-mesa xz-utils libssl-dev git wget ca-certificates ninja-build python3-pip flex bison libglib2.0-dev" FDO_DISTRIBUTION_PACKAGES: "build-essential curl python3-setuptools liborc-0.4-dev libglib2.0-dev libxml2-dev libgtk-3-dev libegl1-mesa libgles2-mesa libgl1-mesa-dri libgl1-mesa-glx libwayland-egl1-mesa xz-utils libssl-dev git wget ca-certificates ninja-build python3-pip flex bison libglib2.0-dev lcov"
FDO_DISTRIBUTION_EXEC: 'bash ci/install-gst.sh && pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates' FDO_DISTRIBUTION_EXEC: 'bash ci/install-gst.sh && pip3 install git+http://gitlab.freedesktop.org/freedesktop/ci-templates'
.build-final-image: .build-final-image:
@ -191,9 +191,7 @@ plugins-update-nightly:
variables: variables:
UPDATE_IMG: "nightly" UPDATE_IMG: "nightly"
.cargo test: .cargo_test_var: &cargo_test
stage: "test"
script:
- rustc --version - rustc --version
# First build and test all the crates with their relevant features # First build and test all the crates with their relevant features
# Keep features in sync with below # Keep features in sync with below
@ -229,6 +227,11 @@ plugins-update-nightly:
cargo build --locked --color=always --manifest-path tutorials/Cargo.toml --bins --examples --all-features cargo build --locked --color=always --manifest-path tutorials/Cargo.toml --bins --examples --all-features
fi fi
.cargo test:
stage: "test"
script:
- *cargo_test
test msrv: test msrv:
extends: extends:
- '.cargo test' - '.cargo test'
@ -413,6 +416,31 @@ outdated:
script: script:
- cargo outdated --color=always --root-deps-only --exit-code 1 -v - cargo outdated --color=always --root-deps-only --exit-code 1 -v
coverage:
extends:
- '.cargo test'
- .img-nightly
stage: 'extras'
variables:
ALL_FEATURES: 'yes'
RUSTFLAGS: "-Zinstrument-coverage"
LLVM_PROFILE_FILE: "gstreamer-rs-%p-%m.profraw"
script:
- *cargo_test
# generate html report
- grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing --ignore "*target*" --ignore "*/sys/*" --ignore "examples/*" --ignore "tutorials/*" -o ./coverage/
# generate cobertura report for gitlab integration
- grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "*target*" --ignore "*/sys/*" --ignore "examples/*" --ignore "tutorials/*" -o lcov
- python3 /usr/local/lib/python3.7/dist-packages/lcov_cobertura.py lcov
# output coverage summary for gitlab parsing
- lcov -r lcov "/*" 2&> out
- grep lines out
artifacts:
paths:
- 'coverage'
reports:
cobertura: coverage.xml
pages: pages:
extends: .img-stable extends: .img-stable
stage: 'deploy' stage: 'deploy'

View file

@ -1,4 +1,4 @@
variables: variables:
GST_RS_IMG_TAG: '2020-12-31.0' GST_RS_IMG_TAG: '2021-01-11.0'
GST_RS_STABLE: '1.49.0' GST_RS_STABLE: '1.49.0'
GST_RS_MSRV: '1.48.0' GST_RS_MSRV: '1.48.0'

View file

@ -26,3 +26,10 @@ if [ "$RUST_IMAGE_FULL" = "1" ]; then
cargo install --force cargo-deny cargo install --force cargo-deny
cargo install --force cargo-outdated cargo install --force cargo-outdated
fi fi
# coverage tools
if [ "$RUST_VERSION" = "nightly" ]; then
cargo install grcov
rustup component add llvm-tools-preview
pip3 install lcov_cobertura
fi