Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2105 from holochain/test-kcov
Browse files Browse the repository at this point in the history
Code coverage with kcov and codecov.io
  • Loading branch information
zippy authored Feb 13, 2020
2 parents 2a7d326 + 765633d commit 5595444
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ jobs:
command: nix-shell --run hc-rust-test
no_output_timeout: 20m

code-coverage:
machine: true
resource_class: xlarge
steps:
- checkout
- run: docker run --env CODECOV_TOKEN --rm --security-opt seccomp=unconfined -v $(pwd):/project holochain/holochain-rust:circle.build.develop sh -c "cd /project && nix-shell --run hc-rust-coverage-kcov"

fmt:
docker:
- image: holochain/holochain-rust:circle.fmt.develop
Expand Down Expand Up @@ -249,6 +256,14 @@ workflows:
- cli-tests
- wasm-conductor-tests

- code-coverage:
filters:
branches:
only:
- develop
- test-kcov
# NOTE - add your branche here if working on coverage

- docker-build-minimal:
filters:
branches:
Expand Down
56 changes: 52 additions & 4 deletions rust/test/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
{ holonix, pkgs }:
let
name = "hc-rust-test";

script = pkgs.writeShellScriptBin name
hc-rust-test = pkgs.writeShellScriptBin "hc-rust-test"
''
hc-rust-wasm-compile && HC_SIMPLE_LOGGER_MUTE=1 RUST_BACKTRACE=1 cargo test --all "$1" -- --test-threads=${holonix.rust.test.threads};
'';

hc-rust-coverage-kcov = pkgs.writeShellScriptBin "hc-rust-coverage-kcov"
''
# this script is a little messy - mainly only designed to be run on CI
# cargo-make coverage only really works for individual crates so we futz
# with the CARGO_TARGET_DIR - also we just blanket install cargo-make
# using cargo-make for executing kcov
cargo install cargo-make
# some tests require compiled wasm
hc-rust-wasm-compile
# kcov does not work with the global /holochain-rust/target
mkdir -p target
# actually kcov does not work with workspace target either
# we need to use targets in each crate - but that is slow
# use symlinks so we don't have to recompile deps over and over
for i in ''$(find crates -maxdepth 1 -mindepth 1 -type d | sort); do
# delete all other test binaries so they don't get run multiple times
rm -rf $(find target/debug -maxdepth 1 -mindepth 1 -type f)
echo "-------"
echo "coverage for '$i'"
echo "-------"
# cd into crate dirs
# remove any pre-existing target dir
# symlink to shared target dir
# build the test binaries
# run the code coverage
( \
cd $i && \
rm -rf target || true && \
ln -s ../../target
export CARGO_TARGET_DIR=$(readlink -f ./target) && \
cargo test --no-run && \
cargo make coverage-kcov \
)
# then remove the symlink so we don't double count the coverage reports
rm -rf "''${i}/target"
done
# upload to codecove.io
bash <(curl -s https://codecov.io/bash) -t "''${CODECOV_TOKEN}"
'';
in
{
buildInputs = [ script ];
buildInputs = [ pkgs.kcov pkgs.curl hc-rust-test hc-rust-coverage-kcov ];
}

0 comments on commit 5595444

Please sign in to comment.