Skip to content

Commit 3b2463a

Browse files
author
James Wilson
committed
Adding script to give code coverage for regression tests.
1 parent 6370cc0 commit 3b2463a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

COMPILING

+17
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,20 @@ To work with Eclipse, do the following:
203203
6) Select Project -> Build All
204204

205205

206+
CODE COVERAGE
207+
-------------
208+
209+
Code coverage metrics are provided using gcov and lcov. Ensure that you
210+
have installed lcov from http://ltp.sourceforge.net/coverage/lcov.php
211+
note for ubuntu lcov is available in the standard apt-get repos.
212+
213+
To get coverage metrics run the following script from the regression
214+
directory:
215+
216+
get_coverage.sh
217+
218+
This will:
219+
1) Rebuild CBMC with gcov enabled
220+
2) Run all the regression tests
221+
3) Collate the coverage metrics
222+
4) Provide an HTML report of the current coverage

regression/get_coverage.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# Get a unique number to prevent collision of output files
4+
outputDir=`mktemp -d ./coverage_XXXXX`
5+
if [ $? -ne 0 ]; then
6+
printf "ERROR: Could not create output directoy"
7+
exit 1
8+
fi
9+
10+
# Check that the previous command succeded, if not exit.
11+
commandStatus()
12+
{
13+
if [ $? -ne 0 ]; then
14+
printf "[ERROR]\n"
15+
echo "ERROR: See $outputDir/cbmc_coverage.out for more information"
16+
exit 1
17+
fi
18+
printf "[OK]\n"
19+
}
20+
21+
# Check that lcov has been installed
22+
printf "INFO: Checking lcov is installed "
23+
lcov -version > $outputDir/cbmc_coverage.out 2>&1
24+
commandStatus
25+
26+
# Remove any previous build that may not have coverage in it.
27+
printf "INFO: Cleaning CBMC build "
28+
make clean -C ../src >> $outputDir/cbmc_coverage.out 2>&1
29+
commandStatus
30+
31+
printf "INFO: Building CBMC with Code Coverage enabled "
32+
# Run the usual make target with --coverage to add gcov instrumentation
33+
make CXXFLAGS="--coverage" LINKFLAGS="--coverage" -C ../src >> $outputDir/cbmc_coverage.out 2>&1
34+
commandStatus
35+
36+
printf "INFO: Running Regression tests "
37+
# Run regression tests which will collect the coverage metrics and put them in the src files
38+
make >> $outputDir/cbmc_coverage.out 2>&1
39+
printf "[DONE]\n"
40+
41+
printf "INFO: Gathering coverage metrics "
42+
# Gather all of the coverage metrics into a single file
43+
lcov --capture --directory ../src --output-file $outputDir/cbmcCoverage.info >> $outputDir/cbmc_coverage.out 2>&1
44+
commandStatus
45+
46+
printf "INFO: Removing unwanted metrics (for external libaries) "
47+
# Remove the metrics for files that aren't CBMC's source code
48+
lcov --remove $outputDir/cbmcCoverage.info '/usr/*' --output-file $outputDir/cbmcCoverage.info >> $outputDir/cbmc_coverage.out 2>&1
49+
commandStatus
50+
51+
printf "INFO: Creating coverage report "
52+
# Generate the HTML coverage report
53+
genhtml $outputDir/cbmcCoverage.info --output-directory $outputDir/cbmcCoverage >> $outputDir/cbmc_coverage.out 2>&1
54+
commandStatus
55+
echo "INFO: Coverage report is availabe in $outputDir/cbmcCoverage"

0 commit comments

Comments
 (0)