2024-06-03 07:30:45 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "$HOME"/.cargo/env
|
2024-10-23 08:22:29 +00:00
|
|
|
source "$(dirname "$0")/test-util.sh"
|
|
|
|
|
|
|
|
process_common_args "$@"
|
2024-06-03 07:30:45 +00:00
|
|
|
|
|
|
|
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 {} \;
|
|
|
|
}
|
|
|
|
|
2024-10-23 08:22:29 +00:00
|
|
|
# test_binary_args is now a command name. Check if it is a valid command and, if so,
|
2024-06-03 07:30:45 +00:00
|
|
|
# run it.
|
|
|
|
#
|
2024-10-23 08:22:29 +00:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
type=${test_binary_args[*]}
|
|
|
|
declare -f "export_$type" >/dev/null
|
2024-06-03 07:30:45 +00:00
|
|
|
code=$?
|
2024-10-23 08:22:29 +00:00
|
|
|
if [[ $code != 0 ]]; then
|
|
|
|
echo "Unknown command: $type. Only support \"lcov\" and \"html\". Change to default command: html"
|
|
|
|
type="html"
|
|
|
|
fi
|
2024-06-03 07:30:45 +00:00
|
|
|
|
|
|
|
func=export_$type
|
2024-10-23 08:22:29 +00:00
|
|
|
$func
|
2024-06-03 07:30:45 +00:00
|
|
|
|
|
|
|
popd || exit 1
|