crosvm/bin/crate_coverage
Dennis Kempin 831b11e869 Add scripts to run code coverage
One script to run coverage for the whole smoke test suite,
the resulting file can be uploaded to codecov.io for consumption:
https://codecov.io/gh/denniskempin/crosvm

Another script to run tests + coverage for a single crate,
which is useful during development to keep track of coverage
while adding tests (IDEs can display the generated lcov.info file)

BUG=b:171082843
TEST=Manual testing of both scripts

Change-Id: I52384762400a146cb0e7deb3d54dccf59b6134db
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2492914
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2020-10-27 05:22:32 +00:00

36 lines
1 KiB
Bash
Executable file

#!/bin/bash
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Calculates coverage for the specified crate only
# Usage:
# $ ./bin/crate_coverage arch [additional arguments for cargo test]
# Requirements:
# $ rustup toolchain install nightly
# $ cargo install grcov rust-covfix
set -ex
cd "${0%/*}/../"
target_dir=$(
cargo metadata --no-deps --format-version 1 |
jq -r ".target_directory"
)
# Delete old coverage profiles
find "$target_dir/debug" -name "*.gcda" -delete
# Run test with coverage profiling
(cd $1 && CARGO_INCREMENTAL=0 \
RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off \
-Zpanic_abort_tests" \
cargo +nightly test "${@:2}")
# Calculate code coverage
grcov "$target_dir/debug" -s . \
--ignore "/*" --ignore-not-existing \
-t lcov --llvm --branch \
-o /tmp/lcov.info
# Apply code coverage fixes
rust-covfix /tmp/lcov.info >lcov.info