2022-11-30 17:35:44 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-11-30 17:51:44 +01:00
|
|
|
help () {
|
|
|
|
cat <<EOF
|
2022-11-30 18:08:14 +01:00
|
|
|
Usage: $0 [-r]
|
2022-11-30 17:51:44 +01:00
|
|
|
Collect coverage statistics of library code into an HTML report.
|
|
|
|
|
|
|
|
General instructions:
|
2022-12-01 17:41:36 +01:00
|
|
|
1. Build the library with CFLAGS="--coverage -O0 -g3" and link the test
|
|
|
|
programs with LDFLAGS="--coverage".
|
2022-11-30 17:51:44 +01:00
|
|
|
This can be an out-of-tree build.
|
2022-12-01 17:41:36 +01:00
|
|
|
For example (in-tree):
|
|
|
|
make CFLAGS="--coverage -O0 -g3" LDFLAGS="--coverage"
|
|
|
|
Or (out-of-tree):
|
|
|
|
mkdir build-coverage && cd build-coverage &&
|
|
|
|
cmake -D CMAKE_BUILD_TYPE=Coverage .. && make
|
2022-11-30 17:51:44 +01:00
|
|
|
2. Run whatever tests you want.
|
|
|
|
3. Run this script from the parent of the directory containing the library
|
|
|
|
object files and coverage statistics files.
|
|
|
|
4. Browse the coverage report in Coverage/index.html.
|
2022-11-30 18:08:14 +01:00
|
|
|
5. After rework, run "$0 -r", then re-test and run "$0" to get a fresh report.
|
|
|
|
|
|
|
|
Options
|
|
|
|
-r Reset traces. Run this before re-testing to get fresh measurements.
|
2022-11-30 17:51:44 +01:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copyright The Mbed TLS Contributors
|
2023-11-02 20:47:20 +01:00
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
2022-11-30 17:51:44 +01:00
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2023-10-19 16:27:59 +02:00
|
|
|
# Repository detection
|
2023-10-23 18:25:52 +02:00
|
|
|
in_mbedtls_build_dir () {
|
|
|
|
test -d library
|
2023-11-13 10:50:58 +01:00
|
|
|
}
|
2023-10-19 16:27:59 +02:00
|
|
|
|
2022-11-30 18:08:14 +01:00
|
|
|
# Collect stats and build a HTML report.
|
|
|
|
lcov_library_report () {
|
2022-11-30 17:51:44 +01:00
|
|
|
rm -rf Coverage
|
2022-11-30 17:56:58 +01:00
|
|
|
mkdir Coverage Coverage/tmp
|
2023-10-19 16:27:59 +02:00
|
|
|
lcov --capture --initial --directory $library_dir -o Coverage/tmp/files.info
|
|
|
|
lcov --rc lcov_branch_coverage=1 --capture --directory $library_dir -o Coverage/tmp/tests.info
|
2022-11-30 17:56:58 +01:00
|
|
|
lcov --rc lcov_branch_coverage=1 --add-tracefile Coverage/tmp/files.info --add-tracefile Coverage/tmp/tests.info -o Coverage/tmp/all.info
|
|
|
|
lcov --rc lcov_branch_coverage=1 --remove Coverage/tmp/all.info -o Coverage/tmp/final.info '*.h'
|
|
|
|
gendesc tests/Descriptions.txt -o Coverage/tmp/descriptions
|
2023-10-19 16:27:59 +02:00
|
|
|
genhtml --title "$title" --description-file Coverage/tmp/descriptions --keep-descriptions --legend --branch-coverage -o Coverage Coverage/tmp/final.info
|
2022-11-30 17:56:58 +01:00
|
|
|
rm -f Coverage/tmp/*.info Coverage/tmp/descriptions
|
2022-11-30 17:51:44 +01:00
|
|
|
echo "Coverage report in: Coverage/index.html"
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:08:14 +01:00
|
|
|
# Reset the traces to 0.
|
|
|
|
lcov_reset_traces () {
|
|
|
|
# Location with plain make
|
2023-10-19 16:27:59 +02:00
|
|
|
rm -f $library_dir/*.gcda
|
2022-11-30 18:08:14 +01:00
|
|
|
# Location with CMake
|
2023-10-19 16:27:59 +02:00
|
|
|
rm -f $library_dir/CMakeFiles/*.dir/*.gcda
|
2022-11-30 18:08:14 +01:00
|
|
|
}
|
|
|
|
|
2022-11-30 17:51:44 +01:00
|
|
|
if [ $# -gt 0 ] && [ "$1" = "--help" ]; then
|
|
|
|
help
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2023-10-23 18:25:52 +02:00
|
|
|
if in_mbedtls_build_dir; then
|
2023-10-19 16:27:59 +02:00
|
|
|
library_dir='library'
|
|
|
|
title='Mbed TLS'
|
|
|
|
else
|
2023-10-23 18:25:52 +02:00
|
|
|
library_dir='core'
|
2023-10-19 16:27:59 +02:00
|
|
|
title='TF-PSA-Crypto'
|
|
|
|
fi
|
|
|
|
|
2022-11-30 18:08:14 +01:00
|
|
|
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" "$@"
|