Gilles Peskine | 7f4705d | 2022-11-30 17:35:44 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Gilles Peskine | 862e4a3 | 2022-11-30 17:51:44 +0100 | [diff] [blame] | 3 | help () { |
| 4 | cat <<EOF |
| 5 | Usage: $0 |
| 6 | Collect coverage statistics of library code into an HTML report. |
| 7 | |
| 8 | General instructions: |
| 9 | 1. Build the library with CFLAGS="--coverage -O0 -g3". |
| 10 | This can be an out-of-tree build. |
| 11 | 2. Run whatever tests you want. |
| 12 | 3. Run this script from the parent of the directory containing the library |
| 13 | object files and coverage statistics files. |
| 14 | 4. Browse the coverage report in Coverage/index.html. |
| 15 | EOF |
| 16 | } |
| 17 | |
| 18 | # Copyright The Mbed TLS Contributors |
| 19 | # SPDX-License-Identifier: Apache-2.0 |
| 20 | # |
| 21 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 22 | # not use this file except in compliance with the License. |
| 23 | # You may obtain a copy of the License at |
| 24 | # |
| 25 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 26 | # |
| 27 | # Unless required by applicable law or agreed to in writing, software |
| 28 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 29 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 30 | # See the License for the specific language governing permissions and |
| 31 | # limitations under the License. |
| 32 | |
| 33 | set -eu |
| 34 | |
| 35 | lcov_rebuild_stats () { |
| 36 | rm -rf Coverage |
Gilles Peskine | f11c33c | 2022-11-30 17:56:58 +0100 | [diff] [blame^] | 37 | mkdir Coverage Coverage/tmp |
| 38 | lcov --capture --initial --directory library -o Coverage/tmp/files.info |
| 39 | lcov --rc lcov_branch_coverage=1 --capture --directory library -o Coverage/tmp/tests.info |
| 40 | lcov --rc lcov_branch_coverage=1 --add-tracefile Coverage/tmp/files.info --add-tracefile Coverage/tmp/tests.info -o Coverage/tmp/all.info |
| 41 | lcov --rc lcov_branch_coverage=1 --remove Coverage/tmp/all.info -o Coverage/tmp/final.info '*.h' |
| 42 | gendesc tests/Descriptions.txt -o Coverage/tmp/descriptions |
| 43 | genhtml --title "mbed TLS" --description-file Coverage/tmp/descriptions --keep-descriptions --legend --branch-coverage -o Coverage Coverage/tmp/final.info |
| 44 | rm -f Coverage/tmp/*.info Coverage/tmp/descriptions |
Gilles Peskine | 862e4a3 | 2022-11-30 17:51:44 +0100 | [diff] [blame] | 45 | echo "Coverage report in: Coverage/index.html" |
| 46 | } |
| 47 | |
| 48 | if [ $# -gt 0 ] && [ "$1" = "--help" ]; then |
| 49 | help |
| 50 | exit |
| 51 | fi |
| 52 | |
| 53 | lcov_rebuild_stats |