Skip to content

Commit

Permalink
ci: add coverage job
Browse files Browse the repository at this point in the history
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
- mozilla/grcov#468 (comment)
- https://www.greycastle.se/how-to-show-flutter-test-coverage-in-gitlab-ci/
  • Loading branch information
Guillaume Desmottes committed Jan 11, 2021
1 parent 4a92966 commit 01e1cfc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
36 changes: 32 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ stages:
- .fdo.container-build@debian
stage: container-base
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'

.build-final-image:
Expand Down Expand Up @@ -191,9 +191,7 @@ plugins-update-nightly:
variables:
UPDATE_IMG: "nightly"

.cargo test:
stage: "test"
script:
.cargo_test_var: &cargo_test
- rustc --version
# First build and test all the crates with their relevant features
# Keep features in sync with below
Expand Down Expand Up @@ -229,6 +227,11 @@ plugins-update-nightly:
cargo build --locked --color=always --manifest-path tutorials/Cargo.toml --bins --examples --all-features
fi
.cargo test:
stage: "test"
script:
- *cargo_test

test msrv:
extends:
- '.cargo test'
Expand Down Expand Up @@ -413,6 +416,31 @@ outdated:
script:
- 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:
extends: .img-stable
stage: 'deploy'
Expand Down
2 changes: 1 addition & 1 deletion ci/images_template.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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_MSRV: '1.48.0'
7 changes: 7 additions & 0 deletions ci/install-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ if [ "$RUST_IMAGE_FULL" = "1" ]; then
cargo install --force cargo-deny
cargo install --force cargo-outdated
fi

# coverage tools
if [ "$RUST_VERSION" = "nightly" ]; then
cargo install grcov
rustup component add llvm-tools-preview
pip3 install lcov_cobertura
fi

0 comments on commit 01e1cfc

Please sign in to comment.