blob: 80ebc79870fc1032b8c9d3789d0f0ab3b366bf57 [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
Gilles Peskinef11c33c2022-11-30 17:56:58 +010037 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 Peskine862e4a32022-11-30 17:51:44 +010045 echo "Coverage report in: Coverage/index.html"
46}
47
48if [ $# -gt 0 ] && [ "$1" = "--help" ]; then
49 help
50 exit
51fi
52
53lcov_rebuild_stats