From 01e1cfce54610cb7a98a08aed61c0141f30f03ea Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Fri, 8 Jan 2021 15:36:07 +0100 Subject: [PATCH] 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/ --- .gitlab-ci.yml | 36 ++++++++++++++++++++++++++++++++---- ci/images_template.yml | 2 +- ci/install-rust.sh | 7 +++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0123035c0..c787aae2b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: @@ -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 @@ -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' @@ -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' diff --git a/ci/images_template.yml b/ci/images_template.yml index 4f08649d9..5833eca6e 100644 --- a/ci/images_template.yml +++ b/ci/images_template.yml @@ -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' diff --git a/ci/install-rust.sh b/ci/install-rust.sh index 60eb1bc6e..29b1ac370 100755 --- a/ci/install-rust.sh +++ b/ci/install-rust.sh @@ -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