From e18ccc347966a264f8bdda796179629841420785 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 20:56:26 -0700 Subject: [PATCH 1/8] Add code coverage support Code coverage is generated by using the `profile` compiler option, along with some other options. The data is consolidated by [`grcov`] and shipped off to Codecov. This follows the same code coverage workflow as the IntelliJ Rust plugin uses, introduced in the most recent release: https://intellij-rust.github.io/2019/07/22/changelog-102.html [`grcov`]: https://github.com/mozilla/grcov Signed-off-by: Mcat12 --- .circleci/config.yml | 17 +++++++++++++++-- docker/x86_64-musl/Dockerfile | 3 ++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c1fea0f4..9160221c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,7 +52,20 @@ version: 2 - run: name: "Test" command: | - [[ "$CIRCLE_JOB" != "x86_64-musl" ]] || time cargo test --release --target $TARGET + if [[ "$CIRCLE_JOB" != "x86_64-musl" ]]; then + exit 0 + fi + + # These flags are used so the test results can be used for code coverage + export CARGO_INCREMENTAL=0 + export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Zno-landing-pads" + + time cargo test --target $TARGET + - run: + name: "Upload Code Coverage" + command: | + grcov target -t lcov --branch --ignore-not-existing --ignore-dir "/*" -o lcov.info + bash <(curl -s https://codecov.io/bash) -f lcov.info - run: name: "Build DEB" command: | @@ -61,7 +74,7 @@ version: 2 mv ../pihole-api*.deb . [[ "$CIRCLE_JOB" != "arm" ]] || for file in pihole-api*.deb; do mv $file ${file//armhf/arm}; done - run: - name: "Upload" + name: "Upload Artifacts" command: | [[ -z "$FTL_SECRET" || "$CIRCLE_PR_NUMBER" != "" ]] && exit 0 DIR="${CIRCLE_TAG:-${CIRCLE_BRANCH}}" diff --git a/docker/x86_64-musl/Dockerfile b/docker/x86_64-musl/Dockerfile index b7bdf6b9..73327523 100644 --- a/docker/x86_64-musl/Dockerfile +++ b/docker/x86_64-musl/Dockerfile @@ -11,7 +11,8 @@ RUN apt-get update && \ ENV PATH="/root/.cargo/bin:$PATH" -RUN rustup component add rustfmt clippy +RUN rustup component add rustfmt clippy && \ + cargo install grcov # Install ghr for GitHub Releases: https://github.com/tcnksm/ghr RUN curl -L -o ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.12.0/ghr_v0.12.0_linux_amd64.tar.gz && \ From d01260bc99bcb77ca4d194ddc487f4db085a6eaf Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 21:08:31 -0700 Subject: [PATCH 2/8] Use the native x86_64-gnu target when compiling the tests The profiler is not included in the x86_64-musl target. Signed-off-by: Mcat12 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9160221c..a29af915 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -60,7 +60,7 @@ version: 2 export CARGO_INCREMENTAL=0 export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Zno-landing-pads" - time cargo test --target $TARGET + time cargo test - run: name: "Upload Code Coverage" command: | From 73c555b2299920c430108efc0b9273080349d526 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 21:09:54 -0700 Subject: [PATCH 3/8] Don't upload code coverage on jobs without coverage info Signed-off-by: Mcat12 --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a29af915..330904cd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,6 +64,10 @@ version: 2 - run: name: "Upload Code Coverage" command: | + if [[ "$CIRCLE_JOB" != "x86_64-musl" ]]; then + exit 0 + fi + grcov target -t lcov --branch --ignore-not-existing --ignore-dir "/*" -o lcov.info bash <(curl -s https://codecov.io/bash) -f lcov.info - run: From b1315df65eb756a55356449744eafc4fef877908 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 21:14:08 -0700 Subject: [PATCH 4/8] Bump the CircleCI cache version The tests now compile using a different target, so the new build files were not getting cached. Signed-off-by: Mcat12 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 330904cd..19f09ef9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,7 @@ version: 2 keys: # Find a cache corresponding to this specific target and Cargo.lock checksum. # There are two dashes used between job and checksum to avoid x86_64 using the x86_64-musl cache - - v3-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }} + - v4-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }} - run: name: "Download Web" command: | From 4ac2bc2b910caa0fb75820cfdd760d0dd8b111d3 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 21:32:47 -0700 Subject: [PATCH 5/8] Don't run the doc tests in service.rs They are not meant to compile. Trying to make them compile requires exporting the service macro and structs, along with adding a lot more code to the test. Signed-off-by: Mcat12 --- src/service.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service.rs b/src/service.rs index efcde74a..2bc28a7c 100644 --- a/src/service.rs +++ b/src/service.rs @@ -15,7 +15,7 @@ //! implement. The code which uses the service references it as a trait object. //! //! Example: -//! ``` +//! ```rust,ignore //! trait MyService { //! fn something(&self); //! } @@ -51,7 +51,7 @@ use rocket::State; /// the request guard which will be created. /// /// Example: -/// ``` +/// ```rust,ignore /// service!(MyServiceGuard, MyService, MyServiceImpl, MyServiceMock); /// /// // Now you can use the guard From 94d41d957a9ec3ecf0f00bbcc16ffc36b2538423 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 21:47:49 -0700 Subject: [PATCH 6/8] Ignore the build.rs coverage It is a build script, and can't be tested via `cargo test`. Signed-off-by: Mcat12 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 19f09ef9..8443b745 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -68,7 +68,7 @@ version: 2 exit 0 fi - grcov target -t lcov --branch --ignore-not-existing --ignore-dir "/*" -o lcov.info + grcov target -t lcov --branch --ignore-not-existing --ignore-dir "/*" --ignore-dir "*build.rs" -o lcov.info bash <(curl -s https://codecov.io/bash) -f lcov.info - run: name: "Build DEB" From 3fd0fe6ce7608c3c2c32c6299adf743051a0b931 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 21:58:58 -0700 Subject: [PATCH 7/8] Ignore some code coverage related files and folders Signed-off-by: Mcat12 --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 6b581ee6..44722f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,10 @@ CMakeLists.txt .idea !.idea/codeStyles/* !.idea/codeStyleSettings.xml + +### Testing +# Code coverage info file +lcov.info + +# Code coverage HTML report +/report/ From 1e98676408508af49f5d1679b1d1ec26f3176a52 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 22 Jul 2019 22:02:54 -0700 Subject: [PATCH 8/8] Fix save_cache not saving to v4 cache Signed-off-by: Mcat12 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8443b745..84a84b7a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -106,7 +106,7 @@ version: 2 - debian/pihole-API.service - rpm/pihole-api.spec - save_cache: - key: v3-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }} + key: v4-cargo-{{ .Environment.CIRCLE_JOB }}--{{ checksum "Cargo.lock" }} paths: - target - /root/.cargo