1#!/usr/bin/env bash 2 3set -x 4 5# shellcheck source=/dev/null 6source "$HOME"/.cargo/env 7 8PROJECT_DIR="/cloud-hypervisor" 9TARGET_DIR="$PROJECT_DIR/target" 10 11pushd $PROJECT_DIR || exit 12 13export BUILD_TARGET=${BUILD_TARGET-$(uname -m)-unknown-linux-gnu} 14 15# GLIBC > 2.31 16GRCOV_RELEASE_URL="https://github.com/mozilla/grcov/releases/download/v0.8.19/grcov-$BUILD_TARGET.tar.bz2" 17wget --quiet "$GRCOV_RELEASE_URL" || exit 1 18tar -xjf "grcov-$BUILD_TARGET.tar.bz2" 19 20rustup component add llvm-tools-preview 21 22export_lcov() { 23 rm "coverage.info" 24 25 ./grcov "$(find . -name 'ch-*.profraw' -print)" -s . \ 26 --ignore "tests/*" \ 27 --ignore "test_infra/*" \ 28 --ignore "performance-metrics/*" \ 29 --binary-path "$TARGET_DIR/$BUILD_TARGET/release/" \ 30 --branch --ignore-not-existing -t lcov \ 31 -o "coverage.info" 32 33 find . -type f -name 'ch-*.profraw' -exec rm {} \; 34} 35 36# Generate HTML report 37export_html() { 38 OUTPUT_DIR="$TARGET_DIR/coverage" 39 rm -rf $OUTPUT_DIR 40 ./grcov "$(find . -name 'ch-*.profraw' -print)" -s . \ 41 --ignore "tests/*" \ 42 --ignore "test_infra/*" \ 43 --ignore "performance-metrics/*" \ 44 --binary-path "$TARGET_DIR/$BUILD_TARGET/release/" \ 45 --branch --ignore-not-existing -t html \ 46 -o $OUTPUT_DIR 47 find . -type f -name 'ch-*.profraw' -exec rm {} \; 48} 49 50# $1 is now a command name. Check if it is a valid command and, if so, 51# run it. 52# 53declare -f "export_$1" >/dev/null 54code=$? 55[[ $code == 0 ]] || echo "Unknown command: $1. Only support \"lcov\" and \"html\". Change to default command: html" 56type=${1-html} 57 58func=export_$type 59shift 60 61$func "$@" 62 63popd || exit 1 64