blob: 8c8c8468bd1e7bdfa4f1ad968cf85e68e2278a02 [file] [log] [blame]
Gilles Peskine7f4705d2022-11-30 17:35:44 +01001#!/bin/sh
2
Gilles Peskine862e4a32022-11-30 17:51:44 +01003help () {
4 cat <<EOF
5Usage: $0
6Collect coverage statistics of library code into an HTML report.
7
8General instructions:
91. Build the library with CFLAGS="--coverage -O0 -g3".
10 This can be an out-of-tree build.
112. Run whatever tests you want.
123. Run this script from the parent of the directory containing the library
13 object files and coverage statistics files.
144. Browse the coverage report in Coverage/index.html.
15EOF
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
33set -eu
34
35lcov_rebuild_stats () {
36 rm -rf Coverage
37 lcov --capture --initial --directory library -o files.info
38 lcov --rc lcov_branch_coverage=1 --capture --directory library -o tests.info
39 lcov --rc lcov_branch_coverage=1 --add-tracefile files.info --add-tracefile tests.info -o all.info
40 lcov --rc lcov_branch_coverage=1 --remove all.info -o final.info '*.h'
41 gendesc tests/Descriptions.txt -o descriptions
42 genhtml --title "mbed TLS" --description-file descriptions --keep-descriptions --legend --branch-coverage -o Coverage final.info
43 rm -f files.info tests.info all.info final.info descriptions
44 echo "Coverage report in: Coverage/index.html"
45}
46
47if [ $# -gt 0 ] && [ "$1" = "--help" ]; then
48 help
49 exit
50fi
51
52lcov_rebuild_stats