2022-11-30 16:35:44 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-11-30 16:51:44 +00:00
|
|
|
help () {
|
|
|
|
cat <<EOF
|
2022-11-30 17:08:14 +00:00
|
|
|
Usage: $0 [-r]
|
2022-11-30 16:51:44 +00:00
|
|
|
Collect coverage statistics of library code into an HTML report.
|
|
|
|
|
|
|
|
General instructions:
|
2022-12-01 16:41:36 +00:00
|
|
|
1. Build the library with CFLAGS="--coverage -O0 -g3" and link the test
|
|
|
|
programs with LDFLAGS="--coverage".
|
2022-11-30 16:51:44 +00:00
|
|
|
This can be an out-of-tree build.
|
2022-12-01 16:41:36 +00: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 16:51:44 +00: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 17:08:14 +00: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 16:51:44 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# Copyright The Mbed TLS Contributors
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2022-11-30 17:08:14 +00:00
|
|
|
# Collect stats and build a HTML report.
|
|
|
|
lcov_library_report () {
|
2022-11-30 16:51:44 +00:00
|
|
|
rm -rf Coverage
|
2022-11-30 16:56:58 +00:00
|
|
|
mkdir Coverage Coverage/tmp
|
|
|
|
lcov --capture --initial --directory library -o Coverage/tmp/files.info
|
|
|
|
lcov --rc lcov_branch_coverage=1 --capture --directory library -o Coverage/tmp/tests.info
|
|
|
|
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
|
|
|
|
genhtml --title "mbed TLS" --description-file Coverage/tmp/descriptions --keep-descriptions --legend --branch-coverage -o Coverage Coverage/tmp/final.info
|
|
|
|
rm -f Coverage/tmp/*.info Coverage/tmp/descriptions
|
2022-11-30 16:51:44 +00:00
|
|
|
echo "Coverage report in: Coverage/index.html"
|
|
|
|
}
|
|
|
|
|
2022-11-30 17:08:14 +00:00
|
|
|
# Reset the traces to 0.
|
|
|
|
lcov_reset_traces () {
|
|
|
|
# Location with plain make
|
|
|
|
rm -f library/*.gcda
|
|
|
|
# Location with CMake
|
|
|
|
rm -f library/CMakeFiles/*.dir/*.gcda
|
|
|
|
}
|
|
|
|
|
2022-11-30 16:51:44 +00:00
|
|
|
if [ $# -gt 0 ] && [ "$1" = "--help" ]; then
|
|
|
|
help
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-11-30 17:08:14 +00: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" "$@"
|