blob: d4d5df73ca0943d32231d7ce2f99b08809aa78ad [file] [log] [blame]
#!/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 test coverage of all unit tests in crosvm.
# Requirements:
# $ apt install jq
# $ 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 --all tests with coverage profiling options enabled.
CARGO_INCREMENTAL=0 \
RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Coverflow-checks=off \
-Zpanic_abort_tests" \
cargo +nightly test \
--no-fail-fast --features default-no-sandbox,wl-dmabuf,gpu,tpm \
--all --exclude aarch64 \
-- \
--test-threads=1
# 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