mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
scripts: add code coverage script
Fixes: #6507 Signed-off-by: Songqian Li <sionli@tencent.com>
This commit is contained in:
committed by
Rob Bradford
parent
eabbeac9c0
commit
9f02839448
63
scripts/run_coverage.sh
Executable file
63
scripts/run_coverage.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -x
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "$HOME"/.cargo/env
|
||||
|
||||
PROJECT_DIR="/cloud-hypervisor"
|
||||
TARGET_DIR="$PROJECT_DIR/target"
|
||||
|
||||
pushd $PROJECT_DIR || exit
|
||||
|
||||
export BUILD_TARGET=${BUILD_TARGET-$(uname -m)-unknown-linux-gnu}
|
||||
|
||||
# GLIBC > 2.31
|
||||
GRCOV_RELEASE_URL="https://github.com/mozilla/grcov/releases/download/v0.8.19/grcov-$BUILD_TARGET.tar.bz2"
|
||||
wget --quiet "$GRCOV_RELEASE_URL" || exit 1
|
||||
tar -xjf "grcov-$BUILD_TARGET.tar.bz2"
|
||||
|
||||
rustup component add llvm-tools-preview
|
||||
|
||||
export_lcov() {
|
||||
rm "coverage.info"
|
||||
|
||||
./grcov "$(find . -name 'ch-*.profraw' -print)" -s . \
|
||||
--ignore "tests/*" \
|
||||
--ignore "test_infra/*" \
|
||||
--ignore "performance-metrics/*" \
|
||||
--binary-path "$TARGET_DIR/$BUILD_TARGET/release/" \
|
||||
--branch --ignore-not-existing -t lcov \
|
||||
-o "coverage.info"
|
||||
|
||||
find . -type f -name 'ch-*.profraw' -exec rm {} \;
|
||||
}
|
||||
|
||||
# Generate HTML report
|
||||
export_html() {
|
||||
OUTPUT_DIR="$TARGET_DIR/coverage"
|
||||
rm -rf $OUTPUT_DIR
|
||||
./grcov "$(find . -name 'ch-*.profraw' -print)" -s . \
|
||||
--ignore "tests/*" \
|
||||
--ignore "test_infra/*" \
|
||||
--ignore "performance-metrics/*" \
|
||||
--binary-path "$TARGET_DIR/$BUILD_TARGET/release/" \
|
||||
--branch --ignore-not-existing -t html \
|
||||
-o $OUTPUT_DIR
|
||||
find . -type f -name 'ch-*.profraw' -exec rm {} \;
|
||||
}
|
||||
|
||||
# $1 is now a command name. Check if it is a valid command and, if so,
|
||||
# run it.
|
||||
#
|
||||
declare -f "export_$1" >/dev/null
|
||||
code=$?
|
||||
[[ $code == 0 ]] || echo "Unknown command: $1. Only support \"lcov\" and \"html\". Change to default command: html"
|
||||
type=${1-html}
|
||||
|
||||
func=export_$type
|
||||
shift
|
||||
|
||||
$func "$@"
|
||||
|
||||
popd || exit 1
|
||||
Reference in New Issue
Block a user