Debian Codegraph @

scripts/record-coverage.sh

raw
1 #! /usr/bin/env bash
2
3 # This script collates coverage data already present from running instrumented code.
4 #
5 # It requires the lcov tool to be installed (this provides the lcov and genhtml commands)
6 #
7 # It will produce a coverage analysis for gcc or clang compiled builds and currently for
8 # C and C++ parts of the build tree.
9 #
10 # It takes two command line arguments:
11 # - The first is the proton source tree: this is mandatory.
12 # - The second is the build tree: this is optional and if not specified is assumed to be the
13 # current directory.
14 #
15 # The output is in the form of an html report which will be found in the generated html directory.
16 # - There will also be a number of intermediate files left in the current directory.
17 #
18 # The typical way to use it would be to use the "Coverage" build type to get instrumented
19 # code, then to run the tests then to extract the coverage information from running the
20 # tests.
21 # Something like:
22 # cmake $PROTON_SRC -DCMAKE_BUILD_TYPE=Coverage
23 # make
24 # make test
25 # make coverage
26
27 # set -x
28
29 # get full path
30 function getpath {
31 pushd -n $1 > /dev/null
32 echo $(dirs -0 -l)
33 popd -n > /dev/null
34 }
35
36 SRC=${1?}
37 BLD=${2:-.}
38
39 BLDPATH=$(getpath $BLD)
40 SRCPATH=$(getpath $SRC)
41
42 # Get base profile
43 # - this initialises 0 counts for every profiled file
44 # without this step any file with no counts at all wouldn't
45 # show up on the final output.
46 lcov -c -i -d $BLDPATH -o proton-base.info
47
48 # Get actual coverage data
49 lcov -c -d $BLDPATH -o proton-ctest.info
50
51 # Total them up
52 lcov --add proton-base.info --add proton-ctest.info > proton-total-raw.info
53
54 # Snip out stuff in /usr (we don't care about coverage in system code)
55 lcov --remove proton-total-raw.info "/usr/include*" "/usr/share*" > proton-total.info
56
57 # Generate report
58 rm -rf html
59 genhtml -p $SRCPATH -p $BLDPATH proton-total.info --title "Proton CTest Coverage" --demangle-cpp -o html
60