#!/bin/sh help () { cat <&2 exit 1 fi in_mbedtls_repo () { test "$PROJECT_NAME" = "Mbed TLS" } # Collect stats and build a HTML report. lcov_library_report () { rm -rf Coverage mkdir Coverage Coverage/tmp # Pass absolute paths as lcov output files. This works around a bug # whereby lcov tries to create the output file in the root directory # if it has emitted a warning. A fix was released in lcov 1.13 in 2016. # Ubuntu 16.04 is affected, 18.04 and above are not. # https://github.com/linux-test-project/lcov/commit/632c25a0d1f5e4d2f4fd5b28ce7c8b86d388c91f COVTMP=$PWD/Coverage/tmp lcov --capture --initial ${lcov_dirs} -o "$COVTMP/files.info" lcov --rc lcov_branch_coverage=1 --capture ${lcov_dirs} -o "$COVTMP/tests.info" lcov --rc lcov_branch_coverage=1 --add-tracefile "$COVTMP/files.info" --add-tracefile "$COVTMP/tests.info" -o "$COVTMP/all.info" lcov --rc lcov_branch_coverage=1 --remove "$COVTMP/all.info" -o "$COVTMP/final.info" '*.h' gendesc tests/Descriptions.txt -o "$COVTMP/descriptions" genhtml --title "$title" --description-file "$COVTMP/descriptions" --keep-descriptions --legend --branch-coverage -o Coverage "$COVTMP/final.info" rm -f "$COVTMP/"*.info "$COVTMP/descriptions" echo "Coverage report in: Coverage/index.html" } # Reset the traces to 0. lcov_reset_traces () { # Location with plain make for dir in ${library_dirs}; do rm -f ${dir}/*.gcda done # Location with CMake for dir in ${library_dirs}; do rm -f ${dir}/CMakeFiles/*.dir/*.gcda done } if [ $# -gt 0 ] && [ "$1" = "--help" ]; then help exit fi if in_mbedtls_repo; then library_dirs='library tf-psa-crypto/core tf-psa-crypto/drivers/builtin' title='Mbed TLS' else library_dirs='core drivers/builtin' title='TF-PSA-Crypto' fi lcov_dirs="" for dir in ${library_dirs}; do lcov_dirs="${lcov_dirs} --directory ${dir}" done main=lcov_library_report while getopts r OPTLET; do case $OPTLET in r) main=lcov_reset_traces;; *) help 2>&1; exit 120;; esac done shift $((OPTIND - 1)) "$main" "$@"