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